roma-client 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +22 -15
- data/Gemfile +2 -0
- data/Gemfile.lock +34 -18
- data/README.md +4 -0
- data/lib/roma/client/client_pool.rb +15 -25
- data/lib/roma/client/client_rttable.rb +1 -2
- data/lib/roma/client/tools/showbalance.rb +0 -1
- data/lib/roma/client/version.rb +1 -1
- data/spec/roma/client/client_pool_spec.rb +133 -173
- data/spec/spec_helper.rb +9 -0
- metadata +3 -79
- data/doc/CHANGELOG_md.html +0 -119
- data/doc/README_md.html +0 -161
- data/doc/Roma.html +0 -95
- data/doc/Roma/Client.html +0 -95
- data/doc/Roma/Client/ClientPool.html +0 -716
- data/doc/Roma/Client/ClientRoutingTable.html +0 -495
- data/doc/Roma/Client/ConPool.html +0 -484
- data/doc/Roma/Client/Plugin.html +0 -95
- data/doc/Roma/Client/Plugin/Alist.html +0 -1276
- data/doc/Roma/Client/Plugin/Map.html +0 -531
- data/doc/Roma/Client/Plugin/MapCount.html +0 -401
- data/doc/Roma/Client/Proxy.html +0 -95
- data/doc/Roma/Client/Proxy/ClientHandler.html +0 -273
- data/doc/Roma/Client/Proxy/Conpool.html +0 -394
- data/doc/Roma/Client/Proxy/Daemon.html +0 -305
- data/doc/Roma/Client/Proxy/RomaHandler.html +0 -217
- data/doc/Roma/Client/RomaClient.html +0 -1339
- data/doc/Roma/Client/Sender.html +0 -482
- data/doc/Roma/Client/Stats.html +0 -162
- data/doc/Roma/Client/VERSION.html +0 -141
- data/doc/Roma/Logging.html +0 -95
- data/doc/Roma/Logging/RLogger.html +0 -786
- data/doc/Roma/Logging/RLogger/ExtLogDev.html +0 -159
- data/doc/Roma/Logging/RLogger/ExtShiftAge.html +0 -95
- data/doc/Roma/Logging/RLogger/ExtTrace.html +0 -109
- data/doc/Roma/Logging/RLogger/Severity.html +0 -139
- data/doc/Roma/Routing.html +0 -95
- data/doc/Roma/Routing/RoutingData.html +0 -912
- data/doc/Roma/Routing/RoutingData/RandomNodeListMaker.html +0 -311
- data/doc/created.rid +0 -20
- data/doc/css/fonts.css +0 -167
- data/doc/css/rdoc.css +0 -590
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -210
- data/doc/js/darkfish.js +0 -161
- data/doc/js/jquery.js +0 -4
- data/doc/js/navigation.js +0 -142
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +0 -109
- data/doc/js/search_index.js +0 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +0 -228
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +0 -972
- data/lib/roma/client/routing/routing_data.rb +0 -241
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb5d75ac6fd6ae1afe804171d6e9d4b64bb734c6245e91ae89349ac09aa1d6ed
|
4
|
+
data.tar.gz: 5b62386df9e8e179deed3b740c5982ea43d30638b53456e6b1153979a20ae258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce830cf733b74d7daa035e7c38e6eaea8dc345ccdb905fafa4e02436b0d9e4eba24d717de282836a128829c0f139eefbca32997978ee9424ccaf9d435fa033b9
|
7
|
+
data.tar.gz: dc7e4c89e63d3bf73d43ed5064997c621b25b00b6e80537209486c1260d6c133ae05b2bf5a03e7a0a542679694ea7c2a20af2caea32f6124202e9059285f3cbd
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# CHANGELOG
|
2
2
|
|
3
|
-
|
4
|
-
* Replace the deprecated method `Object.timeout` with `Timeout.timeout` [#9](https://github.com/roma/roma-ruby-client/pull/9)
|
3
|
+
## 0.4.5 (Jun 17 2019)
|
5
4
|
|
6
|
-
|
5
|
+
- Remove RoutingData since it's not used [#16](https://github.com/roma/roma-ruby-client/pull/16)
|
6
|
+
- Remove dependencies on roma server from test [#15](https://github.com/roma/roma-ruby-client/pull/15)
|
7
7
|
|
8
|
-
|
9
|
-
* Add tests for argumetns of stats [Hiroki Matsue] 9939760
|
10
|
-
* Refactor codes [Hiroki Matsue] 3d37030
|
11
|
-
* Support stat command [Hiroki Matsue] 1d75694
|
8
|
+
## 0.4.4 (Aug 23 2016)
|
12
9
|
|
13
|
-
|
10
|
+
- Started use Travis CI [#8](https://github.com/roma/roma-ruby-client/pull/8)
|
11
|
+
- Replace the deprecated method `Object.timeout` with `Timeout.timeout` [#9](https://github.com/roma/roma-ruby-client/pull/9)
|
14
12
|
|
15
|
-
|
16
|
-
* modify to reproduce environment with Gemfile [tarr1124] 2205ed7
|
13
|
+
## 0.4.3 (Aug 19 2015)
|
17
14
|
|
18
|
-
|
15
|
+
- Change interface of Stat object and refactoring [Hiroki Matsue] 7438faf
|
16
|
+
- Add tests for argumetns of stats [Hiroki Matsue] 9939760
|
17
|
+
- Refactor codes [Hiroki Matsue] 3d37030
|
18
|
+
- Support stat command [Hiroki Matsue] 1d75694
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
## 0.4.2 (Mar 31 2015)
|
21
|
+
|
22
|
+
- Add gemspec and convert "should" to "expect" on rspec tests. [Hiroki Matsue] 4c7c465
|
23
|
+
- modify to reproduce environment with Gemfile [tarr1124] 2205ed7
|
24
|
+
|
25
|
+
## 0.4.1 (Feb 20 2012)
|
26
|
+
|
27
|
+
- add client plugin files. [junji torii] caa2201
|
28
|
+
- 0.4.0
|
29
|
+
- support ClientPool
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,39 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roma-client (0.4.
|
4
|
+
roma-client (0.4.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
9
|
+
coveralls (0.8.23)
|
10
|
+
json (>= 1.8, < 3)
|
11
|
+
simplecov (~> 0.16.1)
|
12
|
+
term-ansicolor (~> 1.3)
|
13
|
+
thor (>= 0.19.4, < 2.0)
|
14
|
+
tins (~> 1.6)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.2)
|
10
17
|
eventmachine (1.0.9.1)
|
11
18
|
jaro_winkler (1.3.7)
|
12
|
-
json (
|
13
|
-
rake (
|
14
|
-
rdoc (
|
15
|
-
json (~> 1.4)
|
19
|
+
json (2.2.0)
|
20
|
+
rake (12.3.2)
|
21
|
+
rdoc (6.1.1)
|
16
22
|
roma (1.3.0)
|
17
23
|
eventmachine (~> 1.0.0)
|
18
24
|
jaro_winkler (~> 1.3.5)
|
19
|
-
rspec (3.
|
20
|
-
rspec-core (~> 3.
|
21
|
-
rspec-expectations (~> 3.
|
22
|
-
rspec-mocks (~> 3.
|
23
|
-
rspec-core (3.
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-expectations (3.
|
25
|
+
rspec (3.8.0)
|
26
|
+
rspec-core (~> 3.8.0)
|
27
|
+
rspec-expectations (~> 3.8.0)
|
28
|
+
rspec-mocks (~> 3.8.0)
|
29
|
+
rspec-core (3.8.1)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-expectations (3.8.4)
|
26
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.
|
28
|
-
rspec-mocks (3.
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-mocks (3.8.1)
|
29
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.
|
31
|
-
rspec-support (3.
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-support (3.8.2)
|
38
|
+
simplecov (0.16.1)
|
39
|
+
docile (~> 1.1)
|
40
|
+
json (>= 1.8, < 3)
|
41
|
+
simplecov-html (~> 0.10.0)
|
42
|
+
simplecov-html (0.10.2)
|
43
|
+
term-ansicolor (1.7.1)
|
44
|
+
tins (~> 1.0)
|
45
|
+
thor (0.20.3)
|
46
|
+
tins (1.20.3)
|
32
47
|
|
33
48
|
PLATFORMS
|
34
49
|
ruby
|
35
50
|
|
36
51
|
DEPENDENCIES
|
52
|
+
coveralls
|
37
53
|
rake
|
38
54
|
rdoc
|
39
55
|
roma
|
@@ -41,4 +57,4 @@ DEPENDENCIES
|
|
41
57
|
rspec
|
42
58
|
|
43
59
|
BUNDLED WITH
|
44
|
-
|
60
|
+
2.0.1
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# ROMA Client for Ruby
|
2
2
|
|
3
|
+
[](https://travis-ci.org/roma/roma-ruby-client)
|
4
|
+
[](https://badge.fury.io/rb/roma-client)
|
5
|
+
[](https://coveralls.io/github/roma/roma-ruby-client?branch=master)
|
6
|
+
|
3
7
|
ROMA is one of the data storing systems for distributed key-value stores in Ruby.
|
4
8
|
The gem `roma-client` is Ruby client to talk with ROMA severs.
|
5
9
|
|
@@ -17,24 +17,23 @@ module Roma
|
|
17
17
|
attr_accessor :servers
|
18
18
|
attr_accessor :default_hash_name
|
19
19
|
attr_accessor :start_sync_routing_proc
|
20
|
-
|
21
|
-
@@client_pools = {}
|
20
|
+
attr_accessor :max_pool_size
|
22
21
|
|
23
22
|
# get ClientPool instance
|
24
23
|
# type:: identifier for client groups.
|
25
24
|
def self.instance(type = :default)
|
26
|
-
|
27
|
-
|
25
|
+
client_pools[type] ||= new
|
26
|
+
client_pools[type]
|
28
27
|
end
|
29
28
|
|
30
29
|
# get all pool
|
31
30
|
def self.client_pools
|
32
|
-
@@client_pools
|
31
|
+
@@client_pools ||= {}
|
33
32
|
end
|
34
33
|
|
35
34
|
# release all pool
|
36
35
|
def self.release_all
|
37
|
-
|
36
|
+
client_pools.each do |k,v|
|
38
37
|
v.release
|
39
38
|
end
|
40
39
|
end
|
@@ -46,21 +45,22 @@ module Roma
|
|
46
45
|
def client
|
47
46
|
c = nil
|
48
47
|
if @clients.empty?
|
49
|
-
|
48
|
+
c = Roma::Client::RomaClient.new(servers,
|
50
49
|
plugin_modules,
|
51
50
|
start_sync_routing_proc)
|
52
|
-
|
53
|
-
c = client
|
51
|
+
c.default_hash_name = default_hash_name
|
54
52
|
else
|
55
53
|
c = @clients.pop
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
if block_given?
|
57
|
+
begin
|
58
|
+
yield c
|
59
|
+
ensure
|
60
|
+
push_client(c)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
return c
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -82,16 +82,6 @@ module Roma
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
# get max pool size
|
86
|
-
def max_pool_size
|
87
|
-
@max_pool_size
|
88
|
-
end
|
89
|
-
|
90
|
-
# set max_pool_size
|
91
|
-
def max_pool_size=(count)
|
92
|
-
@max_pool_size = count
|
93
|
-
end
|
94
|
-
|
95
85
|
# get all clients
|
96
86
|
def clients
|
97
87
|
@clients
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'digest/sha1'
|
3
|
-
require 'roma/client/routing/routing_data'
|
4
3
|
|
5
4
|
module Roma
|
6
5
|
module Client
|
@@ -38,7 +37,7 @@ module Roma
|
|
38
37
|
d & @search_mask
|
39
38
|
end
|
40
39
|
|
41
|
-
# Returns a node-is list at the vnode.
|
40
|
+
# Returns a node-is list at the vnode.
|
42
41
|
# +vn+: vnode-id
|
43
42
|
def search_nodes(vn)
|
44
43
|
@rd.v_idx[vn].clone
|
data/lib/roma/client/version.rb
CHANGED
@@ -1,127 +1,153 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
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
|
-
|
5
|
+
let(:test_nodes) do
|
13
6
|
DEFAULT_PORTS.map { |port| "#{DEFAULT_HOST}:#{port}" }
|
14
7
|
end
|
15
8
|
|
16
9
|
context 'Singleton' do
|
17
10
|
subject { Roma::Client::ClientPool.instance(:test) }
|
18
|
-
it { expect(subject.class).to eq(Roma::Client::ClientPool) }
|
19
11
|
|
12
|
+
it { expect(subject.class).to eq(Roma::Client::ClientPool) }
|
20
13
|
it { expect(subject).to be_equal Roma::Client::ClientPool.instance(:test) }
|
21
|
-
|
22
14
|
it { expect(subject).not_to be_equal Roma::Client::ClientPool.instance(:test2) }
|
23
|
-
|
24
15
|
it do
|
25
16
|
expect { Roma::Client::ClientPool.new }.to raise_error(NoMethodError,
|
26
17
|
"private method `new' called for Roma::Client::ClientPool:Class")
|
27
18
|
end
|
28
19
|
end
|
29
20
|
|
30
|
-
|
31
|
-
|
21
|
+
describe '#max_pool_size' do
|
22
|
+
context 'max pool size of default' do
|
23
|
+
subject { Roma::Client::ClientPool.instance(:test) }
|
24
|
+
|
25
|
+
describe '#max_pool_size' do
|
26
|
+
subject { super().max_pool_size }
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
it { is_expected.to eq(1) }
|
28
|
+
it { is_expected.to eq(1) }
|
29
|
+
end
|
36
30
|
end
|
37
|
-
end
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
context 'set max pool size ' do
|
33
|
+
it do
|
34
|
+
pool = Roma::Client::ClientPool.instance(:test)
|
35
|
+
expect(pool.max_pool_size).to eq(1)
|
36
|
+
pool.max_pool_size = 3
|
37
|
+
expect(pool.max_pool_size).to eq(3)
|
45
38
|
|
46
|
-
|
47
|
-
|
39
|
+
pool2 = Roma::Client::ClientPool.instance(:test2)
|
40
|
+
expect(pool2.max_pool_size).to eq(1)
|
41
|
+
end
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
51
|
-
|
52
|
-
subject { Roma::Client::ClientPool.instance(:test) }
|
45
|
+
describe '#servers' do
|
46
|
+
subject { Roma::Client::ClientPool.instance(:test).servers }
|
53
47
|
|
54
|
-
|
55
|
-
subject { super().servers }
|
56
|
-
it { is_expected.to be_nil }
|
57
|
-
end
|
58
|
-
end
|
48
|
+
it { is_expected.to be_nil }
|
59
49
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
50
|
+
context 'servers set' do
|
51
|
+
it do
|
52
|
+
pool = Roma::Client::ClientPool.instance(:test_servers_set)
|
53
|
+
expect(pool.servers).to be_nil
|
54
|
+
nodes = test_nodes
|
55
|
+
pool.servers = nodes
|
56
|
+
expect(pool.servers).to eq(nodes)
|
67
57
|
|
68
|
-
|
58
|
+
expect(Roma::Client::ClientPool.instance(:test_ini_nodes_set2).servers).to be_nil
|
59
|
+
end
|
69
60
|
end
|
70
61
|
end
|
71
62
|
|
72
|
-
|
63
|
+
describe '#client' do
|
73
64
|
subject do
|
74
65
|
pool = Roma::Client::ClientPool.instance(:test_client)
|
75
|
-
pool.
|
66
|
+
pool.max_pool_size = 1
|
67
|
+
pool.servers = test_nodes
|
76
68
|
pool
|
77
69
|
end
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
client = subject.client
|
82
|
-
expect(client.class).to eq(Roma::Client::RomaClient)
|
83
|
-
subject.push_client(client)
|
84
|
-
expect(subject.pool_count).to eq(1)
|
71
|
+
before do
|
72
|
+
subject.release
|
85
73
|
end
|
86
|
-
it { expect(subject.servers).to eq(get_nodes) }
|
87
|
-
end
|
88
74
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
75
|
+
context 'When the pool is empty' do
|
76
|
+
it 'should generate client instance' do
|
77
|
+
dummy_client = double(:client).as_null_object
|
78
|
+
expect(Roma::Client::RomaClient).to receive(:new).and_return(dummy_client)
|
79
|
+
|
80
|
+
subject.client
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'When the pool is full' do
|
84
|
+
let(:pushed_client) { double('pushed_client') }
|
85
|
+
let(:ignored_client) { double('new dummy client to be ignored') }
|
86
|
+
|
87
|
+
before do
|
88
|
+
subject.push_client(pushed_client)
|
89
|
+
subject.push_client(ignored_client)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'the last pushed client is ignored' do
|
93
|
+
expect(subject.pool_count).to eq(1)
|
94
|
+
expect(subject.clients).to include(pushed_client)
|
95
|
+
expect(subject.clients).to_not include(ignored_client)
|
96
|
+
end
|
97
|
+
end
|
94
98
|
end
|
95
99
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
context 'client multi pool' do
|
101
|
+
subject do
|
102
|
+
pool = Roma::Client::ClientPool.instance(:test_client2)
|
103
|
+
pool.servers = test_nodes
|
104
|
+
pool
|
105
|
+
end
|
100
106
|
|
101
|
-
|
102
|
-
|
107
|
+
it do
|
108
|
+
dummy_client = double(:client).as_null_object
|
109
|
+
expect(Roma::Client::RomaClient).to receive(:new).and_return(dummy_client).twice
|
103
110
|
|
104
|
-
|
105
|
-
|
111
|
+
expect(subject.pool_count).to eq(0)
|
112
|
+
client = subject.client
|
113
|
+
expect(client).not_to be_nil
|
106
114
|
|
107
|
-
|
108
|
-
|
115
|
+
client2 = subject.client
|
116
|
+
expect(client2).not_to be_nil
|
109
117
|
|
110
|
-
|
111
|
-
|
118
|
+
subject.push_client(client)
|
119
|
+
expect(subject.pool_count).to eq(1)
|
120
|
+
|
121
|
+
subject.push_client(client2)
|
122
|
+
expect(subject.pool_count).to eq(1)
|
123
|
+
|
124
|
+
expect(client).to be_equal subject.client
|
125
|
+
expect(subject.pool_count).to eq(0)
|
126
|
+
end
|
112
127
|
end
|
113
|
-
end
|
114
128
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
129
|
+
context 'When block is given' do
|
130
|
+
it do
|
131
|
+
dummy_client = double(:client).as_null_object
|
132
|
+
expect(Roma::Client::RomaClient).to receive(:new).and_return(dummy_client)
|
133
|
+
|
134
|
+
expect { |b| subject.client(&b) }.to yield_with_args(dummy_client)
|
119
135
|
end
|
120
136
|
end
|
137
|
+
end
|
121
138
|
|
122
|
-
|
123
|
-
|
124
|
-
|
139
|
+
describe '#plugin_modules' do
|
140
|
+
before do
|
141
|
+
module TestPlugin
|
142
|
+
def test_plugin
|
143
|
+
'test_plugin'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
module TestPlugin2
|
148
|
+
def test_plugin2
|
149
|
+
'test_plugin2'
|
150
|
+
end
|
125
151
|
end
|
126
152
|
end
|
127
153
|
|
@@ -132,34 +158,34 @@ describe Roma::Client::ClientPool do
|
|
132
158
|
pool.add_plugin_module(TestPlugin)
|
133
159
|
expect(pool.plugin_modules).not_to be_nil
|
134
160
|
expect(pool.plugin_modules.size).to eq(1)
|
135
|
-
pool.plugin_modules[0]
|
161
|
+
expect(pool.plugin_modules[0]).to eq(TestPlugin)
|
136
162
|
end
|
137
163
|
|
138
|
-
|
139
|
-
pool
|
140
|
-
expect(pool.plugin_modules).to be_nil
|
164
|
+
context 'the pool has some plugin moudles' do
|
165
|
+
let(:pool) { Roma::Client::ClientPool.instance(:pms_test) }
|
141
166
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
pool.plugin_modules[1] == TestPlugin2
|
146
|
-
end
|
167
|
+
before do
|
168
|
+
pool.plugin_modules = [TestPlugin, TestPlugin2]
|
169
|
+
end
|
147
170
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
171
|
+
it do
|
172
|
+
expect(pool.plugin_modules.size).to eq(2)
|
173
|
+
expect(pool.plugin_modules).to contain_exactly(TestPlugin, TestPlugin2)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'pool.client generates roma client with pool.plugin_modules' do
|
177
|
+
client = double('roma client').as_null_object
|
178
|
+
expect(Roma::Client::RomaClient).to receive(:new).
|
179
|
+
with(pool.servers, pool.plugin_modules, pool.start_sync_routing_proc).and_return(client)
|
152
180
|
|
153
|
-
|
154
|
-
|
155
|
-
expect(client).not_to be_nil
|
156
|
-
expect(client.test_plugin).to eq('test_plugin')
|
157
|
-
expect(client.test_plugin2).to eq('test_plugin2')
|
181
|
+
pool.client
|
182
|
+
end
|
158
183
|
end
|
159
184
|
end
|
160
185
|
|
161
186
|
context 'default type' do
|
162
187
|
subject { Roma::Client::ClientPool.instance }
|
188
|
+
|
163
189
|
it { is_expected.not_to be_nil }
|
164
190
|
it { expect(subject.class).to eq(Roma::Client::ClientPool) }
|
165
191
|
it { expect(subject).to be_equal Roma::Client::ClientPool.instance(:default) }
|
@@ -170,7 +196,7 @@ describe Roma::Client::ClientPool do
|
|
170
196
|
|
171
197
|
subject do
|
172
198
|
pool = Roma::Client::ClientPool.instance
|
173
|
-
pool.servers =
|
199
|
+
pool.servers = test_nodes
|
174
200
|
pool
|
175
201
|
end
|
176
202
|
|
@@ -181,112 +207,46 @@ describe Roma::Client::ClientPool do
|
|
181
207
|
expect(Roma::Client::ClientPool.instance.default_hash_name).to eq('new_name')
|
182
208
|
expect(Roma::Client::ClientPool.instance(:other).default_hash_name).to eq('roma')
|
183
209
|
|
184
|
-
client =
|
185
|
-
expect(client
|
210
|
+
client = double('roma client').as_null_object
|
211
|
+
expect(client).to receive(:default_hash_name=).with('new_name')
|
212
|
+
expect(Roma::Client::RomaClient).to receive(:new).and_return(client)
|
213
|
+
subject.client
|
186
214
|
end
|
187
215
|
end
|
188
216
|
|
189
217
|
context 'release' do
|
190
218
|
subject do
|
191
219
|
pool = Roma::Client::ClientPool.instance(:release_test)
|
192
|
-
pool.servers =
|
220
|
+
pool.servers = test_nodes
|
193
221
|
pool
|
194
222
|
end
|
195
223
|
|
196
224
|
it do
|
197
|
-
|
198
|
-
subject.client do |client|
|
199
|
-
end
|
200
|
-
|
225
|
+
subject.push_client(double('dummy client'))
|
201
226
|
expect(subject.pool_count).to eq(1)
|
202
227
|
expect(subject.release).to be_truthy
|
203
228
|
expect(subject.pool_count).to eq(0)
|
204
229
|
end
|
205
230
|
end
|
206
231
|
|
207
|
-
context 'client block' do
|
208
|
-
before(:each) do
|
209
|
-
pool = Roma::Client::ClientPool.instance(:client_block)
|
210
|
-
pool.release
|
211
|
-
end
|
212
|
-
|
213
|
-
subject do
|
214
|
-
pool = Roma::Client::ClientPool.instance(:client_block)
|
215
|
-
pool.servers = get_nodes
|
216
|
-
pool
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'use block'do
|
220
|
-
expect(subject.pool_count).to eq(0)
|
221
|
-
subject.client do |client|
|
222
|
-
expect(client.set('test', 'value')).to eq('STORED')
|
223
|
-
end
|
224
|
-
expect(subject.pool_count).to eq(1)
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'raise exception in block, but pool certainly' do
|
228
|
-
expect(subject.pool_count).to eq(0)
|
229
|
-
subject.client do |client|
|
230
|
-
expect(client.set('test', 'value')).to eq('STORED')
|
231
|
-
end
|
232
|
-
expect(subject.pool_count).to eq(1)
|
233
|
-
|
234
|
-
expect do
|
235
|
-
subject.client do |client|
|
236
|
-
raise 'test error'
|
237
|
-
end
|
238
|
-
end.to raise_error RuntimeError, 'test error'
|
239
|
-
|
240
|
-
expect(subject.pool_count).to eq(1)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context 'start sync routing proc' do
|
245
|
-
it do
|
246
|
-
pool = Roma::Client::ClientPool.instance(:sync_test)
|
247
|
-
pool.servers = get_nodes
|
248
|
-
old_thread_count = Thread.list.length
|
249
|
-
pool.client do |c|
|
250
|
-
end
|
251
|
-
|
252
|
-
expect(pool.pool_count).to eq(1)
|
253
|
-
expect(Thread.list.length).to eq(old_thread_count + 1)
|
254
|
-
end
|
255
|
-
|
256
|
-
it do
|
257
|
-
pool = Roma::Client::ClientPool.instance(:no_sync_test)
|
258
|
-
pool.servers = get_nodes
|
259
|
-
pool.start_sync_routing_proc = false
|
260
|
-
old_thread_count = Thread.list.length
|
261
|
-
pool.client do |c|
|
262
|
-
end
|
263
|
-
|
264
|
-
expect(pool.pool_count).to eq(1)
|
265
|
-
expect(Thread.list.length).to eq(old_thread_count)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
232
|
context 'release all' do
|
270
233
|
it do
|
271
234
|
pool = Roma::Client::ClientPool.instance(:release_all_1)
|
272
|
-
pool.servers =
|
273
|
-
pool.client
|
274
|
-
end
|
235
|
+
pool.servers = test_nodes
|
236
|
+
pool.push_client(double('dummy client 1'))
|
275
237
|
expect(Roma::Client::ClientPool.instance(:release_all_1).pool_count).to eq(1)
|
276
238
|
|
277
239
|
pool = Roma::Client::ClientPool.instance(:release_all_2)
|
278
|
-
pool.servers =
|
279
|
-
pool.client
|
280
|
-
end
|
240
|
+
pool.servers = test_nodes
|
241
|
+
pool.push_client(double('dummy client 1'))
|
281
242
|
expect(pool.pool_count).to eq(1)
|
282
243
|
expect(Roma::Client::ClientPool.instance(:release_all_2).pool_count).to eq(1)
|
283
244
|
|
284
245
|
Roma::Client::ClientPool.release_all
|
285
246
|
expect(Roma::Client::ClientPool.instance(:release_all_1).pool_count).to eq(0)
|
286
247
|
expect(Roma::Client::ClientPool.instance(:release_all_2).pool_count).to eq(0)
|
287
|
-
|
288
|
-
expect(Roma::Client::ClientPool.instance(:
|
289
|
-
expect(Roma::Client::ClientPool.instance(:release_all_2).servers).to eq(get_nodes)
|
248
|
+
expect(Roma::Client::ClientPool.instance(:release_all_1).servers).to eq(test_nodes)
|
249
|
+
expect(Roma::Client::ClientPool.instance(:release_all_2).servers).to eq(test_nodes)
|
290
250
|
end
|
291
251
|
end
|
292
252
|
end
|