roma-client 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/Gemfile.lock +18 -19
- data/lib/roma/client/client_pool.rb +1 -1
- data/lib/roma/client/proxy/version.rb +14 -15
- data/lib/roma/client/rclient.rb +9 -12
- data/lib/roma/client/sender.rb +29 -19
- data/lib/roma/client/stats.rb +17 -0
- data/lib/roma/client/version.rb +10 -11
- data/spec/roma/client/client_pool_spec.rb +76 -82
- data/spec/roma/client/stats_spec.rb +63 -0
- data/spec/roma/client/version_spec.rb +0 -1
- data/spec/spec_helper.rb +32 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa08ca4abf7e429b64dd7ccede43f0cc1b8df38
|
4
|
+
data.tar.gz: 4229f43985000b6c82ff5dac4b87251988bbf60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2724bde9c6a933562b4729e05bdaad563fe6e604d8ed7840410b516ff366c706f844605e1205339a24cc88a5fc5640b15c815bab2dbbad51f8d7096b126e5aeb
|
7
|
+
data.tar.gz: 8e62fccf9a0a168c494500fe3509a3cad98eeb5cbfd4aafd86110a2df53fd1477699dc94989259a1e7c62262dbc81abdb8193f7b19654bb0464974f80e75e82c
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
* 0.4.3 (Aug 19 2015)
|
2
|
+
|
3
|
+
* Change interface of Stat object and refactoring [Hiroki Matsue] 7438faf
|
4
|
+
* Add tests for argumetns of stats [Hiroki Matsue] 9939760
|
5
|
+
* Refactor codes [Hiroki Matsue] 3d37030
|
6
|
+
* Support stat command [Hiroki Matsue] 1d75694
|
7
|
+
|
1
8
|
* 0.4.2 (Mar 31 2015)
|
2
9
|
|
3
10
|
* Add gemspec and convert "should" to "expect" on rspec tests. [Hiroki Matsue] 4c7c465
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roma-client (0.4.
|
4
|
+
roma-client (0.4.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.2.5)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
eventmachine (1.0.3)
|
11
|
+
jaro_winkler (1.3.5)
|
12
|
+
json (1.8.1)
|
13
|
+
rake (10.2.2)
|
14
|
+
rdoc (4.1.1)
|
13
15
|
json (~> 1.4)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
rspec-
|
19
|
-
|
20
|
-
rspec-
|
21
|
-
rspec-
|
22
|
-
|
23
|
-
|
24
|
-
rspec-mocks (
|
25
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.2.0)
|
27
|
-
rspec-support (3.2.2)
|
16
|
+
roma (1.2.0)
|
17
|
+
eventmachine (~> 1.0.0)
|
18
|
+
jaro_winkler (~> 1.3.5)
|
19
|
+
rspec (2.14.1)
|
20
|
+
rspec-core (~> 2.14.0)
|
21
|
+
rspec-expectations (~> 2.14.0)
|
22
|
+
rspec-mocks (~> 2.14.0)
|
23
|
+
rspec-core (2.14.8)
|
24
|
+
rspec-expectations (2.14.5)
|
25
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
26
|
+
rspec-mocks (2.14.6)
|
28
27
|
|
29
28
|
PLATFORMS
|
30
29
|
ruby
|
@@ -32,6 +31,6 @@ PLATFORMS
|
|
32
31
|
DEPENDENCIES
|
33
32
|
rake
|
34
33
|
rdoc
|
34
|
+
roma
|
35
35
|
roma-client!
|
36
|
-
rr
|
37
36
|
rspec
|
@@ -1,25 +1,24 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
#
|
3
2
|
# = roma/client/proxy/version.rb
|
4
3
|
# This file is derived from roma client proxy daemon.
|
5
4
|
#
|
6
5
|
module Roma #:nodoc:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
module Client #:nodoc:
|
7
|
+
# == What Is This Library?
|
8
|
+
# ROMA client proxy daemon's version module
|
9
|
+
#
|
10
|
+
module VERSION
|
11
|
+
# MAJOR version
|
12
|
+
MAJOR = 0
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
# MINOR version
|
15
|
+
MINOR = 1
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
# TINY version
|
18
|
+
TINY = 0
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
# Version string
|
21
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
24
22
|
end
|
23
|
+
end
|
25
24
|
end
|
data/lib/roma/client/rclient.rb
CHANGED
@@ -7,10 +7,8 @@ require 'roma/client/sender'
|
|
7
7
|
|
8
8
|
module Roma
|
9
9
|
module Client
|
10
|
-
|
11
10
|
# Class to access ROMA .
|
12
11
|
class RomaClient
|
13
|
-
|
14
12
|
# ROMA server connect timeout .
|
15
13
|
@@timeout = 5
|
16
14
|
|
@@ -24,33 +22,33 @@ module Roma
|
|
24
22
|
#
|
25
23
|
# [ini_nodes] ROMA nodes array
|
26
24
|
# [plugin_modules] set plugin modules if you use .
|
27
|
-
def initialize(ini_nodes,plugin_modules = nil, start_sync_routing_proc = true)
|
25
|
+
def initialize(ini_nodes, plugin_modules = nil, start_sync_routing_proc = true)
|
28
26
|
@retry_count_write = 10
|
29
27
|
@retry_count_read = 5
|
30
28
|
@default_hash_name = 'roma'
|
31
29
|
|
32
30
|
if plugin_modules
|
33
|
-
plugin_modules.each do|plugin|
|
31
|
+
plugin_modules.each do |plugin|
|
34
32
|
self.extend plugin
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
36
|
init_sender
|
39
|
-
update_rttable(ini_nodes.map{|n| n.sub(':','_')})
|
37
|
+
update_rttable(ini_nodes.map { |n| n.sub(':', '_') })
|
40
38
|
init_sync_routing_proc if start_sync_routing_proc
|
41
39
|
end
|
42
40
|
|
43
41
|
def init_sync_routing_proc
|
44
|
-
Thread.new
|
42
|
+
Thread.new do
|
45
43
|
begin
|
46
|
-
loop
|
44
|
+
loop do
|
47
45
|
sleep 10
|
48
46
|
update_rttable
|
49
|
-
|
47
|
+
end
|
50
48
|
rescue => e
|
51
49
|
puts "#{e}\n#{$@}"
|
52
50
|
end
|
53
|
-
|
51
|
+
end
|
54
52
|
end
|
55
53
|
private :init_sync_routing_proc
|
56
54
|
|
@@ -377,9 +375,8 @@ module Roma
|
|
377
375
|
ret.to_i
|
378
376
|
end
|
379
377
|
|
380
|
-
def stats
|
381
|
-
|
382
|
-
@sender.send_stats_command
|
378
|
+
def stats(filter: "", node: @rttable.nodes.first)
|
379
|
+
@sender.send_stats_command(filter, node)
|
383
380
|
end
|
384
381
|
|
385
382
|
def version
|
data/lib/roma/client/sender.rb
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
require 'yaml'
|
3
3
|
require 'roma/client/con_pool'
|
4
|
+
require 'roma/client/stats'
|
4
5
|
|
5
6
|
module Roma
|
6
7
|
module Client
|
7
|
-
|
8
8
|
class Sender
|
9
|
-
|
10
9
|
def initialize
|
11
10
|
end
|
12
11
|
|
13
12
|
def send_route_mklhash_command(node_id)
|
14
|
-
timeout(1)
|
13
|
+
timeout(1) do
|
15
14
|
conn = ConPool.instance.get_connection(node_id)
|
16
15
|
conn.write "mklhash 0\r\n"
|
17
16
|
ret = conn.gets
|
18
17
|
ConPool.instance.return_connection(node_id, conn)
|
19
18
|
return ret.chomp if ret
|
20
|
-
|
21
|
-
rescue =>e
|
19
|
+
end
|
20
|
+
rescue => e
|
22
21
|
STDERR.puts "#{node_id} #{e.inspect}"
|
23
22
|
return nil
|
24
23
|
end
|
25
24
|
|
26
25
|
def send_routedump_command(node_id)
|
27
|
-
timeout(1)
|
26
|
+
timeout(1) do
|
28
27
|
buf = RUBY_VERSION.split('.')
|
29
28
|
if buf[0].to_i == 1 && buf[1].to_i == 8
|
30
29
|
return send_routedump_yaml_command(node_id)
|
@@ -47,8 +46,8 @@ module Roma
|
|
47
46
|
rd = Marshal.load(routes)
|
48
47
|
ConPool.instance.return_connection(node_id, conn)
|
49
48
|
return rd
|
50
|
-
|
51
|
-
rescue =>e
|
49
|
+
end
|
50
|
+
rescue => e
|
52
51
|
STDERR.puts "#{node_id} #{e.inspect}"
|
53
52
|
nil
|
54
53
|
end
|
@@ -58,17 +57,29 @@ module Roma
|
|
58
57
|
conn.write "routingdump yaml\r\n"
|
59
58
|
|
60
59
|
yaml = ''
|
61
|
-
while
|
60
|
+
while ((line = conn.gets) != "END\r\n")
|
62
61
|
yaml << line
|
63
62
|
end
|
64
63
|
|
65
64
|
rd = YAML.load(yaml)
|
66
65
|
ConPool.instance.return_connection(node_id, conn)
|
67
|
-
|
66
|
+
rd
|
68
67
|
end
|
69
68
|
|
70
|
-
def send_stats_command
|
71
|
-
|
69
|
+
def send_stats_command(filter, node_id)
|
70
|
+
conn = ConPool.instance.get_connection(node_id)
|
71
|
+
cmd = 'stats'
|
72
|
+
cmd += " #{filter}" if filter
|
73
|
+
conn.write "#{cmd}\r\n"
|
74
|
+
|
75
|
+
stats_str = ''
|
76
|
+
while ((line = conn.gets) != "END\r\n")
|
77
|
+
stats_str << line
|
78
|
+
end
|
79
|
+
|
80
|
+
stats = Roma::Client::Stats.new(stats_str)
|
81
|
+
ConPool.instance.return_connection(node_id, conn)
|
82
|
+
stats
|
72
83
|
end
|
73
84
|
|
74
85
|
def send_version_command(ap)
|
@@ -76,8 +87,8 @@ module Roma
|
|
76
87
|
conn.write("version\r\n")
|
77
88
|
res = conn.gets.chomp
|
78
89
|
ConPool.instance.return_connection(ap, conn)
|
79
|
-
|
80
|
-
|
90
|
+
fail unless res
|
91
|
+
res
|
81
92
|
end
|
82
93
|
|
83
94
|
def send_verbosity_command(ap)
|
@@ -88,7 +99,7 @@ module Roma
|
|
88
99
|
|
89
100
|
def send_command(nid, cmd, value = nil, receiver = :oneline_receiver)
|
90
101
|
con = ConPool.instance.get_connection(nid)
|
91
|
-
|
102
|
+
fail unless con
|
92
103
|
if value
|
93
104
|
con.write "#{cmd}\r\n#{value}\r\n"
|
94
105
|
else
|
@@ -97,8 +108,8 @@ module Roma
|
|
97
108
|
ret = send(receiver, con)
|
98
109
|
ConPool.instance.return_connection(nid, con)
|
99
110
|
if ret && ret.instance_of?(String) &&
|
100
|
-
|
101
|
-
|
111
|
+
(ret =~ /^SERVER_ERROR/ || ret =~ /^CLIENT_ERROR/)
|
112
|
+
fail ret
|
102
113
|
end
|
103
114
|
ret
|
104
115
|
end
|
@@ -107,7 +118,7 @@ module Roma
|
|
107
118
|
|
108
119
|
def oneline_receiver(con)
|
109
120
|
ret = con.gets
|
110
|
-
|
121
|
+
fail 'connection closed' if ret.nil?
|
111
122
|
ret.chomp
|
112
123
|
end
|
113
124
|
|
@@ -160,7 +171,6 @@ module Roma
|
|
160
171
|
end
|
161
172
|
ret
|
162
173
|
end
|
163
|
-
|
164
174
|
end
|
165
175
|
end
|
166
176
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Roma
|
2
|
+
module Client
|
3
|
+
# TODO: Implement accessors and return values with correct type
|
4
|
+
# Now: client.stats["routing.redundant"] #=> "2"
|
5
|
+
# Better: client.stats.routing.redundant #=> 2
|
6
|
+
class Stats < Hash
|
7
|
+
def initialize(stats_str)
|
8
|
+
stats_str.each_line do |line|
|
9
|
+
line =~ /^(.+?)\s(.+)/
|
10
|
+
key = Regexp.last_match(1)
|
11
|
+
value = Regexp.last_match(2).chomp
|
12
|
+
self[key] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/roma/client/version.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
#
|
3
2
|
# = roma/client/version.rb
|
4
3
|
# This file is derived from roma client.
|
5
4
|
#
|
6
5
|
module Roma #:nodoc:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
module Client #:nodoc:
|
7
|
+
# == What Is This Library?
|
8
|
+
# ROMA client version info.
|
9
|
+
#
|
10
|
+
module VERSION
|
11
|
+
MAJOR = 0
|
13
12
|
|
14
|
-
|
13
|
+
MINOR = 4
|
15
14
|
|
16
|
-
|
15
|
+
TINY = 3
|
17
16
|
|
18
|
-
|
19
|
-
end
|
17
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
20
18
|
end
|
19
|
+
end
|
21
20
|
end
|
@@ -1,44 +1,42 @@
|
|
1
1
|
require File.expand_path(File.join('..', '..', 'spec_helper'), File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe Roma::Client::ClientPool do
|
4
|
+
before(:all) do
|
5
|
+
start_roma
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:all) do
|
9
|
+
stop_roma
|
10
|
+
end
|
11
|
+
|
4
12
|
def get_nodes
|
5
|
-
|
13
|
+
DEFAULT_PORTS.map { |port| "#{DEFAULT_HOST}:#{port}" }
|
6
14
|
end
|
7
15
|
|
8
|
-
context
|
16
|
+
context 'Singleton' do
|
9
17
|
subject { Roma::Client::ClientPool.instance(:test) }
|
10
|
-
it {
|
11
|
-
|
12
|
-
}
|
13
|
-
|
14
|
-
it {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
it {
|
23
|
-
expect {
|
24
|
-
Roma::Client::ClientPool.new
|
25
|
-
}.to raise_error(NoMethodError,
|
26
|
-
"private method `new' called for Roma::Client::ClientPool:Class")
|
27
|
-
}
|
18
|
+
it { expect(subject.class).to eq(Roma::Client::ClientPool) }
|
19
|
+
|
20
|
+
it { expect(subject).to be_equal Roma::Client::ClientPool.instance(:test) }
|
21
|
+
|
22
|
+
it { expect(subject).not_to be_equal Roma::Client::ClientPool.instance(:test2) }
|
23
|
+
|
24
|
+
it do
|
25
|
+
expect { Roma::Client::ClientPool.new }.to raise_error(NoMethodError,
|
26
|
+
"private method `new' called for Roma::Client::ClientPool:Class")
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
|
-
context
|
31
|
-
subject{ Roma::Client::ClientPool.instance(:test) }
|
30
|
+
context 'max pool size of default' do
|
31
|
+
subject { Roma::Client::ClientPool.instance(:test) }
|
32
32
|
|
33
33
|
describe '#max_pool_size' do
|
34
34
|
subject { super().max_pool_size }
|
35
|
-
it {
|
36
|
-
is_expected.to eq(1)
|
37
|
-
}
|
35
|
+
it { is_expected.to eq(1) }
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
context
|
39
|
+
context 'set max pool size ' do
|
42
40
|
it do
|
43
41
|
pool = Roma::Client::ClientPool.instance(:test)
|
44
42
|
expect(pool.max_pool_size).to eq(1)
|
@@ -50,7 +48,7 @@ describe Roma::Client::ClientPool do
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
|
-
context
|
51
|
+
context 'servers default' do
|
54
52
|
subject { Roma::Client::ClientPool.instance(:test) }
|
55
53
|
|
56
54
|
describe '#servers' do
|
@@ -59,8 +57,8 @@ describe Roma::Client::ClientPool do
|
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
|
-
context
|
63
|
-
it
|
60
|
+
context 'servers set' do
|
61
|
+
it do
|
64
62
|
pool = Roma::Client::ClientPool.instance(:test_servers_set)
|
65
63
|
expect(pool.servers).to be_nil
|
66
64
|
nodes = get_nodes
|
@@ -68,35 +66,34 @@ describe Roma::Client::ClientPool do
|
|
68
66
|
expect(pool.servers).to eq(nodes)
|
69
67
|
|
70
68
|
expect(Roma::Client::ClientPool.instance(:test_ini_nodes_set2).servers).to be_nil
|
71
|
-
|
69
|
+
end
|
72
70
|
end
|
73
71
|
|
74
|
-
context
|
72
|
+
context 'client' do
|
75
73
|
subject do
|
76
74
|
pool = Roma::Client::ClientPool.instance(:test_client)
|
77
75
|
pool.servers = get_nodes
|
78
76
|
pool
|
79
77
|
end
|
80
78
|
|
81
|
-
it { skip 'TODO: startup or mock roma server'}
|
82
79
|
it { expect(subject.pool_count).to eq(0) }
|
83
|
-
it
|
80
|
+
it do
|
84
81
|
client = subject.client
|
85
82
|
expect(client.class).to eq(Roma::Client::RomaClient)
|
86
83
|
subject.push_client(client)
|
87
84
|
expect(subject.pool_count).to eq(1)
|
88
|
-
|
89
|
-
it {
|
85
|
+
end
|
86
|
+
it { expect(subject.servers).to eq(get_nodes) }
|
90
87
|
end
|
91
88
|
|
92
|
-
context
|
89
|
+
context 'client multi pool' do
|
93
90
|
subject do
|
94
91
|
pool = Roma::Client::ClientPool.instance(:test_client2)
|
95
92
|
pool.servers = get_nodes
|
96
93
|
pool
|
97
94
|
end
|
98
95
|
|
99
|
-
it
|
96
|
+
it do
|
100
97
|
expect(subject.pool_count).to eq(0)
|
101
98
|
client = subject.client
|
102
99
|
expect(client).not_to be_nil
|
@@ -112,23 +109,23 @@ describe Roma::Client::ClientPool do
|
|
112
109
|
|
113
110
|
expect(client).to be_equal subject.client
|
114
111
|
expect(subject.pool_count).to eq(0)
|
115
|
-
|
112
|
+
end
|
116
113
|
end
|
117
114
|
|
118
|
-
context
|
115
|
+
context 'plugin modules' do
|
119
116
|
module TestPlugin
|
120
117
|
def test_plugin
|
121
|
-
|
118
|
+
'test_plugin'
|
122
119
|
end
|
123
120
|
end
|
124
121
|
|
125
122
|
module TestPlugin2
|
126
123
|
def test_plugin2
|
127
|
-
|
124
|
+
'test_plugin2'
|
128
125
|
end
|
129
126
|
end
|
130
127
|
|
131
|
-
it
|
128
|
+
it do
|
132
129
|
pool = Roma::Client::ClientPool.instance(:pm_test)
|
133
130
|
expect(pool.plugin_modules).to be_nil
|
134
131
|
|
@@ -136,9 +133,9 @@ describe Roma::Client::ClientPool do
|
|
136
133
|
expect(pool.plugin_modules).not_to be_nil
|
137
134
|
expect(pool.plugin_modules.size).to eq(1)
|
138
135
|
pool.plugin_modules[0] == TestPlugin
|
139
|
-
|
136
|
+
end
|
140
137
|
|
141
|
-
it
|
138
|
+
it do
|
142
139
|
pool = Roma::Client::ClientPool.instance(:pms_test)
|
143
140
|
expect(pool.plugin_modules).to be_nil
|
144
141
|
|
@@ -146,9 +143,9 @@ describe Roma::Client::ClientPool do
|
|
146
143
|
expect(pool.plugin_modules.size).to eq(2)
|
147
144
|
pool.plugin_modules[0] == TestPlugin
|
148
145
|
pool.plugin_modules[1] == TestPlugin2
|
149
|
-
|
146
|
+
end
|
150
147
|
|
151
|
-
it
|
148
|
+
it do
|
152
149
|
pool = Roma::Client::ClientPool.instance(:pms_test2)
|
153
150
|
pool.servers = get_nodes
|
154
151
|
expect(pool.plugin_modules).to be_nil
|
@@ -156,31 +153,29 @@ describe Roma::Client::ClientPool do
|
|
156
153
|
pool.plugin_modules = [TestPlugin, TestPlugin2]
|
157
154
|
client = pool.client
|
158
155
|
expect(client).not_to be_nil
|
159
|
-
expect(client.test_plugin).to eq(
|
160
|
-
expect(client.test_plugin2).to eq(
|
161
|
-
|
156
|
+
expect(client.test_plugin).to eq('test_plugin')
|
157
|
+
expect(client.test_plugin2).to eq('test_plugin2')
|
158
|
+
end
|
162
159
|
end
|
163
160
|
|
164
|
-
context
|
161
|
+
context 'default type' do
|
165
162
|
subject { Roma::Client::ClientPool.instance }
|
166
163
|
it { is_expected.not_to be_nil }
|
167
164
|
it { expect(subject.class).to eq(Roma::Client::ClientPool) }
|
168
165
|
it { expect(subject).to be_equal Roma::Client::ClientPool.instance(:default) }
|
169
166
|
end
|
170
167
|
|
171
|
-
context
|
172
|
-
after(:all) {
|
173
|
-
Roma::Client::ClientPool.instance.default_hash_name = 'roma'
|
174
|
-
}
|
168
|
+
context 'support hash name' do
|
169
|
+
after(:all) { Roma::Client::ClientPool.instance.default_hash_name = 'roma' }
|
175
170
|
|
176
|
-
subject
|
171
|
+
subject do
|
177
172
|
pool = Roma::Client::ClientPool.instance
|
178
173
|
pool.servers = get_nodes
|
179
174
|
pool
|
180
|
-
|
175
|
+
end
|
181
176
|
|
182
177
|
it { expect(subject.default_hash_name).to eq('roma') }
|
183
|
-
it
|
178
|
+
it do
|
184
179
|
subject.default_hash_name = 'new_name'
|
185
180
|
expect(subject.default_hash_name).to eq('new_name')
|
186
181
|
expect(Roma::Client::ClientPool.instance.default_hash_name).to eq('new_name')
|
@@ -188,17 +183,17 @@ describe Roma::Client::ClientPool do
|
|
188
183
|
|
189
184
|
client = subject.client
|
190
185
|
expect(client.default_hash_name).to eq('new_name')
|
191
|
-
|
186
|
+
end
|
192
187
|
end
|
193
188
|
|
194
|
-
context
|
195
|
-
subject
|
189
|
+
context 'release' do
|
190
|
+
subject do
|
196
191
|
pool = Roma::Client::ClientPool.instance(:release_test)
|
197
192
|
pool.servers = get_nodes
|
198
193
|
pool
|
199
|
-
|
194
|
+
end
|
200
195
|
|
201
|
-
it
|
196
|
+
it do
|
202
197
|
expect(subject.pool_count).to eq(0)
|
203
198
|
subject.client do |client|
|
204
199
|
end
|
@@ -206,48 +201,48 @@ describe Roma::Client::ClientPool do
|
|
206
201
|
expect(subject.pool_count).to eq(1)
|
207
202
|
expect(subject.release).to be_truthy
|
208
203
|
expect(subject.pool_count).to eq(0)
|
209
|
-
|
204
|
+
end
|
210
205
|
end
|
211
206
|
|
212
|
-
context
|
207
|
+
context 'client block' do
|
213
208
|
before(:each) do
|
214
209
|
pool = Roma::Client::ClientPool.instance(:client_block)
|
215
210
|
pool.release
|
216
211
|
end
|
217
212
|
|
218
|
-
subject
|
213
|
+
subject do
|
219
214
|
pool = Roma::Client::ClientPool.instance(:client_block)
|
220
215
|
pool.servers = get_nodes
|
221
216
|
pool
|
222
|
-
|
217
|
+
end
|
223
218
|
|
224
|
-
it
|
219
|
+
it 'use block'do
|
225
220
|
expect(subject.pool_count).to eq(0)
|
226
221
|
subject.client do |client|
|
227
|
-
expect(client.set(
|
222
|
+
expect(client.set('test', 'value')).to eq('STORED')
|
228
223
|
end
|
229
224
|
expect(subject.pool_count).to eq(1)
|
230
225
|
end
|
231
226
|
|
232
|
-
it
|
227
|
+
it 'raise exception in block, but pool certainly' do
|
233
228
|
expect(subject.pool_count).to eq(0)
|
234
229
|
subject.client do |client|
|
235
|
-
expect(client.set(
|
230
|
+
expect(client.set('test', 'value')).to eq('STORED')
|
236
231
|
end
|
237
232
|
expect(subject.pool_count).to eq(1)
|
238
233
|
|
239
|
-
expect
|
234
|
+
expect do
|
240
235
|
subject.client do |client|
|
241
|
-
raise
|
236
|
+
raise 'test error'
|
242
237
|
end
|
243
|
-
|
238
|
+
end.to raise_error RuntimeError, 'test error'
|
244
239
|
|
245
240
|
expect(subject.pool_count).to eq(1)
|
246
241
|
end
|
247
242
|
end
|
248
243
|
|
249
|
-
context
|
250
|
-
it
|
244
|
+
context 'start sync routing proc' do
|
245
|
+
it do
|
251
246
|
pool = Roma::Client::ClientPool.instance(:sync_test)
|
252
247
|
pool.servers = get_nodes
|
253
248
|
old_thread_count = Thread.list.length
|
@@ -256,9 +251,9 @@ describe Roma::Client::ClientPool do
|
|
256
251
|
|
257
252
|
expect(pool.pool_count).to eq(1)
|
258
253
|
expect(Thread.list.length).to eq(old_thread_count + 1)
|
259
|
-
|
254
|
+
end
|
260
255
|
|
261
|
-
it
|
256
|
+
it do
|
262
257
|
pool = Roma::Client::ClientPool.instance(:no_sync_test)
|
263
258
|
pool.servers = get_nodes
|
264
259
|
pool.start_sync_routing_proc = false
|
@@ -268,11 +263,11 @@ describe Roma::Client::ClientPool do
|
|
268
263
|
|
269
264
|
expect(pool.pool_count).to eq(1)
|
270
265
|
expect(Thread.list.length).to eq(old_thread_count)
|
271
|
-
|
266
|
+
end
|
272
267
|
end
|
273
268
|
|
274
|
-
context
|
275
|
-
it
|
269
|
+
context 'release all' do
|
270
|
+
it do
|
276
271
|
pool = Roma::Client::ClientPool.instance(:release_all_1)
|
277
272
|
pool.servers = get_nodes
|
278
273
|
pool.client do |c|
|
@@ -292,7 +287,6 @@ describe Roma::Client::ClientPool do
|
|
292
287
|
|
293
288
|
expect(Roma::Client::ClientPool.instance(:release_all_1).servers).to eq(get_nodes)
|
294
289
|
expect(Roma::Client::ClientPool.instance(:release_all_2).servers).to eq(get_nodes)
|
295
|
-
|
290
|
+
end
|
296
291
|
end
|
297
292
|
end
|
298
|
-
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.join('..', '..', 'spec_helper'), File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Roma::Client::Stats do
|
4
|
+
before(:all) do
|
5
|
+
start_roma
|
6
|
+
nodes = DEFAULT_PORTS.map { |port| "#{DEFAULT_HOST}:#{port}" }
|
7
|
+
@client = Roma::Client::RomaClient.new(nodes)
|
8
|
+
@stats = @client.stats
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
stop_roma
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'first level' do
|
16
|
+
it 'accessible to version' do
|
17
|
+
expect(@stats['version']).to match(/\d+\.\d+\.\d+.*/)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'second level' do
|
22
|
+
it 'accessible to routing.redundant' do
|
23
|
+
expect(@stats['routing.redundant']).to eq('2')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'third level' do
|
28
|
+
it 'accessible to routing.nodes.length' do
|
29
|
+
expect(@stats['routing.vnodes.length']).to eq('512')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'filter argument' do
|
34
|
+
it 'responce only stats.run_recover' do
|
35
|
+
keyword = 'stats.run_recover'
|
36
|
+
stat = @client.stats(filter: keyword)
|
37
|
+
expect(stat.keys.size).to eq(1)
|
38
|
+
expect(stat[keyword]).to eq('false')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'node argument' do
|
43
|
+
it 'responce from accessed port' do
|
44
|
+
DEFAULT_PORTS.each do |port|
|
45
|
+
stat = @client.stats(node: "#{DEFAULT_HOST}:#{port}")
|
46
|
+
expect(stat['stats.address']).to eq(DEFAULT_HOST)
|
47
|
+
expect(stat['stats.port']).to eq(port)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'filter and node arguments' do
|
53
|
+
it 'responce only stats.address and stats.port from accessed port' do
|
54
|
+
DEFAULT_PORTS.each do |port|
|
55
|
+
keywords = %w(address port)
|
56
|
+
stat = @client.stats(filter: keywords.join('|'), node: "#{DEFAULT_HOST}:#{port}")
|
57
|
+
expect(stat.keys.size).to eq(2)
|
58
|
+
expect(stat['stats.address']).to eq(DEFAULT_HOST)
|
59
|
+
expect(stat['stats.port']).to eq(port)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,39 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'rspec'
|
2
|
+
require 'roma/romad'
|
3
3
|
|
4
|
-
|
5
|
-
Dir[File.dirname(__FILE__) +
|
4
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
Dir[File.dirname(__FILE__) + '/supports/**/*.rb'].each { |f| require f }
|
6
6
|
|
7
7
|
require 'roma-client'
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
DEFAULT_HOST = '127.0.0.1'
|
10
|
+
DEFAULT_PORTS = %w(12001 12002)
|
11
|
+
SHELL_LOG_PATH = 'roma_spec_outputs.log'
|
12
|
+
|
13
|
+
def start_roma(host: DEFAULT_HOST, ports: DEFAULT_PORTS)
|
14
|
+
nodes = ports.map { |port| "#{host}_#{port}" }
|
15
|
+
|
16
|
+
nodes.each do |node|
|
17
|
+
FileUtils.rm(Dir.glob(["#{node}.log*", "#{node}.route*"]))
|
18
|
+
end
|
19
|
+
|
20
|
+
system("mkroute #{nodes.join(' ')} --replication_in_host >> #{SHELL_LOG_PATH} 2>&1")
|
21
|
+
|
22
|
+
ports.each do |port|
|
23
|
+
system("romad #{host} -p #{port} -d --replication_in_host --disabled_cmd_protect >> #{SHELL_LOG_PATH} 2>&1")
|
24
|
+
end
|
11
25
|
end
|
12
26
|
|
27
|
+
def stop_roma(host: DEFAULT_HOST, port: DEFAULT_PORTS[0])
|
28
|
+
conn = Roma::Messaging::ConPool.instance.get_connection("#{host}_#{port}")
|
29
|
+
if conn
|
30
|
+
conn.write "balse\r\n"
|
31
|
+
conn.gets
|
32
|
+
conn.write "yes\r\n"
|
33
|
+
conn.gets
|
34
|
+
conn.close
|
35
|
+
end
|
36
|
+
Roma::Client::ConPool.instance.close_all
|
37
|
+
rescue => e
|
38
|
+
puts "#{e} #{ $ERROR_POSITION}"
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roma-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muga Nishizawa
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: rdoc
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: roma
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
@@ -98,9 +98,11 @@ files:
|
|
98
98
|
- lib/roma/client/rlogger.rb
|
99
99
|
- lib/roma/client/routing/routing_data.rb
|
100
100
|
- lib/roma/client/sender.rb
|
101
|
+
- lib/roma/client/stats.rb
|
101
102
|
- lib/roma/client/tools/showbalance.rb
|
102
103
|
- lib/roma/client/version.rb
|
103
104
|
- spec/roma/client/client_pool_spec.rb
|
105
|
+
- spec/roma/client/stats_spec.rb
|
104
106
|
- spec/roma/client/version_spec.rb
|
105
107
|
- spec/spec_helper.rb
|
106
108
|
homepage: http://roma-kvs.org/
|