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,348 @@
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 'rubygems'
8
+ gem 'test-unit'
9
+ require 'test/unit'
10
+ require 'flare/tools'
11
+ require 'flare/tools/cli'
12
+ require 'flare/test/cluster'
13
+ require 'subcommands'
14
+
15
+ class CliTest < Test::Unit::TestCase
16
+ include Flare::Tools::Common
17
+ include Subcommands
18
+
19
+ def setup
20
+ @flare_cluster = Flare::Test::Cluster.new('test')
21
+ sleep 1 # XXX
22
+ @node_servers = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
23
+ sleep 1 # XXX
24
+ @flare_cluster.wait_for_ready
25
+ @config = {
26
+ :command => 'dummy',
27
+ :index_server_hostname => @flare_cluster.indexname,
28
+ :index_server_port => @flare_cluster.indexport,
29
+ :dry_run => false,
30
+ :timeout => 10
31
+ }
32
+ end
33
+
34
+ def teardown
35
+ @flare_cluster.shutdown
36
+ end
37
+
38
+ def test_ping_simple_call1
39
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
40
+ for node in @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
41
+ assert_equal(S_OK, ping(node))
42
+ end
43
+ end
44
+
45
+ def test_ping_invalid_argument1
46
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
47
+ for node in @node_servers.map{|n| "#{n.hostname}"}
48
+ assert_equal(S_NG, ping(node))
49
+ end
50
+ for node in @node_servers.map{|n| ":#{n.port}"}
51
+ assert_equal(S_NG, ping(node))
52
+ end
53
+ for node in @node_servers.map{|n| "#{n.hostname}:#{n.port}:1"}
54
+ assert_equal(S_NG, ping(node))
55
+ end
56
+ end
57
+
58
+ def test_ping_all_nodes1
59
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
60
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
61
+ assert_equal(S_OK, ping(*args))
62
+ end
63
+
64
+ def test_ping_without_daemon1
65
+ @node_servers.each {|n| n.terminate}
66
+ # sleep 1
67
+ for node in @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
68
+ assert_equal(S_NG, ping(node))
69
+ end
70
+ end
71
+
72
+ def test_list_simple_call1
73
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
74
+ assert_equal(S_OK, list())
75
+ assert_equal(S_OK, list('--numeric-hosts'))
76
+ end
77
+
78
+ def test_list
79
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
80
+ assert_equal(S_OK, list())
81
+ assert_equal(S_OK, list('--numeric-hosts'))
82
+ end
83
+
84
+ def test_list_log_file1
85
+ File.delete("list.log") if File.exist?("list.log")
86
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
87
+ Flare::Util::Logging.set_logger('list.log')
88
+ assert_equal(S_OK, list())
89
+ assert_equal(true, File.exist?("list.log"))
90
+ File.delete("list.log") if File.exist?("list.log")
91
+ end
92
+
93
+ def test_stats_simple_call1
94
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
95
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
96
+ assert_equal(S_OK, stats())
97
+ assert_equal(S_OK, stats('--qps', '--count=5'))
98
+ assert_equal(S_OK, stats('--qps', '--wait=2', '--count=3'))
99
+ end
100
+
101
+ def test_down_all_nodes1
102
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
103
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
104
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
105
+ assert_equal(S_OK, down(*args))
106
+ end
107
+
108
+ def test_down_simple_call1
109
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
110
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
111
+ args = @node_servers[0..1].map{|n| "#{n.hostname}:#{n.port}"}
112
+ assert_equal(S_OK, down(*args))
113
+ end
114
+
115
+ def test_down_except_last_one1
116
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
117
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
118
+ targets = @node_servers.dup
119
+ targets.shift
120
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"}
121
+ assert_equal(S_OK, down(*args))
122
+ end
123
+
124
+ def test_slave_simple_call1
125
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
126
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
127
+ targets = @node_servers.dup
128
+ targets.shift
129
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"}
130
+ assert_equal(S_OK, down(*args))
131
+ newbalance = 1
132
+ args = targets.map{|n| "#{n.hostname}:#{n.port}:#{newbalance}:0"}
133
+ # sleep 3
134
+ assert_equal(S_OK, slave(*args))
135
+ end
136
+
137
+ def test_slave_with_option_clean1
138
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
139
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
140
+ targets = @node_servers.dup
141
+ targets.shift # remove master
142
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"}
143
+ assert_equal(S_OK, down(*args))
144
+ @flare_cluster.clear_data(@node_servers[0])
145
+ newbalance = 1
146
+ args = targets.map{|n| "#{n.hostname}:#{n.port}:#{newbalance}:0"} << "--clean"
147
+ # sleep 3
148
+ assert_equal(S_OK, slave(*args))
149
+ size = targets.map {|slave| slave.open { |n| n.stats['cur_items'].to_i } }
150
+ assert_equal(0, size[0])
151
+ assert_equal(0, size[1])
152
+ end
153
+
154
+ def test_balance_simple_call1
155
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
156
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
157
+ newbalance = 4
158
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}:#{newbalance}"}
159
+ assert_equal(S_OK, balance(*args))
160
+ end
161
+
162
+ def test_balance_invalid_argument1
163
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
164
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
165
+ newbalance = 4
166
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
167
+ assert_equal(S_NG, balance(*args))
168
+ end
169
+
170
+ def test_reconstruct_simple_call1
171
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
172
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
173
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
174
+ assert_equal(S_OK, reconstruct(*args))
175
+ end
176
+
177
+ def test_reconstruct_invalid_argument1
178
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
179
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
180
+ args = @node_servers.map{|n| "#{n.hostname}"}
181
+ assert_equal(S_NG, reconstruct(*args))
182
+ args = @node_servers.map{|n| ":#{n.port}"}
183
+ assert_equal(S_NG, reconstruct(*args))
184
+ end
185
+
186
+ def test_reconstruct_reconstructable1
187
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
188
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
189
+ args = @node_servers.dup[1..-1].map{|n| "#{n.hostname}:#{n.port}"}
190
+ assert_equal(S_OK, down(*args))
191
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"}
192
+ assert_equal(S_NG, reconstruct(*args))
193
+ end
194
+
195
+ def test_reconstruct_unsafe1
196
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
197
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
198
+ targets = @node_servers.dup[2..-1]
199
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"}
200
+ assert_equal(S_OK, down(*args))
201
+ args = @node_servers.map{|n| "#{n.hostname}:#{n.port}"} << "--safe"
202
+ assert_equal(S_NG, reconstruct(*args))
203
+ end
204
+
205
+ def test_index_simple_call1
206
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
207
+ @flare_cluster.prepare_data(@node_servers[0], "key", 10)
208
+ assert_equal(S_OK, index())
209
+ end
210
+
211
+ def remove_boostheader(s)
212
+ lines = s.split("\n")
213
+ h1 = lines.shift
214
+ h2 = lines.shift
215
+ lines.shift
216
+ lines.unshift(h2)
217
+ lines.unshift(h1)
218
+ lines.join("\n")
219
+ end
220
+
221
+ def test_index_output_ident1
222
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
223
+ @flare_cluster.prepare_data(@node_servers[0], "key", 10)
224
+ args = ["--output=flare.xml"]
225
+ assert_equal(S_OK, index(*args))
226
+ assert_equal(true, File.exist?("flare.xml"))
227
+ flarexml = remove_boostheader(open("flare.xml").read)
228
+ indexxml = remove_boostheader(@flare_cluster.index)
229
+ assert_equal(indexxml, flarexml)
230
+ File.delete("flare.xml")
231
+ end
232
+
233
+ def test_remove_simple_call1
234
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
235
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
236
+ targets = @node_servers.dup
237
+ master = targets.shift
238
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"}
239
+ assert_equal(S_OK, down(*args))
240
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"} << "--connection-threshold=4"
241
+ # sleep 3
242
+ assert_equal(S_OK, remove(*args))
243
+ assert_equal(false, @flare_cluster.exist?(args[0]))
244
+ assert_equal(false, @flare_cluster.exist?(args[1]))
245
+ end
246
+
247
+ def test_remove_unremovable1
248
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
249
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
250
+ targets = @node_servers.dup
251
+ master = targets.shift
252
+ args = targets.map{|n| "#{n.hostname}:#{n.port}"} << "--connection-threshold=4" << "--wait=3"
253
+ assert_equal(S_OK, remove(*args))
254
+ assert_equal(true, @flare_cluster.exist?(args[0]))
255
+ assert_equal(true, @flare_cluster.exist?(args[1]))
256
+ end
257
+
258
+ def test_master_simple1
259
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
260
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
261
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
262
+ assert_equal(S_OK, down(*args))
263
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
264
+ assert_equal(S_OK, activate(*args))
265
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}:1:1"}
266
+ assert_equal(S_OK, master(*args))
267
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
268
+ assert_equal(S_OK, activate(*args))
269
+ end
270
+
271
+ def test_master_activate1
272
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
273
+ @flare_cluster.prepare_data(@node_servers[0], "key", 1000)
274
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
275
+ assert_equal(S_OK, down(*args))
276
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
277
+ assert_equal(S_OK, activate(*args))
278
+ args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
279
+ assert_equal(S_OK, master(*args))
280
+ end
281
+
282
+ def test_dump1
283
+
284
+ end
285
+
286
+ def test_dumpkey1
287
+ args = @node_servers[0..0].map{|n| "#{n.hostname}:#{n.port}:1:0"}
288
+ assert_equal(S_OK, master(*args))
289
+ args = @node_servers[1..1].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
290
+ assert_equal(S_OK, master(*args))
291
+ args = @node_servers[2..2].map{|n| "#{n.hostname}:#{n.port}:1:2"} << "--activate"
292
+ assert_equal(S_OK, master(*args))
293
+ @flare_cluster.prepare_data(@node_servers[0], "key", 10000)
294
+ args = @node_servers[0..2].map{|n| "#{n.hostname}:#{n.port}"} << "--bwlimit=800k" << "--output=keys.txt"
295
+ assert_equal(S_OK, dumpkey(*args))
296
+ File.delete("keys.txt") if File.exist?("keys.txt")
297
+ end
298
+
299
+ def test_dumpkey2
300
+ args = @node_servers[0..0].map{|n| "#{n.hostname}:#{n.port}:1:0"}
301
+ assert_equal(S_OK, master(*args))
302
+ args = @node_servers[1..1].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
303
+ assert_equal(S_OK, master(*args))
304
+ args = @node_servers[2..2].map{|n| "#{n.hostname}:#{n.port}:1:2"} << "--activate"
305
+ assert_equal(S_OK, master(*args))
306
+ @flare_cluster.prepare_data(@node_servers[0], "key", 10000)
307
+ args = ["--all"]
308
+ args << "--bwlimit=800k" << "--output=keys.txt"
309
+ assert_equal(S_OK, dumpkey(*args))
310
+ File.delete("keys.txt") if File.exist?("keys.txt")
311
+ end
312
+
313
+ def test_verify1
314
+ args = @node_servers[0..0].map{|n| "#{n.hostname}:#{n.port}:1:0"}
315
+ assert_equal(S_OK, master(*args))
316
+ args = @node_servers[1..1].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
317
+ assert_equal(S_OK, master(*args))
318
+ args = @node_servers[2..2].map{|n| "#{n.hostname}:#{n.port}:1:2"} << "--activate"
319
+ assert_equal(S_OK, master(*args))
320
+ kha = if Flare::Test::Daemon.instance.required_version? [1, 0, 15] then "crc32" else "simple" end
321
+ args = ["--use-test-data", "--key-hash-algorithm=#{kha}"]
322
+ assert_equal(S_OK, verify(*args))
323
+ end
324
+
325
+ def test_verify2
326
+ args = @node_servers[0..0].map{|n| "#{n.hostname}:#{n.port}:1:0"}
327
+ assert_equal(S_OK, master(*args))
328
+ args = @node_servers[1..1].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
329
+ assert_equal(S_OK, master(*args))
330
+ args = @node_servers[2..2].map{|n| "#{n.hostname}:#{n.port}:1:2"} << "--activate"
331
+ assert_equal(S_OK, master(*args))
332
+ kha = unless Flare::Test::Daemon.instance.required_version? [1, 0, 15] then "crc32" else "simple" end
333
+ args = ["--use-test-data", "--key-hash-algorithm=#{kha}"]
334
+ assert_equal(S_NG, verify(*args))
335
+ end
336
+
337
+ def test_verify3
338
+ args = @node_servers[0..0].map{|n| "#{n.hostname}:#{n.port}:1:0"}
339
+ assert_equal(S_OK, master(*args))
340
+ args = @node_servers[1..1].map{|n| "#{n.hostname}:#{n.port}:1:1"} << "--activate"
341
+ assert_equal(S_OK, master(*args))
342
+ args = @node_servers[2..2].map{|n| "#{n.hostname}:#{n.port}:1:2"} << "--activate"
343
+ assert_equal(S_OK, master(*args))
344
+ args = ["--use-test-data", "--meta"]
345
+ assert_equal(S_OK, verify(*args))
346
+ end
347
+
348
+ end
@@ -0,0 +1,103 @@
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/daemon'
10
+ require 'flare/test/cluster'
11
+ require 'subcommands'
12
+
13
+ class DumpExpiredTest < Test::Unit::TestCase
14
+ include Flare::Tools::Common
15
+ include Subcommands
16
+
17
+ def setup
18
+ @flare_cluster = Flare::Test::Cluster.new('test')
19
+ sleep 1 # XXX
20
+ @node_servers = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
21
+ sleep 1 # XXX
22
+ @flare_cluster.wait_for_ready
23
+ @config = {
24
+ :command => 'dummy',
25
+ :index_server_hostname => @flare_cluster.indexname,
26
+ :index_server_port => @flare_cluster.indexport,
27
+ :dry_run => false,
28
+ :timeout => 10
29
+ }
30
+ end
31
+
32
+ def teardown
33
+ @flare_cluster.shutdown
34
+ end
35
+
36
+ def test_dump_expired
37
+ efmt = "key%05.5d"
38
+ mfmt = "exp%05.5d"
39
+ statsth = Thread.new do
40
+ stats('--count=40')
41
+ end
42
+ @flare_cluster.prepare_master_and_slaves(@node_servers)
43
+ master = @node_servers[0]
44
+ m = Flare::Tools::Node.open(master.hostname, master.port, 10)
45
+ (0...1000).each do |i|
46
+ m.set(mfmt % i, "MORTAL", 0, 1)
47
+ end
48
+ sleep 3
49
+ @node_servers[1..2].each do |node|
50
+ dumpth = Thread.new do
51
+ Flare::Tools::Node.open(node.hostname, node.port, 10) do |dn|
52
+ puts "DUMP START."
53
+ dn.dump(1000) do |data, key, flag, len, version, expire|
54
+ if key =~ /exp.*/
55
+ print " #{key}(#{expire})"
56
+ assert_equal("MORTAL", data)
57
+ assert_not_equal(0, expire)
58
+ end
59
+ end
60
+ puts "DUMP DONE."
61
+ end
62
+ end
63
+ Flare::Tools::Node.open(master.hostname, master.port, 10) do |n|
64
+ puts "SET START."
65
+ flag = 0
66
+ expire = 3
67
+ (0...1000).each do |i|
68
+ m.set(efmt % i, "ETERNAL", 0, 0)
69
+ n.set(mfmt % i, "MORTAL", flag, expire+rand(3))
70
+ n.get(mfmt % (rand(i)))
71
+ end
72
+ puts "SET DONE."
73
+ end
74
+ dumpth.join
75
+ end
76
+ statsth.join
77
+ puts "checking ..."
78
+ stats
79
+ items = @node_servers[1..2].map do |node|
80
+ Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
81
+ n.stats["curr_items"].to_i
82
+ end
83
+ end
84
+ assert(items[0] >= items[1], "#{items[0]} < #{items[1]}")
85
+ puts "dumping again..."
86
+ sleep 8
87
+ @node_servers[0..2].each do |node|
88
+ Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
89
+ n.dump
90
+ end
91
+ end
92
+ puts "checking again ..."
93
+ stats
94
+ items = @node_servers[1..2].map do |node|
95
+ Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
96
+ n.stats["curr_items"].to_i
97
+ end
98
+ end
99
+ assert(items[0] >= items[1], "#{items[0]} < #{items[1]}")
100
+ m.close
101
+ end
102
+ end
103
+