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.
- data/.gemtest +0 -0
- data/Flare-tools.txt +0 -0
- data/History.txt +114 -2
- data/LICENSE +21 -0
- data/Manifest.txt +65 -8
- data/README.txt +356 -0
- data/Rakefile +90 -25
- data/Tutorial.txt +370 -0
- data/bin/flare-admin +6 -0
- data/bin/flare-argv0 +6 -0
- data/bin/flare-deploy +6 -0
- data/bin/flare-keychecker +6 -0
- data/bin/flare-part +6 -0
- data/bin/flare-ping +6 -0
- data/bin/flare-stats +4 -10
- data/bin/flare-zkadmin +6 -0
- data/lib/flare/net/connection.rb +98 -0
- data/lib/flare/test/cluster.rb +140 -0
- data/lib/flare/test/daemon.rb +144 -0
- data/lib/flare/test/node.rb +62 -0
- data/lib/flare/tools.rb +18 -16
- data/lib/flare/tools/cli.rb +32 -0
- data/lib/flare/tools/cli/activate.rb +106 -0
- data/lib/flare/tools/cli/balance.rb +83 -0
- data/lib/flare/tools/cli/cli_util.rb +77 -0
- data/lib/flare/tools/cli/deploy.rb +170 -0
- data/lib/flare/tools/cli/down.rb +85 -0
- data/lib/flare/tools/cli/dump.rb +219 -0
- data/lib/flare/tools/cli/dumpkey.rb +117 -0
- data/lib/flare/tools/cli/flare_admin.rb +81 -0
- data/lib/flare/tools/cli/flare_argv0.rb +60 -0
- data/lib/flare/tools/cli/flare_keychecker.rb +106 -0
- data/lib/flare/tools/cli/flare_zkadmin.rb +226 -0
- data/lib/flare/tools/cli/index.rb +54 -0
- data/lib/flare/tools/cli/list.rb +93 -0
- data/lib/flare/tools/cli/master.rb +143 -0
- data/lib/flare/tools/cli/part.rb +100 -0
- data/lib/flare/tools/cli/ping.rb +81 -0
- data/lib/flare/tools/cli/reconstruct.rb +164 -0
- data/lib/flare/tools/cli/remove.rb +119 -0
- data/lib/flare/tools/cli/restore.rb +180 -0
- data/lib/flare/tools/cli/slave.rb +125 -0
- data/lib/flare/tools/cli/stats.rb +229 -122
- data/lib/flare/tools/cli/sub_command.rb +73 -0
- data/lib/flare/tools/cli/summary.rb +97 -0
- data/lib/flare/tools/cli/threads.rb +78 -0
- data/lib/flare/tools/cli/verify.rb +202 -0
- data/lib/flare/tools/client.rb +267 -0
- data/lib/flare/tools/cluster.rb +319 -0
- data/lib/flare/tools/common.rb +196 -0
- data/lib/flare/tools/index_server.rb +51 -0
- data/lib/flare/tools/node.rb +162 -0
- data/lib/flare/tools/stats.rb +75 -0
- data/lib/flare/tools/zk_util.rb +28 -0
- data/lib/flare/util.rb +34 -0
- data/lib/flare/util/bwlimit.rb +132 -0
- data/lib/flare/util/command_line.rb +79 -0
- data/lib/flare/util/conf.rb +71 -0
- data/lib/flare/util/constant.rb +25 -0
- data/lib/flare/util/conversion.rb +26 -0
- data/lib/flare/util/default_logger.rb +52 -0
- data/lib/flare/util/exception.rb +19 -0
- data/lib/flare/util/filesystem.rb +30 -0
- data/lib/flare/util/flared_conf.rb +33 -0
- data/lib/flare/util/flarei_conf.rb +32 -0
- data/lib/flare/util/hash_function.rb +32 -0
- data/lib/flare/util/interruption.rb +70 -0
- data/lib/flare/util/key_resolver.rb +67 -0
- data/lib/flare/util/log4r_logger.rb +79 -0
- data/lib/flare/util/logger.rb +40 -0
- data/lib/flare/util/logging.rb +84 -0
- data/lib/flare/util/result.rb +53 -0
- data/test/test/experimental/cache_test.rb +113 -0
- data/test/test/experimental/key_distribution_test.rb +38 -0
- data/test/test/experimental/keychecker_test.rb +60 -0
- data/test/test/experimental/list_test.rb +108 -0
- data/test/test/extra/replication_test.rb +184 -0
- data/test/test/integration/cli_test.rb +348 -0
- data/test/test/integration/dump_expired_test.rb +103 -0
- data/test/test/integration/dump_test.rb +128 -0
- data/test/test/integration/index_server_test.rb +35 -0
- data/test/test/integration/node_test.rb +78 -0
- data/test/test/integration/partition_test.rb +235 -0
- data/test/test/integration/proxy_test.rb +54 -0
- data/test/test/integration/stats_test.rb +79 -0
- data/test/test/system/flare_admin_test.rb +191 -0
- data/test/test/unit/bwlimit_test.rb +52 -0
- data/test/test/unit/cluster_test.rb +96 -0
- data/test/test/unit/daemon_test.rb +30 -0
- data/test/test/unit/logger_test.rb +46 -0
- data/test/test/unit/tools_test.rb +25 -0
- data/test/test/unit/util_test.rb +70 -0
- metadata +239 -84
- data/README.rdoc +0 -83
- data/bin/flare-partition-setting +0 -12
- data/lib/flare/tools/cli/partition_setting.rb +0 -86
- data/lib/flare/tools/core.rb +0 -189
- data/lib/flare/tools/logger.rb +0 -31
- data/test/test_flare-tools.rb +0 -11
- data/test/test_helper.rb +0 -3
@@ -0,0 +1,128 @@
|
|
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 DumpTest < Test::Unit::TestCase
|
16
|
+
include Flare::Tools::Common
|
17
|
+
include Subcommands
|
18
|
+
|
19
|
+
def setup
|
20
|
+
File.delete("src.tch") if File.exist?("src.tch")
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
File.delete("src.tch") if File.exist?("src.tch")
|
25
|
+
end
|
26
|
+
|
27
|
+
def prepare cluster, partitions, ranges
|
28
|
+
sleep 1 # XXX
|
29
|
+
nodes = (1..6).map {|n| cluster.create_node("node#{n}")}
|
30
|
+
sleep 1 # XXX
|
31
|
+
cluster.wait_for_ready
|
32
|
+
partitions.each do |p|
|
33
|
+
cluster.prepare_master_and_slaves(nodes.values_at(*ranges[p]), p)
|
34
|
+
end
|
35
|
+
nodes
|
36
|
+
end
|
37
|
+
|
38
|
+
def dump_and_restore(range, prefixes, extra_dump_options, extra_restore_options, &check)
|
39
|
+
expected_data = [1, 2, 3, 4, 5, 6, 7, 8, 9].pack("c*")
|
40
|
+
expected_flag = 1234
|
41
|
+
expected_expire = 2000000000
|
42
|
+
# prepare
|
43
|
+
ranges = [[0, 1], [2, 3], [4, 5]]
|
44
|
+
src_cluster = Flare::Test::Cluster.new('src')
|
45
|
+
puts "preparing src"
|
46
|
+
src_nodes = prepare(src_cluster, [0], ranges)
|
47
|
+
puts "storing"
|
48
|
+
range.each do |i|
|
49
|
+
src_nodes[0].open do |n|
|
50
|
+
prefixes.each do |prefix|
|
51
|
+
n.set("#{prefix}::#{i}", expected_data, expected_flag, expected_expire)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
src_nodes = prepare(src_cluster, [1, 2], ranges)
|
56
|
+
puts "preparing dest"
|
57
|
+
dest_cluster = Flare::Test::Cluster.new('dest')
|
58
|
+
dest_nodes = prepare(dest_cluster, [0, 1, 2], ranges)
|
59
|
+
|
60
|
+
puts "dumping"
|
61
|
+
@config = {
|
62
|
+
:index_server_hostname => src_cluster.indexname,
|
63
|
+
:index_server_port => src_cluster.indexport,
|
64
|
+
:timeout => 10
|
65
|
+
}
|
66
|
+
args = %w(--format=tch --output=src.tch)
|
67
|
+
args.concat extra_dump_options
|
68
|
+
assert_equal(S_OK, dump(*args))
|
69
|
+
|
70
|
+
@config = {
|
71
|
+
:index_server_hostname => dest_cluster.indexname,
|
72
|
+
:index_server_port => dest_cluster.indexport,
|
73
|
+
:timeout => 10
|
74
|
+
}
|
75
|
+
n = dest_nodes[0]
|
76
|
+
args = %w(--format=tch --input=src.tch)
|
77
|
+
args.concat extra_restore_options
|
78
|
+
args << "#{n.hostname}:#{n.port}"
|
79
|
+
assert_equal(S_OK, restore(*args))
|
80
|
+
|
81
|
+
# check - total number
|
82
|
+
restored = [0, 2, 4].inject(0) do |r,i|
|
83
|
+
dest_nodes[i].open do |n|
|
84
|
+
r+n.stats["curr_items"].to_i
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# check - flags
|
89
|
+
count = 0
|
90
|
+
(0..2).each do |partition|
|
91
|
+
dest_nodes[ranges[partition][0]].open do |n|
|
92
|
+
n.dump(0, partition, ranges.size, 0) do |data, key, flag, len, version, expire|
|
93
|
+
assert_equal(expected_data, data)
|
94
|
+
assert_equal(expected_flag, flag)
|
95
|
+
assert_equal(expected_expire, expire)
|
96
|
+
count += 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
assert_not_equal(0, count)
|
101
|
+
|
102
|
+
# check - call
|
103
|
+
check.call(restored)
|
104
|
+
|
105
|
+
# destroy
|
106
|
+
src_cluster.shutdown
|
107
|
+
dest_cluster.shutdown
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_dump_and_restore1
|
111
|
+
dump_and_restore (0...100), ["prefix", "xiferp", "pre"], %w(--all), %w(--include=^prefix) do |restored|
|
112
|
+
assert_equal(100, restored)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_dump_and_restore2
|
117
|
+
dump_and_restore (0...100), ["prefix", "xiferp", "pre"], %w(--all), %w(--prefix-include=prefix) do |restored|
|
118
|
+
assert_equal(100, restored)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_dump_and_restore3
|
123
|
+
dump_and_restore (0...100), ["prefix", "xiferp", "pre"], %w(--all --raw), %w(--prefix-include=prefix) do |restored|
|
124
|
+
assert_equal(100, restored)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 IndexServerTest < 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::IndexServer.new(hostname, port, 10)
|
29
|
+
nodes = stats.stats_nodes
|
30
|
+
cluster = Flare::Tools::Cluster.new(hostname, port, nodes)
|
31
|
+
assert_equal(cluster.size, @node_servers.size)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,78 @@
|
|
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
|
+
|
12
|
+
class NodeTest < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
@flare_cluster = Flare::Test::Cluster.new('test')
|
15
|
+
sleep 1 # XXX
|
16
|
+
@node_servers = ['node1', 'node2', 'node3'].map {|name| @flare_cluster.create_node(name)}
|
17
|
+
sleep 1 # XXX
|
18
|
+
@flare_cluster.wait_for_ready
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
@flare_cluster.shutdown
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_dummy
|
26
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_one_million_entry
|
30
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers)
|
31
|
+
@flare_cluster.prepare_data(@node_servers[0], "key", 1000000)
|
32
|
+
end if ENV['FLARE_TOOLS_STRESS_TEST']
|
33
|
+
|
34
|
+
def test_update1
|
35
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers)
|
36
|
+
Flare::Tools::Node.open(@flare_cluster.indexname, @flare_cluster.indexport, 10) do |s|
|
37
|
+
node = @node_servers[1]
|
38
|
+
Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
|
39
|
+
n.set("incr", "0")
|
40
|
+
n.set("decr", "9")
|
41
|
+
sleep 1
|
42
|
+
assert_equal(0.to_s, n.get("incr"))
|
43
|
+
assert_equal(9.to_s, n.get("decr"))
|
44
|
+
n.set_noreply("incr_noreply", "0")
|
45
|
+
n.set_noreply("decr_noreply", "9")
|
46
|
+
sleep 1
|
47
|
+
assert_equal(0.to_s, n.get("incr_noreply"))
|
48
|
+
assert_equal(9.to_s, n.get("decr_noreply"))
|
49
|
+
(1...10).each do |i|
|
50
|
+
assert_equal(i.to_s, n.incr("incr", 1))
|
51
|
+
assert_equal((9-i.to_i).to_s, n.decr("decr", 1))
|
52
|
+
n.incr("incr_noreply", 1)
|
53
|
+
n.decr("decr_noreply", 1)
|
54
|
+
end
|
55
|
+
assert_equal(9.to_s, n.get("incr_noreply"))
|
56
|
+
assert_equal(0.to_s, n.get("decr_noreply"))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_delete1
|
62
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers)
|
63
|
+
Flare::Tools::Node.open(@flare_cluster.indexname, @flare_cluster.indexport, 10) do |s|
|
64
|
+
node = @node_servers[1]
|
65
|
+
Flare::Tools::Node.open(node.hostname, node.port, 10) do |n|
|
66
|
+
n.set("key", "0")
|
67
|
+
n.delete("key")
|
68
|
+
assert_equal(false, n.get("key"))
|
69
|
+
n.set("key", "0")
|
70
|
+
n.delete_noreply("key")
|
71
|
+
sleep 0.1
|
72
|
+
assert_equal(false, n.get("key"))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,235 @@
|
|
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/tools/cli'
|
10
|
+
require 'flare/test/cluster'
|
11
|
+
require 'subcommands'
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'progressbar'
|
15
|
+
rescue LoadError => e
|
16
|
+
end
|
17
|
+
|
18
|
+
class Result
|
19
|
+
def initialize(resultq)
|
20
|
+
@resultq = resultq
|
21
|
+
end
|
22
|
+
|
23
|
+
def get
|
24
|
+
@resultq.pop
|
25
|
+
end
|
26
|
+
|
27
|
+
def sync
|
28
|
+
@resultq.pop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class FlareClient
|
33
|
+
def initialize(node)
|
34
|
+
@queue = Queue.new
|
35
|
+
@resultq = Queue.new
|
36
|
+
@node = node
|
37
|
+
@th = Thread.new do
|
38
|
+
while item = @queue.pop
|
39
|
+
case item[0]
|
40
|
+
when :get
|
41
|
+
value = @node.get(item[1])
|
42
|
+
@resultq.push(value)
|
43
|
+
when :set
|
44
|
+
@node.set(item[1], item[2])
|
45
|
+
@resultq.push(nil)
|
46
|
+
when :quit
|
47
|
+
@node.quit
|
48
|
+
break
|
49
|
+
when :detach
|
50
|
+
break
|
51
|
+
else
|
52
|
+
p item
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(key)
|
59
|
+
@queue.push([:get, key.to_s])
|
60
|
+
Result.new(@resultq)
|
61
|
+
end
|
62
|
+
|
63
|
+
def set(key, value)
|
64
|
+
@queue.push([:set, key.to_s, value.to_s])
|
65
|
+
Result.new(@resultq)
|
66
|
+
end
|
67
|
+
|
68
|
+
def quit
|
69
|
+
@queue.push([:quit])
|
70
|
+
@th.join
|
71
|
+
end
|
72
|
+
|
73
|
+
def detach
|
74
|
+
@queue.push([:detach])
|
75
|
+
@th.join
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
class PartitionTest < Test::Unit::TestCase
|
81
|
+
include Flare::Tools::Common
|
82
|
+
include Subcommands
|
83
|
+
|
84
|
+
S_OK = 0
|
85
|
+
S_NG = 1
|
86
|
+
|
87
|
+
def setup
|
88
|
+
@flare_cluster = Flare::Test::Cluster.new('test')
|
89
|
+
sleep 1 # XXX
|
90
|
+
@node_servers = ['node1', 'node2', 'node3', 'node4', 'node5', 'node6', 'node7'].map {|name|
|
91
|
+
@flare_cluster.create_node(name)
|
92
|
+
}
|
93
|
+
sleep 1 # XXX
|
94
|
+
@flare_cluster.wait_for_ready
|
95
|
+
@config = {
|
96
|
+
:command => 'dummy',
|
97
|
+
:index_server_hostname => @flare_cluster.indexname,
|
98
|
+
:index_server_port => @flare_cluster.indexport,
|
99
|
+
:dry_run => false,
|
100
|
+
:timeout => 10
|
101
|
+
}
|
102
|
+
@nodes = @node_servers.map {|node| node.open}
|
103
|
+
@wait = 0.005
|
104
|
+
end
|
105
|
+
|
106
|
+
def teardown
|
107
|
+
@nodes.map {|n| n.close}
|
108
|
+
@flare_cluster.shutdown
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_dynamic_partition_creation1
|
112
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers[0..1])
|
113
|
+
@flare_cluster.prepare_data(@node_servers[0], "key", 10)
|
114
|
+
master = FlareClient.new(@nodes[0])
|
115
|
+
args = @node_servers[2...3].map{|n| "#{n.hostname}:#{n.port}:1:1"}
|
116
|
+
assert_equal(S_OK, master(*args))
|
117
|
+
list
|
118
|
+
for i in 0..10
|
119
|
+
r = master.set("k#{i}", "piyo")
|
120
|
+
r.sync
|
121
|
+
sleep @wait
|
122
|
+
master_items = @nodes[0].stats["curr_items"].to_i
|
123
|
+
slave_items = @nodes[1].stats["curr_items"].to_i
|
124
|
+
puts "master_items=#{master_items}, slave_items=#{slave_items}"
|
125
|
+
assert_equal(master_items, slave_items)
|
126
|
+
end
|
127
|
+
args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
|
128
|
+
assert_equal(S_OK, activate(*args))
|
129
|
+
master.detach
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_dynamic_partition_creation2
|
133
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers[0..1])
|
134
|
+
@flare_cluster.prepare_data(@node_servers[0], "key", 10)
|
135
|
+
master = FlareClient.new(@nodes[0])
|
136
|
+
args = @node_servers[2...3].map{|n| "#{n.hostname}:#{n.port}:1:1"}
|
137
|
+
assert_equal(S_OK, master(*args))
|
138
|
+
args = @node_servers[3...4].map{|n| "#{n.hostname}:#{n.port}:0:1"}
|
139
|
+
assert_equal(S_OK, slave(*args))
|
140
|
+
list
|
141
|
+
basesize = @nodes[0].stats["curr_items"].to_i
|
142
|
+
size = 10
|
143
|
+
for i in 0...size
|
144
|
+
r = master.set("k#{i}", "piyo")
|
145
|
+
r.sync
|
146
|
+
sleep @wait
|
147
|
+
master_items = @nodes[0].stats["curr_items"].to_i
|
148
|
+
slave_items = @nodes[1].stats["curr_items"].to_i
|
149
|
+
preparing_master_items = @nodes[2].stats["curr_items"].to_i
|
150
|
+
preparing_slave_items = @nodes[3].stats["curr_items"].to_i
|
151
|
+
puts "master=#{master_items}, slaves=#{slave_items}, preparing_master=#{preparing_master_items}, preparing_slave=#{preparing_slave_items}"
|
152
|
+
assert_equal(master_items, slave_items)
|
153
|
+
end
|
154
|
+
assert_equal(size+basesize, master_items)
|
155
|
+
args = @node_servers[2..3].map{|n| "#{n.hostname}:#{n.port}"}
|
156
|
+
assert_equal(S_OK, activate(*args))
|
157
|
+
master.detach
|
158
|
+
end
|
159
|
+
|
160
|
+
def dynamic_partition_creation3(ntarget)
|
161
|
+
p, m0, s0, m1, s1, m2, s2 = 0, 1, 2, 3, 4, 5, 6
|
162
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers[m0..s0])
|
163
|
+
target = FlareClient.new(ntarget)
|
164
|
+
assert_equal(S_OK, master(*@node_servers[m1..m1].map{|n| "#{n.hostname}:#{n.port}:1:1"}))
|
165
|
+
assert_equal(S_OK, slave(*@node_servers[s1..s1].map{|n| "#{n.hostname}:#{n.port}:1:1"}))
|
166
|
+
assert_equal(S_OK, activate(*@node_servers[m1..m1].map{|n| "#{n.hostname}:#{n.port}"}))
|
167
|
+
assert_equal(S_OK, master(*@node_servers[m2..m2].map{|n| "#{n.hostname}:#{n.port}:1:2"}))
|
168
|
+
assert_equal(S_OK, slave(*@node_servers[s2..s2].map{|n| "#{n.hostname}:#{n.port}:1:2"}))
|
169
|
+
list
|
170
|
+
size = 10
|
171
|
+
for i in 0...size
|
172
|
+
r = target.set("k#{i}", "piyo")
|
173
|
+
r.sync
|
174
|
+
sleep @wait
|
175
|
+
items = @nodes.map {|n| n.stats["curr_items"].to_i}
|
176
|
+
assert_equal(items[m0], items[s0])
|
177
|
+
assert_equal(items[m1], items[s1])
|
178
|
+
assert_equal(items[m2], items[s2])
|
179
|
+
end
|
180
|
+
assert_equal(size, items[m0]+items[m1])
|
181
|
+
assert_equal(S_OK, activate(*@node_servers[m2..m2].map{|n| "#{n.hostname}:#{n.port}"}))
|
182
|
+
for i in 0...size
|
183
|
+
r = target.set("k#{i}", "piyo")
|
184
|
+
r.sync
|
185
|
+
sleep @wait
|
186
|
+
items = @nodes.map {|n| n.stats["curr_items"].to_i}
|
187
|
+
assert_equal(items[m0], items[s0])
|
188
|
+
assert_equal(items[m1], items[s1])
|
189
|
+
assert_equal(items[m2], items[s2])
|
190
|
+
end
|
191
|
+
target.detach
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.deftest_all(name)
|
195
|
+
syms = ["p", "m0", "s0", "m1", "s1", "m2", "s2"]
|
196
|
+
for i in (0...syms.size)
|
197
|
+
self.class_eval %{
|
198
|
+
def test_#{name.to_s}_#{syms[i]}
|
199
|
+
#{name.to_s}(@nodes[#{i}])
|
200
|
+
end
|
201
|
+
}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
deftest_all :dynamic_partition_creation3
|
206
|
+
|
207
|
+
def test_dynamic_partition_creation4
|
208
|
+
p, m0, s0, m1, s1, m2, s2 = 0, 1, 2, 3, 4, 5, 6
|
209
|
+
@flare_cluster.prepare_master_and_slaves(@node_servers[m0..s0])
|
210
|
+
assert_equal(S_OK, master(*@node_servers[m1..m1].map{|n| "#{n.hostname}:#{n.port}:1:1"}))
|
211
|
+
assert_equal(S_OK, slave(*@node_servers[s1..s1].map{|n| "#{n.hostname}:#{n.port}:1:1"}))
|
212
|
+
assert_equal(S_OK, activate(*@node_servers[m1..m1].map{|n| "#{n.hostname}:#{n.port}"}))
|
213
|
+
assert_equal(S_OK, master(*@node_servers[m2..m2].map{|n| "#{n.hostname}:#{n.port}:1:2"}))
|
214
|
+
assert_equal(S_OK, slave(*@node_servers[s2..s2].map{|n| "#{n.hostname}:#{n.port}:1:2"}))
|
215
|
+
targets = @nodes.map {|n| FlareClient.new(n)}
|
216
|
+
list
|
217
|
+
size = 1000
|
218
|
+
pbar = ProgressBar.new('test_dynamic_partition_creation4', size, $stderr) if defined? ProgressBar
|
219
|
+
for i in 0...size
|
220
|
+
r = targets[rand(targets.size)].set("k#{i}", "piyo")
|
221
|
+
r.sync
|
222
|
+
sleep @wait
|
223
|
+
items = @nodes.map {|n| n.stats["curr_items"].to_i}
|
224
|
+
assert_equal(items[m0], items[s0])
|
225
|
+
assert_equal(items[m1], items[s1])
|
226
|
+
assert_equal(items[m2], items[s2])
|
227
|
+
if defined? ProgressBar
|
228
|
+
pbar.inc
|
229
|
+
end
|
230
|
+
assert_equal(S_OK, activate(*@node_servers[m2..m2].map{|n| "#{n.hostname}:#{n.port}"})) if i == size/2
|
231
|
+
end
|
232
|
+
targets.each {|c| c.detach}
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|