aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/filechunk_section_test.go
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2023-01-10 00:46:46 -0800
committerchrislu <chris.lu@gmail.com>2023-01-10 00:46:46 -0800
commit75bdd4a0d1caa5af940397793fe0decc3da1093e (patch)
tree2f38fb005d1e81dec4d4fa57f53e6455c4fd263f /weed/filer/filechunk_section_test.go
parent51d4a4b28d0edcd01ab1faa19f8a80f4137fc497 (diff)
downloadseaweedfs-75bdd4a0d1caa5af940397793fe0decc3da1093e.tar.xz
seaweedfs-75bdd4a0d1caa5af940397793fe0decc3da1093e.zip
refactor
Diffstat (limited to 'weed/filer/filechunk_section_test.go')
-rw-r--r--weed/filer/filechunk_section_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/weed/filer/filechunk_section_test.go b/weed/filer/filechunk_section_test.go
new file mode 100644
index 000000000..e4536540b
--- /dev/null
+++ b/weed/filer/filechunk_section_test.go
@@ -0,0 +1,48 @@
+package filer
+
+import (
+ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
+ "testing"
+)
+
+func Test_removeGarbageChunks(t *testing.T) {
+ section := NewFileChunkSection(0)
+ section.addChunk(&filer_pb.FileChunk{
+ FileId: "0",
+ Offset: 0,
+ Size: 1,
+ ModifiedTsNs: 0,
+ })
+ section.addChunk(&filer_pb.FileChunk{
+ FileId: "1",
+ Offset: 1,
+ Size: 1,
+ ModifiedTsNs: 1,
+ })
+ section.addChunk(&filer_pb.FileChunk{
+ FileId: "2",
+ Offset: 2,
+ Size: 1,
+ ModifiedTsNs: 2,
+ })
+ section.addChunk(&filer_pb.FileChunk{
+ FileId: "3",
+ Offset: 3,
+ Size: 1,
+ ModifiedTsNs: 3,
+ })
+ section.addChunk(&filer_pb.FileChunk{
+ FileId: "4",
+ Offset: 4,
+ Size: 1,
+ ModifiedTsNs: 4,
+ })
+ garbageFileIds := make(map[string]struct{})
+ garbageFileIds["0"] = struct{}{}
+ garbageFileIds["2"] = struct{}{}
+ garbageFileIds["4"] = struct{}{}
+ removeGarbageChunks(section, garbageFileIds)
+ if len(section.chunks) != 2 {
+ t.Errorf("remove chunk 2 failed")
+ }
+}