cellect-client 0.0.7 → 0.0.8
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 +4 -4
- data/cellect-client.gemspec +1 -0
- data/lib/cellect/client/connection.rb +11 -1
- data/lib/cellect/version.rb +1 -1
- data/spec/client/connection_spec.rb +21 -3
- data/spec/client/node_set_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/support/shared_examples_for_node_set.rb +6 -6
- data/spec/support/shared_examples_for_set.rb +4 -4
- data/spec/support/shared_examples_for_workflow.rb +8 -8
- data/spec/support/zk_setup.rb +27 -25
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bef3620635a4c9925ddec189583b56ccf60ed08
|
4
|
+
data.tar.gz: 4cf61ff3a15c4661df6279efb382fb0be24cee0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60fe4c89fb71a17972eefb544e76e13960e2e84b94fef1f75b4076730bb2a09180eab9e106ce37d2bff2f108af88b1a1c34dd5c0e8b2c834f5723b8bb5e12ae3
|
7
|
+
data.tar.gz: fe2197a0d56baae9439755057e03c3391a6655ca7b40716137d79c76f10866115a5800ff253f945c81da597536bea6571f31fe02480076ca927641dcc4c063ab
|
data/cellect-client.gemspec
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'http'
|
2
|
+
require 'multi_json'
|
2
3
|
|
3
4
|
module Cellect
|
4
5
|
module Client
|
6
|
+
class CellectServerError < StandardError; end
|
5
7
|
class Connection
|
6
8
|
include Celluloid
|
7
9
|
include Celluloid::IO
|
@@ -31,7 +33,9 @@ module Cellect
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def get_subjects(user_id: user_id, host: host, workflow_id: workflow_id, limit: limit, group_id: group_id)
|
34
|
-
send_http host, :get, "/workflows/#{ workflow_id }", querystring(user_id: user_id, group_id: group_id, limit: limit)
|
36
|
+
response = send_http host, :get, "/workflows/#{ workflow_id }", querystring(user_id: user_id, group_id: group_id, limit: limit)
|
37
|
+
ensure_valid_response response
|
38
|
+
MultiJson.load response.body
|
35
39
|
end
|
36
40
|
|
37
41
|
protected
|
@@ -57,6 +61,12 @@ module Cellect
|
|
57
61
|
end
|
58
62
|
end.join('&')
|
59
63
|
end
|
64
|
+
|
65
|
+
def ensure_valid_response(response)
|
66
|
+
unless response.code == 200
|
67
|
+
raise CellectServerError, "Server Responded #{ response.code }"
|
68
|
+
end
|
69
|
+
end
|
60
70
|
end
|
61
71
|
end
|
62
72
|
end
|
data/lib/cellect/version.rb
CHANGED
@@ -5,11 +5,11 @@ module Cellect::Client
|
|
5
5
|
let(:connection){ Cellect::Client.connection }
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
Cellect::Client.node_set.
|
8
|
+
allow(Cellect::Client.node_set).to receive(:nodes).and_return 'a' => '1', 'b' => '2'
|
9
9
|
end
|
10
10
|
|
11
11
|
def should_send(action: action, url: url, to: to)
|
12
|
-
HTTP.
|
12
|
+
expect(HTTP).to receive(:send).with(action, "http://#{ to }/#{ url }", socket_class: Celluloid::IO::TCPSocket).and_return(HTTP::Response.new(200, nil, nil, "{ \"this response\": \"intentionally blank\" }"))
|
13
13
|
end
|
14
14
|
|
15
15
|
def should_broadcast(action: action, url: url)
|
@@ -60,12 +60,30 @@ module Cellect::Client
|
|
60
60
|
should_send action: :put, url: 'workflows/random/users/123/add_seen?subject_id=456', to: 1
|
61
61
|
connection.add_seen subject_id: 456, host: '1', user_id: 123, workflow_id: 'random'
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it 'should get subjects' do
|
65
65
|
should_send action: :get, url: 'workflows/random?user_id=1&group_id=1&limit=10', to: 1
|
66
66
|
connection.get_subjects host: '1', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
|
67
67
|
should_send action: :get, url: 'workflows/random?user_id=1', to: 1
|
68
68
|
connection.get_subjects host: '1', workflow_id: 'random', user_id: 1
|
69
69
|
end
|
70
|
+
|
71
|
+
context 'getting subjects' do
|
72
|
+
def get_subjects
|
73
|
+
connection.get_subjects host: '1', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should return subjects as an array' do
|
77
|
+
response = HTTP::Response.new 200, '1.1', nil, '[1, 2, 3, 4, 5]'
|
78
|
+
allow(HTTP).to receive(:send).and_return response
|
79
|
+
expect(get_subjects).to eq [1, 2, 3, 4, 5]
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should raise an error for unexpected responses' do
|
83
|
+
response = HTTP::Response.new 404, '1.1', nil, ''
|
84
|
+
allow(HTTP).to receive(:send).and_return response
|
85
|
+
expect{ get_subjects }.to raise_error Cellect::Client::CellectServerError, 'Server Responded 404'
|
86
|
+
end
|
87
|
+
end
|
70
88
|
end
|
71
89
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
Bundler.require :test, :development
|
9
9
|
|
10
10
|
ENV['CELLECT_POOL_SIZE'] = '3'
|
11
|
+
SPAWN_ZK = !ENV['ZK_URL']
|
11
12
|
|
12
13
|
require 'pry'
|
13
14
|
require 'oj'
|
@@ -24,7 +25,6 @@ Cellect::Server.adapter = SpecAdapter.new
|
|
24
25
|
SET_TYPES = %w(random priority pairwise_random pairwise_priority)
|
25
26
|
|
26
27
|
RSpec.configure do |config|
|
27
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
28
28
|
config.run_all_when_everything_filtered = true
|
29
29
|
config.filter_run :focus
|
30
30
|
config.order = 'random'
|
@@ -37,6 +37,6 @@ RSpec.configure do |config|
|
|
37
37
|
end
|
38
38
|
|
39
39
|
config.after(:suite) do
|
40
|
-
`zkServer stop #{ CELLECT_ZK_CONFIG } > /dev/null 2>&1`
|
40
|
+
`zkServer stop #{ CELLECT_ZK_CONFIG } > /dev/null 2>&1` if SPAWN_ZK
|
41
41
|
end
|
42
42
|
end
|
@@ -2,24 +2,24 @@ shared_examples_for 'node set' do
|
|
2
2
|
let(:node_set){ Cellect::NodeSet.new }
|
3
3
|
|
4
4
|
it 'should connect to zoo keeper' do
|
5
|
-
node_set.zk.
|
5
|
+
expect(node_set.zk).to be_nil
|
6
6
|
pass_until node_set, is: :ready
|
7
|
-
node_set.zk.
|
7
|
+
expect(node_set.zk).to be_connected
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should know the connection state' do
|
11
|
-
node_set.state.
|
11
|
+
expect(node_set.state).to be :initializing
|
12
12
|
pass_until node_set, is: :ready
|
13
|
-
node_set.
|
13
|
+
expect(node_set).to be_ready
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should accept a connection string' do
|
17
17
|
begin
|
18
18
|
pass_until node_set, is: :ready
|
19
19
|
ENV['ZK_URL'] = 'foobar'
|
20
|
-
node_set.send(:zk_url).
|
20
|
+
expect(node_set.send(:zk_url)).to eq 'foobar'
|
21
21
|
ENV.delete 'ZK_URL'
|
22
|
-
node_set.send(:zk_url).
|
22
|
+
expect(node_set.send(:zk_url)).to eq 'localhost:2181'
|
23
23
|
ensure
|
24
24
|
ENV['ZK_URL'] = 'localhost:21811'
|
25
25
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
shared_examples_for 'a set' do
|
2
2
|
it 'should convert to an Array' do
|
3
|
-
set.to_a.
|
3
|
+
expect(set.to_a).to eq (1..5).to_a
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'should add elements' do
|
7
7
|
set.add 100
|
8
|
-
set.to_a.
|
8
|
+
expect(set.to_a).to include 100
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should remove elements' do
|
@@ -14,7 +14,7 @@ shared_examples_for 'a set' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should sample elements' do
|
17
|
-
set.sample(2).length.
|
17
|
+
expect(set.sample(2).length).to eq 2
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should not include removed elements in samples' do
|
@@ -29,6 +29,6 @@ shared_examples_for 'a set' do
|
|
29
29
|
it 'should know if it contains an element' do
|
30
30
|
set.should_not include 100
|
31
31
|
set.add 100
|
32
|
-
set.
|
32
|
+
expect(set).to include 100
|
33
33
|
end
|
34
34
|
end
|
@@ -6,21 +6,21 @@ shared_examples_for 'workflow' do |name|
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'should add singleton instances to the registry' do
|
9
|
-
obj.class[:foo].
|
10
|
-
obj.class[:foo].object_id.
|
9
|
+
expect(obj.class[:foo]).to be_a_kind_of Cellect::Server::Workflow
|
10
|
+
expect(obj.class[:foo].object_id).to eq obj.class[:foo].object_id
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should initialize empty' do
|
14
|
-
obj.name.
|
15
|
-
obj.users.
|
14
|
+
expect(obj.name).to be_a String
|
15
|
+
expect(obj.users).to be_a Hash
|
16
16
|
|
17
17
|
set_klass = obj.prioritized? ? DiffSet::PrioritySet : DiffSet::RandomSet
|
18
|
-
obj.subjects.
|
18
|
+
expect(obj.subjects).to be_a set_klass
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should provide a user lookup' do
|
22
|
-
obj.user(1).
|
23
|
-
obj.user(1).object_id.
|
24
|
-
obj.users.keys.
|
22
|
+
expect(obj.user(1)).to be_a Cellect::Server::User
|
23
|
+
expect(obj.user(1).object_id).to eq obj.user(1).object_id
|
24
|
+
expect(obj.users.keys).to include 1
|
25
25
|
end
|
26
26
|
end
|
data/spec/support/zk_setup.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
if SPAWN_ZK
|
2
|
+
zk_dir = File.join CELLECT_ROOT, 'tmp/zookeeper'
|
3
|
+
CELLECT_ZK_CONFIG = "#{ zk_dir }/zoo.cfg"
|
4
|
+
|
5
|
+
`rm -rf #{ zk_dir }; mkdir -p #{ zk_dir }`
|
6
|
+
|
7
|
+
File.open(CELLECT_ZK_CONFIG, 'w') do |out|
|
8
|
+
out.puts <<-TEXT
|
9
|
+
tickTime=2000
|
10
|
+
initLimit=10
|
11
|
+
syncLimit=5
|
12
|
+
dataDir=#{ zk_dir }
|
13
|
+
clientPort=21811
|
14
|
+
forceSync=no
|
15
|
+
snapCount=1000000
|
16
|
+
TEXT
|
17
|
+
end
|
18
|
+
|
19
|
+
if `echo ruok | nc 127.0.0.1 21811`.chomp == 'imok'
|
20
|
+
pid = `ps aux | grep -e 'Cellect[\/]tmp[\/]zookeeper'`.split[1]
|
21
|
+
puts "Killing rogue zookeeper process: #{ pid }..."
|
22
|
+
`kill -s TERM #{ pid }`
|
23
|
+
sleep 1
|
24
|
+
end
|
25
|
+
|
26
|
+
`zkServer start #{ CELLECT_ZK_CONFIG } > /dev/null 2>&1`
|
27
|
+
ENV['ZK_URL'] = 'localhost:21811'
|
16
28
|
end
|
17
|
-
|
18
|
-
if `echo ruok | nc 127.0.0.1 21811`.chomp == 'imok'
|
19
|
-
pid = `ps aux | grep -e 'Cellect[\/]tmp[\/]zookeeper'`.split[1]
|
20
|
-
puts "Killing rogue zookeeper process: #{ pid }..."
|
21
|
-
`kill -s TERM #{ pid }`
|
22
|
-
sleep 1
|
23
|
-
end
|
24
|
-
|
25
|
-
`zkServer start #{ CELLECT_ZK_CONFIG } > /dev/null 2>&1`
|
26
|
-
ENV['ZK_URL'] = 'localhost:21811'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellect-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '1.9'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: multi_json
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.10.1
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.10.1
|
153
167
|
description: ''
|
154
168
|
email:
|
155
169
|
- michael@zooniverse.org
|
@@ -216,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
230
|
version: '0'
|
217
231
|
requirements: []
|
218
232
|
rubyforge_project:
|
219
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.4.2
|
220
234
|
signing_key:
|
221
235
|
specification_version: 4
|
222
236
|
summary: ''
|