flare-tools 0.1.4 → 0.4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.gemtest +0 -0
  2. data/Flare-tools.txt +0 -0
  3. data/History.txt +114 -2
  4. data/LICENSE +21 -0
  5. data/Manifest.txt +65 -8
  6. data/README.txt +356 -0
  7. data/Rakefile +90 -25
  8. data/Tutorial.txt +370 -0
  9. data/bin/flare-admin +6 -0
  10. data/bin/flare-argv0 +6 -0
  11. data/bin/flare-deploy +6 -0
  12. data/bin/flare-keychecker +6 -0
  13. data/bin/flare-part +6 -0
  14. data/bin/flare-ping +6 -0
  15. data/bin/flare-stats +4 -10
  16. data/bin/flare-zkadmin +6 -0
  17. data/lib/flare/net/connection.rb +98 -0
  18. data/lib/flare/test/cluster.rb +140 -0
  19. data/lib/flare/test/daemon.rb +144 -0
  20. data/lib/flare/test/node.rb +62 -0
  21. data/lib/flare/tools.rb +18 -16
  22. data/lib/flare/tools/cli.rb +32 -0
  23. data/lib/flare/tools/cli/activate.rb +106 -0
  24. data/lib/flare/tools/cli/balance.rb +83 -0
  25. data/lib/flare/tools/cli/cli_util.rb +77 -0
  26. data/lib/flare/tools/cli/deploy.rb +170 -0
  27. data/lib/flare/tools/cli/down.rb +85 -0
  28. data/lib/flare/tools/cli/dump.rb +219 -0
  29. data/lib/flare/tools/cli/dumpkey.rb +117 -0
  30. data/lib/flare/tools/cli/flare_admin.rb +81 -0
  31. data/lib/flare/tools/cli/flare_argv0.rb +60 -0
  32. data/lib/flare/tools/cli/flare_keychecker.rb +106 -0
  33. data/lib/flare/tools/cli/flare_zkadmin.rb +226 -0
  34. data/lib/flare/tools/cli/index.rb +54 -0
  35. data/lib/flare/tools/cli/list.rb +93 -0
  36. data/lib/flare/tools/cli/master.rb +143 -0
  37. data/lib/flare/tools/cli/part.rb +100 -0
  38. data/lib/flare/tools/cli/ping.rb +81 -0
  39. data/lib/flare/tools/cli/reconstruct.rb +164 -0
  40. data/lib/flare/tools/cli/remove.rb +119 -0
  41. data/lib/flare/tools/cli/restore.rb +180 -0
  42. data/lib/flare/tools/cli/slave.rb +125 -0
  43. data/lib/flare/tools/cli/stats.rb +229 -122
  44. data/lib/flare/tools/cli/sub_command.rb +73 -0
  45. data/lib/flare/tools/cli/summary.rb +97 -0
  46. data/lib/flare/tools/cli/threads.rb +78 -0
  47. data/lib/flare/tools/cli/verify.rb +202 -0
  48. data/lib/flare/tools/client.rb +267 -0
  49. data/lib/flare/tools/cluster.rb +319 -0
  50. data/lib/flare/tools/common.rb +196 -0
  51. data/lib/flare/tools/index_server.rb +51 -0
  52. data/lib/flare/tools/node.rb +162 -0
  53. data/lib/flare/tools/stats.rb +75 -0
  54. data/lib/flare/tools/zk_util.rb +28 -0
  55. data/lib/flare/util.rb +34 -0
  56. data/lib/flare/util/bwlimit.rb +132 -0
  57. data/lib/flare/util/command_line.rb +79 -0
  58. data/lib/flare/util/conf.rb +71 -0
  59. data/lib/flare/util/constant.rb +25 -0
  60. data/lib/flare/util/conversion.rb +26 -0
  61. data/lib/flare/util/default_logger.rb +52 -0
  62. data/lib/flare/util/exception.rb +19 -0
  63. data/lib/flare/util/filesystem.rb +30 -0
  64. data/lib/flare/util/flared_conf.rb +33 -0
  65. data/lib/flare/util/flarei_conf.rb +32 -0
  66. data/lib/flare/util/hash_function.rb +32 -0
  67. data/lib/flare/util/interruption.rb +70 -0
  68. data/lib/flare/util/key_resolver.rb +67 -0
  69. data/lib/flare/util/log4r_logger.rb +79 -0
  70. data/lib/flare/util/logger.rb +40 -0
  71. data/lib/flare/util/logging.rb +84 -0
  72. data/lib/flare/util/result.rb +53 -0
  73. data/test/test/experimental/cache_test.rb +113 -0
  74. data/test/test/experimental/key_distribution_test.rb +38 -0
  75. data/test/test/experimental/keychecker_test.rb +60 -0
  76. data/test/test/experimental/list_test.rb +108 -0
  77. data/test/test/extra/replication_test.rb +184 -0
  78. data/test/test/integration/cli_test.rb +348 -0
  79. data/test/test/integration/dump_expired_test.rb +103 -0
  80. data/test/test/integration/dump_test.rb +128 -0
  81. data/test/test/integration/index_server_test.rb +35 -0
  82. data/test/test/integration/node_test.rb +78 -0
  83. data/test/test/integration/partition_test.rb +235 -0
  84. data/test/test/integration/proxy_test.rb +54 -0
  85. data/test/test/integration/stats_test.rb +79 -0
  86. data/test/test/system/flare_admin_test.rb +191 -0
  87. data/test/test/unit/bwlimit_test.rb +52 -0
  88. data/test/test/unit/cluster_test.rb +96 -0
  89. data/test/test/unit/daemon_test.rb +30 -0
  90. data/test/test/unit/logger_test.rb +46 -0
  91. data/test/test/unit/tools_test.rb +25 -0
  92. data/test/test/unit/util_test.rb +70 -0
  93. metadata +239 -84
  94. data/README.rdoc +0 -83
  95. data/bin/flare-partition-setting +0 -12
  96. data/lib/flare/tools/cli/partition_setting.rb +0 -86
  97. data/lib/flare/tools/core.rb +0 -189
  98. data/lib/flare/tools/logger.rb +0 -31
  99. data/test/test_flare-tools.rb +0 -11
  100. data/test/test_helper.rb +0 -3
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8; -*-
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../../../lib")
6
+
7
+ require 'test/unit'
8
+ require 'flare/tools'
9
+ require 'flare/test/cluster'
10
+
11
+ class ProxyTest < Test::Unit::TestCase
12
+ include Flare::Tools::Common
13
+
14
+ def setup
15
+ @flare_cluster = Flare::Test::Cluster.new('test')
16
+ sleep 1 # XXX
17
+ @node_servers = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
18
+ sleep 1 # XXX
19
+ @flare_cluster.wait_for_ready
20
+ @config = {
21
+ :command => 'dummy',
22
+ :index_server_hostname => @flare_cluster.indexname,
23
+ :index_server_port => @flare_cluster.indexport,
24
+ :dry_run => false,
25
+ :timeout => 10
26
+ }
27
+ end
28
+
29
+ def teardown
30
+ @flare_cluster.shutdown
31
+ end
32
+
33
+ def test_proxy1
34
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
35
+ Flare::Tools::Node.open(@flare_cluster.indexname, @flare_cluster.indexport, 10) do |s|
36
+ puts string_of_nodelist(s.stats_nodes)
37
+ node = @node_servers[1]
38
+ puts "throwing requests to #{node.hostname}:#{node.port}."
39
+ Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
40
+ value = lambda {|key| return "value of "+key }
41
+ fmt = "key%010.10d"
42
+ (0...10).each do |i|
43
+ n.set(fmt % i, value.call(fmt % i))
44
+ end
45
+ (0...10).each do |i|
46
+ assert_equal(value.call(fmt % i), n.get(fmt % i))
47
+ end
48
+ sleep 1
49
+ end
50
+ puts string_of_nodelist(s.stats_nodes)
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8; -*-
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__)+"/../../../lib")
6
+
7
+ require 'test/unit'
8
+ require 'flare/tools.rb'
9
+ require 'flare/test/daemon'
10
+ require 'flare/test/cluster'
11
+
12
+ class StatsTest < Test::Unit::TestCase
13
+ def setup
14
+ @flare_cluster = Flare::Test::Cluster.new('test')
15
+ sleep 1
16
+ @node_servers = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
17
+ sleep 1
18
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
19
+ end
20
+
21
+ def teardown
22
+ @flare_cluster.shutdown
23
+ end
24
+
25
+ def test_index_cluster_info
26
+ hostname = @flare_cluster.indexname
27
+ port = @flare_cluster.indexport
28
+ stats = Flare::Tools::Stats.new(hostname, port, 10)
29
+ cluster = Flare::Tools::Cluster.new(hostname, port, stats.stats_nodes)
30
+ assert_equal(cluster.size, @node_servers.size)
31
+ end
32
+
33
+ def test_node_cluster_info
34
+ clusters = @node_servers.map {|node_server|
35
+ hostname = node_server.hostname
36
+ port = node_server.port
37
+ stats = Flare::Tools::Stats.new(hostname, port, 10)
38
+ nodes = stats.stats_nodes
39
+ Flare::Tools::Cluster.new(hostname, port, nodes)
40
+ }
41
+ clusters.each {|cluster|
42
+ assert_equal(clusters[0].size, cluster.size)
43
+ }
44
+ end
45
+
46
+ def test_client_stats_threads
47
+ @node_servers.each {|node_server|
48
+ hostname = node_server.hostname
49
+ port = node_server.port
50
+ stats = Flare::Tools::Stats.new(hostname, port, 10)
51
+ r = stats.stats_threads
52
+ if stats.required_version?([1,0,10])
53
+ assert_not_equal({}, r)
54
+ else
55
+ assert_equal({}, r)
56
+ end
57
+ }
58
+ end
59
+
60
+ def test_version
61
+ @node_servers.each {|node_server|
62
+ hostname = node_server.hostname
63
+ port = node_server.port
64
+ stats = Flare::Tools::Stats.new(hostname, port, 10)
65
+ assert_equal(false, stats.required_version?([100,0,0]))
66
+ assert_equal(true, stats.required_version?([1,0,0]))
67
+ assert_equal(false, stats.required_version?([3,4,6], [3,4,5]))
68
+ assert_equal(true, stats.required_version?([3,4,5], [3,4,5]))
69
+ assert_equal(true, stats.required_version?([3,4,4], [3,4,5]))
70
+ assert_equal(false, stats.required_version?([3,5,5], [3,4,5]))
71
+ assert_equal(true, stats.required_version?([3,4,5], [3,4,5]))
72
+ assert_equal(true, stats.required_version?([3,3,5], [3,4,5]))
73
+ assert_equal(false, stats.required_version?([4,4,6], [3,4,5]))
74
+ assert_equal(true, stats.required_version?([3,4,5], [3,4,5]))
75
+ assert_equal(true, stats.required_version?([2,4,4], [3,4,5]))
76
+ }
77
+ end
78
+ end
79
+
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8; -*-
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__)+"/../lib"
5
+
6
+ require 'test/unit'
7
+ require 'flare/tools'
8
+ require 'flare/test/cluster'
9
+
10
+ ENV['FLARE_INDEX_SERVER'] = nil
11
+
12
+ class FlareAdminTest < Test::Unit::TestCase
13
+ Admin = "../bin/flare-admin"
14
+ S_OK = 0
15
+ S_NG = 1
16
+
17
+ def setup
18
+ @flare_cluster = Flare::Test::Cluster.new('test')
19
+ sleep 1 # XXX
20
+ @datanodes = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
21
+ sleep 1 # XXX
22
+ @flare_cluster.wait_for_ready
23
+ @indexname = @flare_cluster.indexname
24
+ @indexport = @flare_cluster.indexport
25
+ @opt_index = "--index-server=#{@indexname}:#{@indexport}"
26
+ end
27
+
28
+ def teardown
29
+ @flare_cluster.shutdown
30
+ end
31
+
32
+ def flare_admin_with_yes arg
33
+ cmd = "yes | #{Admin} #{arg}"
34
+ puts "> #{cmd}"
35
+ puts `#{cmd}`
36
+ $?.exitstatus
37
+ end
38
+
39
+ def flare_admin arg
40
+ cmd = "#{Admin} #{arg}"
41
+ puts "> #{cmd}"
42
+ puts `#{cmd}`
43
+ $?.exitstatus
44
+ end
45
+
46
+ def test_subc_simple1
47
+ flare_admin "help"
48
+ assert_equal(S_NG, $?.exitstatus)
49
+ flare_admin ""
50
+ assert_equal(S_NG, $?.exitstatus)
51
+ end
52
+
53
+ def test_common_option_long1
54
+ flare_admin "list --index-server"
55
+ assert_equal(S_NG, $?.exitstatus)
56
+ flare_admin "list --index-server-port"
57
+ assert_equal(S_NG, $?.exitstatus)
58
+ flare_admin "list --index-server --index-server-port"
59
+ assert_equal(S_NG, $?.exitstatus)
60
+ flare_admin "list --index-server=#{@indexname}:#{@indexport}"
61
+ assert_equal(S_OK, $?.exitstatus)
62
+ flare_admin "list --index-server=#{@indexname} --index-server-port=#{@indexport}"
63
+ assert_equal(S_OK, $?.exitstatus)
64
+ flare_admin "list --index-server=#{@indexname}:#{@indexport} --index-server-port=#{@indexport}"
65
+ assert_equal(S_NG, $?.exitstatus)
66
+ flare_admin "list --log-file"
67
+ assert_equal(S_NG, $?.exitstatus)
68
+ flare_admin "list --log-file=/"
69
+ assert_equal(S_NG, $?.exitstatus)
70
+ flare_admin "list --log-file=''"
71
+ assert_equal(S_NG, $?.exitstatus)
72
+ flare_admin "list --log-file=''"
73
+ assert_equal(S_NG, $?.exitstatus)
74
+ flare_admin "list #{@opt_index} --dry-run"
75
+ assert_equal(S_OK, $?.exitstatus)
76
+ end
77
+
78
+ def test_common_option_short1
79
+ flare_admin "list"
80
+ assert_equal(S_NG, $?.exitstatus)
81
+ flare_admin "list -i"
82
+ assert_equal(S_NG, $?.exitstatus)
83
+ flare_admin "list -i -p"
84
+ assert_equal(S_NG, $?.exitstatus)
85
+ flare_admin "list -p"
86
+ assert_equal(S_NG, $?.exitstatus)
87
+ flare_admin "list -i #{@indexname}:#{@indexport}"
88
+ assert_equal(S_OK, $?.exitstatus)
89
+ flare_admin "list -i #{@indexname} -p #{@indexport}"
90
+ assert_equal(S_OK, $?.exitstatus)
91
+ flare_admin "list -i #{@indexname}:#{@indexport} -p #{@indexport}"
92
+ assert_equal(S_NG, $?.exitstatus)
93
+ end
94
+
95
+ def test_list_simple1
96
+ flare_admin "list"
97
+ assert_equal(S_NG, $?.exitstatus)
98
+ flare_admin "list --index-server=#{@indexname}:#{@indexport}"
99
+ assert_equal(S_OK, $?.exitstatus)
100
+ flare_admin "list --index-server=#{@indexname}:#{@indexport} --index-server-port=#{@indexport}"
101
+ assert_equal(S_NG, $?.exitstatus)
102
+ flare_admin "list #{@opt_index} --numeric-hosts"
103
+ assert_equal(S_OK, $?.exitstatus)
104
+ end
105
+
106
+ def test_log_file1
107
+ filename = "logfile.log"
108
+ exist = File.exist?(filename)
109
+ flare_admin "list --log-file=#{filename}"
110
+ assert_equal(S_NG, $?.exitstatus)
111
+ exist = File.exist?(filename)
112
+ assert_equal(true, exist)
113
+ ensure
114
+ File.delete(filename) if exist
115
+ end
116
+
117
+ def test_ping_simple1
118
+ flare_admin "ping"
119
+ assert_equal(S_OK, $?.exitstatus)
120
+ flare_admin "ping #{@indexname}:#{@indexport}"
121
+ assert_equal(S_OK, $?.exitstatus)
122
+ flare_admin "ping #{@datanodes[0].hostname}:#{@datanodes[0].port}"
123
+ assert_equal(S_OK, $?.exitstatus)
124
+ flare_admin "ping #{@datanodes[0].hostname}:23"
125
+ assert_equal(S_NG, $?.exitstatus)
126
+ end
127
+
128
+ def test_ping_wait1
129
+ flare_admin "ping --wait"
130
+ assert_equal(S_OK, $?.exitstatus)
131
+ flare_admin "ping --wait #{@indexname}:#{@indexport}"
132
+ assert_equal(S_OK, $?.exitstatus)
133
+ flare_admin "ping --wait #{@datanodes[0].hostname}:#{@datanodes[0].port}"
134
+ assert_equal(S_OK, $?.exitstatus)
135
+ end
136
+
137
+ def test_thread_simple1
138
+ flare_admin "threads"
139
+ assert_equal(S_NG, $?.exitstatus)
140
+ flare_admin "threads --index-server=#{@indexname}:#{@indexport}"
141
+ assert_equal(S_OK, $?.exitstatus)
142
+ flare_admin "threads #{@indexname}:#{@indexport}"
143
+ assert_equal(S_OK, $?.exitstatus)
144
+ flare_admin "threads #{@datanodes[0].hostname}:#{@datanodes[0].port}"
145
+ assert_equal(S_OK, $?.exitstatus)
146
+ end
147
+
148
+ def test_master_simple1
149
+ h = @datanodes[0].hostname
150
+ p = @datanodes[0].port
151
+ flare_admin_with_yes "master --index-server=#{@indexname}:#{@indexport} #{h}:#{p}:1:0"
152
+ assert_equal(S_OK, $?.exitstatus)
153
+ end
154
+
155
+ def test_reconstruct_simple1
156
+ h = @datanodes[0].hostname
157
+ p = @datanodes[0].port
158
+ flare_admin_with_yes "master --index-server=#{@indexname}:#{@indexport} #{h}:#{p}:1:0"
159
+ assert_equal(S_OK, $?.exitstatus)
160
+ h = @datanodes[1].hostname
161
+ p = @datanodes[1].port
162
+ flare_admin_with_yes "slave --index-server=#{@indexname}:#{@indexport} #{h}:#{p}:1:0"
163
+ assert_equal(S_OK, $?.exitstatus)
164
+ flare_admin_with_yes "reconstruct --index-server=#{@indexname}:#{@indexport} --all"
165
+ assert_equal(S_OK, $?.exitstatus)
166
+ end
167
+
168
+ def test_index_servers_env1
169
+ ENV["FLARE_INDEX_SERVERS"] = "clustername:#{@indexname}:#{@indexport}"
170
+ flare_admin "list"
171
+ assert_equal(S_NG, $?.exitstatus)
172
+ h = @datanodes[0].hostname
173
+ p = @datanodes[0].port
174
+ flare_admin_with_yes "master #{h}:#{p}:1:0"
175
+ assert_equal(S_OK, $?.exitstatus)
176
+ ensure
177
+ ENV["FLARE_INDEX_SERVERS"] = nil
178
+ end
179
+
180
+ def test_index_servers_env2
181
+ ENV["FLARE_INDEX_SERVERS"] = "clustername:#{@indexname}:#{@indexport}"
182
+ flare_admin "list"
183
+ assert_equal(S_NG, $?.exitstatus)
184
+ flare_admin "list --cluster=clustername"
185
+ assert_equal(S_OK, $?.exitstatus)
186
+ ensure
187
+ ENV["FLARE_INDEX_SERVERS"] = nil
188
+ end
189
+
190
+ end
191
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8; -*-
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__)+"/../lib"
5
+
6
+ require 'test/unit'
7
+ require 'flare/util/bwlimit'
8
+ require 'timeout'
9
+
10
+ class BwlimitTest < Test::Unit::TestCase
11
+ Bwlimit = Flare::Util::Bwlimit
12
+
13
+ def setup
14
+
15
+ end
16
+
17
+ def bps(s, scale)
18
+ assert_equal(0, Bwlimit.bps("#{s}B"), "#{s}B")
19
+ assert_equal(100*scale, Bwlimit.bps("100#{s}"), "100#{s}")
20
+ assert_equal(100*scale*8, Bwlimit.bps("100#{s}B"), "100#{s}B")
21
+ assert_equal(10000*scale, Bwlimit.bps("10000#{s}"), "10000#{s}")
22
+ assert_equal(10000*scale*8, Bwlimit.bps("10000#{s}B"), "10000#{s}B")
23
+ end
24
+
25
+ def test_bps1
26
+ bps("", 1)
27
+ bps("k", 1024)
28
+ bps("M", 1024*1024)
29
+ bps("G", 1024*1024*1024)
30
+ end
31
+
32
+ def test_limit1
33
+ duration = 5
34
+ size = 100
35
+ total = size*1024*duration
36
+ bwlimit = Bwlimit.new("#{size}kB")
37
+ assert_nothing_raised {
38
+ timeout(duration*1.5) {
39
+ while bwlimit.totalbytes < total
40
+ bwlimit.inc((1500*(rand+1)).to_i)
41
+ bwlimit.wait
42
+ # puts "#{bwlimit.speed} bps, #{bwlimit.totalbytes}/#{total} bytes"
43
+ end
44
+ }
45
+ }
46
+ bwlimit.history.each do |e|
47
+ t, b = e[:time], e[:speed]
48
+ puts "#{t}, #{b}"
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8; -*-
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__)+"/../lib"
5
+
6
+ require 'test/unit'
7
+ require 'flare/tools/cluster'
8
+
9
+ class ClusterTest < Test::Unit::TestCase
10
+ def setup
11
+ data = [
12
+ ["host1:12121", {"partition"=>"-1", "port"=>"12121", "thread_type"=>"17", "role"=>"proxy", "balance"=>"0", "state"=>"down"}],
13
+ ["host2:12121", {"partition"=>"0", "port"=>"12121", "thread_type"=>"16", "role"=>"master", "balance"=>"4", "state"=>"active"}],
14
+ ["host2:12122", {"partition"=>"0", "port"=>"12121", "thread_type"=>"16", "role"=>"slave", "balance"=>"4", "state"=>"active"}],
15
+ ["host3:12121", {"partition"=>"0", "port"=>"12121", "thread_type"=>"18", "role"=>"slave", "balance"=>"100", "state"=>"prepare"}],
16
+ ["host4:12121", {"partition"=>"1", "port"=>"12121", "thread_type"=>"18", "role"=>"master", "balance"=>"1", "state"=>"ready"}],
17
+ ]
18
+ @cluster = Flare::Tools::Cluster.new('127.0.0.1', 12120, data)
19
+ @expected = data
20
+ end
21
+
22
+ def teardown
23
+ end
24
+
25
+ def test_cluster_simple1
26
+ assert_equal(nil, @cluster.node_stat("xxx:12121"))
27
+ assert_equal("host2:12121", @cluster.master_in_partition(0))
28
+ assert_equal(["host2:12122", "host3:12121"].sort, @cluster.slaves_in_partition(0).sort)
29
+ end
30
+
31
+ def test_cluster_reconstructable1
32
+ assert_equal(true, @cluster.reconstructable?("host2:12121"))
33
+ assert_equal(false, @cluster.safely_reconstructable?("host2:12121"))
34
+ end
35
+
36
+ def test_cluster_stat1
37
+ n1 = @cluster.node_stat("host1:12121")
38
+ assert_equal(-1, n1.partition)
39
+ assert_equal(17, n1.thread_type)
40
+ assert_equal(true, n1.proxy?)
41
+ assert_equal(0, n1.balance)
42
+ assert_equal(true, n1.down?)
43
+
44
+ n2 = @cluster.node_stat("host2:12121")
45
+ assert_equal(0, n2.partition)
46
+ assert_equal(16, n2.thread_type)
47
+ assert_equal(true, n2.master?)
48
+ assert_equal(4, n2.balance)
49
+ assert_equal(true, n2.active?)
50
+
51
+ n3 = @cluster.node_stat("host2:12122")
52
+ assert_equal(0, n3.partition)
53
+ assert_equal(16, n3.thread_type)
54
+ assert_equal(true, n3.slave?)
55
+ assert_equal(4, n3.balance)
56
+ assert_equal(true, n3.active?)
57
+
58
+ n4 = @cluster.node_stat("host3:12121")
59
+ assert_equal(0, n4.partition)
60
+ assert_equal(18, n4.thread_type)
61
+ assert_equal(true, n4.slave?)
62
+ assert_equal(100, n4.balance)
63
+ assert_equal(true, n4.prepare?)
64
+
65
+ n5 = @cluster.node_stat("host4:12121")
66
+ assert_equal(1, n5.partition)
67
+ assert_equal(18, n5.thread_type)
68
+ assert_equal(true, n5.master?)
69
+ assert_equal(1, n5.balance)
70
+ assert_equal(true, n5.ready?)
71
+ end
72
+
73
+ def test_cluster_stat2
74
+ @expected.each do |i|
75
+ begin
76
+ nodekey, data = i
77
+ n = @cluster.node_stat(nodekey)
78
+ assert_equal(data['partition'].to_i, n.partition)
79
+ assert_equal(data['thread_type'].to_i, n.thread_type)
80
+ assert_equal(data['role'] == 'proxy', n.proxy?)
81
+ assert_equal(data['role'] == 'master', n.master?)
82
+ assert_equal(data['role'] == 'slave', n.slave?)
83
+ assert_equal(data['balance'].to_i, n.balance)
84
+ assert_equal(data['state'] == 'down', n.down?)
85
+ assert_equal(data['state'] == 'prepare', n.prepare?)
86
+ assert_equal(data['state'] == 'ready', n.ready?)
87
+ assert_equal(data['state'] == 'active', n.active?)
88
+ rescue => e
89
+ p i
90
+ raise e
91
+ end
92
+ end
93
+ end
94
+
95
+ end
96
+