needle_map_metric_test.go 1.0 KB

123456789101112131415161718192021222324252627282930
  1. package storage
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  5. "io/ioutil"
  6. "math/rand"
  7. "testing"
  8. )
  9. func TestFastLoadingNeedleMapMetrics(t *testing.T) {
  10. idxFile, _ := ioutil.TempFile("", "tmp.idx")
  11. nm := NewBtreeNeedleMap(idxFile)
  12. for i := 0; i < 10000; i++ {
  13. nm.Put(Uint64ToNeedleId(uint64(i+1)), Uint32ToOffset(uint32(0)), uint32(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. }