debug_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package cluster
  11. import (
  12. "math"
  13. "testing"
  14. "time"
  15. "devt.de/krotik/eliasdb/cluster/manager"
  16. )
  17. func TestDebugging(t *testing.T) {
  18. // Set a low distribution range
  19. defaultDistributionRange = 10
  20. defer func() { defaultDistributionRange = math.MaxUint64 }()
  21. // Setup a cluster
  22. manager.FreqHousekeeping = 5
  23. defer func() { manager.FreqHousekeeping = 1000 }()
  24. // Log transfer worker runs
  25. logTransferWorker = true
  26. defer func() { logTransferWorker = false }()
  27. // Create a cluster with 3 members and a replication factor of 2
  28. cluster3, ms := createCluster(3, 2)
  29. // Debug output
  30. // manager.LogDebug = manager.LogInfo
  31. // log.SetOutput(os.Stderr)
  32. // defer func() { log.SetOutput(ioutil.Discard) }()
  33. for i, dd := range cluster3 {
  34. dd.Start()
  35. defer dd.Close()
  36. if i > 0 {
  37. err := dd.MemberManager.JoinCluster(cluster3[0].MemberManager.Name(), cluster3[0].MemberManager.NetAddr())
  38. if err != nil {
  39. t.Error(err)
  40. return
  41. }
  42. }
  43. }
  44. ClearMSMap()
  45. msmap[cluster3[1]] = ms[1]
  46. sm := cluster3[1].StorageManager("test", true)
  47. // Insert two strings into the store
  48. if loc, err := sm.Insert("test1"); loc != 1 || err != nil {
  49. t.Error("Unexpected result:", loc, err)
  50. return
  51. }
  52. if loc, err := sm.Insert("test2"); loc != 2 || err != nil {
  53. t.Error("Unexpected result:", loc, err)
  54. return
  55. }
  56. sm.Flush()
  57. ms[1].transferRunning = true
  58. go func() {
  59. time.Sleep(10 * time.Millisecond)
  60. ms[1].transferRunning = false
  61. }()
  62. WaitForTransfer()
  63. if res := DumpMemoryClusterLayout("test"); res != `MemoryStorage: mgs2
  64. TestClusterMember-1 MemberStorageManager mgs2/ls_test
  65. Roots: 0=0 1=0 2=0 3=0 4=0 5=0 6=0 7=0 8=0 9=0
  66. cloc: 1 (v:1) - lloc: 1 - "\b\f\x00\x05test1"
  67. cloc: 2 (v:1) - lloc: 2 - "\b\f\x00\x05test2"
  68. ` {
  69. t.Error("Unexpected result:", res)
  70. return
  71. }
  72. }