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.

78 lines
1.7 KiB

7 years ago
7 years ago
7 years ago
  1. package needle
  2. import (
  3. . "github.com/chrislusf/seaweedfs/weed/storage/types"
  4. "testing"
  5. )
  6. func TestIssue52(t *testing.T) {
  7. m := NewCompactMap()
  8. m.Set(NeedleId(10002), 10002, 10002)
  9. if element, ok := m.Get(NeedleId(10002)); ok {
  10. println("key", 10002, "ok", ok, element.Key, element.Offset, element.Size)
  11. }
  12. m.Set(NeedleId(10001), 10001, 10001)
  13. if element, ok := m.Get(NeedleId(10002)); ok {
  14. println("key", 10002, "ok", ok, element.Key, element.Offset, element.Size)
  15. } else {
  16. t.Fatal("key 10002 missing after setting 10001")
  17. }
  18. }
  19. func TestXYZ(t *testing.T) {
  20. m := NewCompactMap()
  21. for i := uint32(0); i < 100*batch; i += 2 {
  22. m.Set(NeedleId(i), Offset(i), i)
  23. }
  24. for i := uint32(0); i < 100*batch; i += 37 {
  25. m.Delete(NeedleId(i))
  26. }
  27. for i := uint32(0); i < 10*batch; i += 3 {
  28. m.Set(NeedleId(i), Offset(i+11), i+5)
  29. }
  30. // for i := uint32(0); i < 100; i++ {
  31. // if v := m.Get(Key(i)); v != nil {
  32. // glog.V(4).Infoln(i, "=", v.Key, v.Offset, v.Size)
  33. // }
  34. // }
  35. for i := uint32(0); i < 10*batch; i++ {
  36. v, ok := m.Get(NeedleId(i))
  37. if i%3 == 0 {
  38. if !ok {
  39. t.Fatal("key", i, "missing!")
  40. }
  41. if v.Size != i+5 {
  42. t.Fatal("key", i, "size", v.Size)
  43. }
  44. } else if i%37 == 0 {
  45. if ok && v.Size > 0 {
  46. t.Fatal("key", i, "should have been deleted needle value", v)
  47. }
  48. } else if i%2 == 0 {
  49. if v.Size != i {
  50. t.Fatal("key", i, "size", v.Size)
  51. }
  52. }
  53. }
  54. for i := uint32(10 * batch); i < 100*batch; i++ {
  55. v, ok := m.Get(NeedleId(i))
  56. if i%37 == 0 {
  57. if ok && v.Size > 0 {
  58. t.Fatal("key", i, "should have been deleted needle value", v)
  59. }
  60. } else if i%2 == 0 {
  61. if v == nil {
  62. t.Fatal("key", i, "missing")
  63. }
  64. if v.Size != i {
  65. t.Fatal("key", i, "size", v.Size)
  66. }
  67. }
  68. }
  69. }