filechunk_section_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package filer
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  4. "testing"
  5. )
  6. func Test_removeGarbageChunks(t *testing.T) {
  7. section := NewFileChunkSection(0)
  8. section.chunks = append(section.chunks, &filer_pb.FileChunk{
  9. FileId: "0",
  10. Offset: 0,
  11. Size: 1,
  12. ModifiedTsNs: 0,
  13. })
  14. section.chunks = append(section.chunks, &filer_pb.FileChunk{
  15. FileId: "1",
  16. Offset: 1,
  17. Size: 1,
  18. ModifiedTsNs: 1,
  19. })
  20. section.chunks = append(section.chunks, &filer_pb.FileChunk{
  21. FileId: "2",
  22. Offset: 2,
  23. Size: 1,
  24. ModifiedTsNs: 2,
  25. })
  26. section.chunks = append(section.chunks, &filer_pb.FileChunk{
  27. FileId: "3",
  28. Offset: 3,
  29. Size: 1,
  30. ModifiedTsNs: 3,
  31. })
  32. section.chunks = append(section.chunks, &filer_pb.FileChunk{
  33. FileId: "4",
  34. Offset: 4,
  35. Size: 1,
  36. ModifiedTsNs: 4,
  37. })
  38. garbageFileIds := make(map[string]struct{})
  39. garbageFileIds["0"] = struct{}{}
  40. garbageFileIds["2"] = struct{}{}
  41. garbageFileIds["4"] = struct{}{}
  42. removeGarbageChunks(section, garbageFileIds)
  43. if len(section.chunks) != 2 {
  44. t.Errorf("remove chunk 2 failed")
  45. }
  46. }