You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

  1. package storage
  2. import (
  3. "math/rand"
  4. "os"
  5. "testing"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  8. )
  9. func TestFastLoadingNeedleMapMetrics(t *testing.T) {
  10. idxFile, _ := os.CreateTemp("", "tmp.idx")
  11. nm := NewCompactNeedleMap(idxFile)
  12. for i := 0; i < 10000; i++ {
  13. nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), Size(1))
  14. if rand.Float32() < 0.2 {
  15. nm.Delete(Uint64ToNeedleId(uint64(rand.Int63n(int64(i))+1)), Uint32ToOffset(uint32(0)))
  16. }
  17. }
  18. mm, _ := newNeedleMapMetricFromIndexFile(idxFile)
  19. glog.V(0).Infof("FileCount expected %d actual %d", nm.FileCount(), mm.FileCount())
  20. glog.V(0).Infof("DeletedSize expected %d actual %d", nm.DeletedSize(), mm.DeletedSize())
  21. glog.V(0).Infof("ContentSize expected %d actual %d", nm.ContentSize(), mm.ContentSize())
  22. glog.V(0).Infof("DeletedCount expected %d actual %d", nm.DeletedCount(), mm.DeletedCount())
  23. glog.V(0).Infof("MaxFileKey expected %d actual %d", nm.MaxFileKey(), mm.MaxFileKey())
  24. }