cellect-client 1.3.3 → 2.0.0.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c414f83a76934a80ce41a9b009cff485aa7f3cdc
4
- data.tar.gz: 04721cdaa50af48bb7fdecaad358931dafecadec
3
+ metadata.gz: c1943ffc5eb994302c23d0a0029699596566f1f6
4
+ data.tar.gz: 7fefec91b8e36608d19a8f2c8d1f042643affb17
5
5
  SHA512:
6
- metadata.gz: 12ad06c6fe0d0f84e8c852b77a1035292351eff79e3d88308f33de8f914a837a078f8fe3cddb5d9c4838e670c232dadd41f61840dd08b6528e4d57f01322775e
7
- data.tar.gz: 735fcf22c87fe2e9e3fef69cff278e1b4aa8cfd3f1df45707059fdf0cbe7a51b632340565046f20b8fd5859c709aa57db65d05e48e15f9d87a27ee22615a1534
6
+ metadata.gz: 2a1f6cccf3a2100522114974045b2c2a1de9815ed00c70684fbd639a2cba3103d2755c860e5d9b4d03493c23943965c40d5b094d182c74fa17a3bd0aec21359b
7
+ data.tar.gz: a00b8b4bc3b8c63fac8cbf12ce42e62da0b02232ee0dc990d9bcde68334d7835da1aed816aa92bacd080b63f6f77593d35797f3606910b215ee2afaac20bf26d
data/.travis.yml CHANGED
@@ -12,3 +12,5 @@ rvm:
12
12
  - 2.2.1
13
13
 
14
14
  script: bundle exec rake spec
15
+ services:
16
+ - redis-server
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}){ |m| "spec/#{ m[1] }_spec.rb" }
4
+ watch('spec/spec_helper.rb'){ 'spec' }
5
+ watch(%r{^spec/support/(.+)\.rb$}){ 'spec' }
6
+ end
data/README.md CHANGED
@@ -14,7 +14,7 @@ Available as
14
14
 
15
15
  ## Cellect::Server
16
16
 
17
- An actor based system that provides an API around subject selection actions. Server nodes are discovered via [ZooKeeper](http://zookeeper.apache.org/).
17
+ An actor based system that provides an API around subject selection actions. Server nodes are discovered via [Attention](https://github.com/parrish/attention).
18
18
 
19
19
  ### Cellect::Server::Adapters
20
20
 
@@ -25,7 +25,13 @@ We're overriding the default adapter with a customization in [cellect_panoptes](
25
25
 
26
26
  ## Cellect::Client
27
27
 
28
- Provides a mix of asynchronous and synchronous operations for server awareness and API communication.
28
+ Provides operations for server awareness and API communication.
29
+
30
+ API timeouts can be set with
31
+
32
+ ```ruby
33
+ Cellect::Client::Connection.timeout = 5 # seconds
34
+ ```
29
35
 
30
36
 
31
37
  ## Building
@@ -42,9 +48,7 @@ To install rice your Ruby must be compiled with shared libraries enabled, from t
42
48
 
43
49
  ## Testing
44
50
 
45
- * You'll need a local Zookeeper server to run the specs (they will auto start / stop the server for you).
46
- * `brew install zookeeper`
47
- * Note: this may require a Java Runtime (JRE) install, `brew cask install java`
51
+ * You'll need a local Redis server to run the specs.
48
52
 
49
53
  Run the specs with `rake`
50
54
 
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cellect'
5
+ require 'cellect/server'
6
+ require 'cellect/client'
7
+ require 'pry'
8
+
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -24,14 +24,14 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'bundler', '~> 1.10'
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'oj'
27
+ spec.add_development_dependency 'guard'
28
+ spec.add_development_dependency 'guard-rspec'
27
29
  spec.add_development_dependency 'rspec'
28
- spec.add_development_dependency 'zk-server'
29
30
  spec.add_development_dependency 'rack-test'
30
31
  spec.add_development_dependency 'pry'
31
32
 
32
33
  spec.add_runtime_dependency 'celluloid', '0.16.0'
33
- spec.add_runtime_dependency 'celluloid-io', '0.16.0'
34
34
  spec.add_runtime_dependency 'http', '~> 0.9'
35
- spec.add_runtime_dependency 'zk', '~> 1.9'
35
+ spec.add_runtime_dependency 'attention', '~> 0.0.4'
36
36
  spec.add_runtime_dependency 'multi_json', '~> 1.11'
37
37
  end
data/cellect.gemspec CHANGED
@@ -23,8 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'oj'
24
24
  spec.add_development_dependency 'rspec'
25
25
  spec.add_development_dependency 'rack-test'
26
- spec.add_development_dependency 'zk-server'
27
26
  spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'guard'
28
+ spec.add_development_dependency 'guard-rspec'
28
29
  spec.add_development_dependency 'puma', '~> 2.8'
29
30
  spec.add_development_dependency 'pg', '~> 0.17'
30
31
  spec.add_development_dependency 'connection_pool', '~> 2.0'
@@ -5,8 +5,11 @@ module Cellect
5
5
  module Client
6
6
  class CellectServerError < StandardError; end
7
7
  class Connection
8
- include Celluloid
9
- include Celluloid::IO
8
+ class << self
9
+ attr_accessor :timeout
10
+ end
11
+
12
+ @timeout = 5
10
13
 
11
14
  # Reload the data for a workflow on all servers
12
15
  def reload_workflow(id)
@@ -49,17 +52,21 @@ module Cellect
49
52
 
50
53
  # Broadcast by iterating over each server
51
54
  def broadcast(action, path, query = '')
52
- Cellect::Client.node_set.nodes.each_pair do |node, host|
53
- send_http host, action, path, query
55
+ Cellect::Client.node_set.nodes.each do |node|
56
+ send_http node['ip'], action, path, query
54
57
  end
55
58
  end
56
59
 
57
- # Makes an API call through an evented Celluloid Socket
60
+ # Makes an API call
58
61
  def send_http(host, action, path, query = '')
59
62
  params = { host: host, path: path }
60
63
  params[:query] = query if query && !query.empty?
61
64
  uri = URI::HTTP.build params
62
- HTTP.send action, uri.to_s, socket_class: Celluloid::IO::TCPSocket
65
+ with_timeout.send action, uri.to_s
66
+ end
67
+
68
+ def with_timeout
69
+ HTTP.timeout :global, connect: self.class.timeout
63
70
  end
64
71
 
65
72
  # Builds a querystring from a hash
@@ -1,37 +1,13 @@
1
- require 'cellect/node_set'
2
-
3
1
  module Cellect
4
2
  module Client
5
- class NodeSet < Cellect::NodeSet
3
+ class NodeSet
6
4
  attr_accessor :nodes
7
5
 
8
- # Sets up an empty node set
9
- def initialize(zk_url = nil)
10
- self.nodes = { }
11
- super
12
- end
13
-
14
- protected
15
-
16
- # Respond to a node coming online or timing out
17
- def nodes_changed(nodes)
18
- self.nodes = { }
19
- nodes.each do |node|
20
- self.nodes[node] = zk.get("/nodes/#{ node }").first
21
- end
22
- end
23
-
24
- # Register with ZooKeeper and get the list of nodes
25
- def setup
26
- watch_nodes
27
- zk.mkdir_p '/nodes'
28
- nodes_changed zk.children('/nodes', watch: true)
29
- end
30
-
31
- # Watch ZooKeeper for changes to the node set
32
- def watch_nodes
33
- zk.register('/nodes') do |event|
34
- nodes_changed zk.children('/nodes', watch: true)
6
+ # Gets the current list of nodes and listens to changes
7
+ def initialize
8
+ self.nodes = Attention.instances
9
+ Attention.on_change do |change, instances|
10
+ self.nodes = instances
35
11
  end
36
12
  end
37
13
  end
@@ -5,36 +5,24 @@ module Cellect
5
5
  require 'cellect/client/node_set'
6
6
  require 'cellect/client/connection'
7
7
 
8
- class << self
9
- attr_accessor :connection, :_node_set
10
- end
11
-
12
- # Disabled with lib/cellect/testing.rb
13
- def self.mock_zookeeper?
14
- false
15
- end
16
-
17
8
  # Sets up the set of server nodes
18
- def self.node_set(zk_url=nil)
19
- self._node_set ||= NodeSet.supervise(zk_url)
20
- _node_set.actors.first
9
+ def self.node_set
10
+ @node_set ||= NodeSet.new
21
11
  end
22
12
 
23
- def self.ready?
24
- node_set.ready?
13
+ def self.connection
14
+ @connection ||= Connection.new
25
15
  end
26
16
 
27
17
  # Selects a server for a user
28
18
  def self.choose_host
29
- node_set.nodes.values.sample
19
+ host = node_set.nodes.sample
20
+ host && host['ip']
30
21
  end
31
22
 
32
23
  # Ensure a previously selected server is still available
33
24
  def self.host_exists?(ip)
34
- node_set.nodes.values.include? ip
25
+ node_set.nodes.select{ |node| node['ip'] == ip }.length > 0
35
26
  end
36
-
37
- Client.node_set
38
- Client.connection = Connection.pool size: ENV.fetch('CELLECT_POOL_SIZE', 100).to_i
39
27
  end
40
28
  end
@@ -1,3 +1,3 @@
1
1
  module Cellect
2
- VERSION = '1.3.3'
2
+ VERSION = '2.0.0.beta1'
3
3
  end
data/lib/cellect.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'celluloid'
2
- require 'celluloid/io'
3
2
  require 'cellect/version'
3
+ require 'attention'
4
4
 
5
5
  module Cellect
6
-
7
6
  end
7
+
8
+ Attention.options[:namespace] = 'cellect'
9
+ Attention.options[:redis_url] = ENV['REDIS_URL'] if ENV['REDIS_URL']
10
+ Attention.options[:ttl] = 20
@@ -5,15 +5,20 @@ module Cellect::Client
5
5
  let(:connection){ Cellect::Client.connection }
6
6
 
7
7
  before(:each) do
8
- allow(Cellect::Client.node_set).to receive(:nodes).and_return 'a' => '1', 'b' => '2'
8
+ allow(Cellect::Client.node_set).to receive(:nodes).and_return [
9
+ { 'id' => '1', 'ip' => '1.2.3.4' },
10
+ { 'id' => '2', 'ip' => '5.6.7.8' }
11
+ ]
9
12
  end
10
13
 
11
14
  def should_send(action:, url:, to:)
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\" }"))
15
+ send_double = double
16
+ expect(HTTP).to receive(:timeout).with(:global, connect: Connection.timeout).and_return send_double
17
+ expect(send_double).to receive(:send).with(action, "http://#{ to }/#{ url }").and_return(HTTP::Response.new(200, nil, nil, "{ \"this response\": \"intentionally blank\" }"))
13
18
  end
14
19
 
15
20
  def should_broadcast(action:, url:)
16
- [1, 2].each{ |i| should_send action: action, url: url, to: i }
21
+ ['1.2.3.4', '5.6.7.8'].each{ |ip| should_send action: action, url: url, to: ip }
17
22
  end
18
23
 
19
24
  it 'should reload workflows' do
@@ -52,40 +57,44 @@ module Cellect::Client
52
57
  end
53
58
 
54
59
  it 'should load users' do
55
- should_send action: :post, url: 'workflows/random/users/123/load', to: 1
56
- connection.load_user user_id: 123, host: '1', workflow_id: 'random'
60
+ should_send action: :post, url: 'workflows/random/users/123/load', to: '1.2.3.4'
61
+ connection.load_user user_id: 123, host: '1.2.3.4', workflow_id: 'random'
57
62
  end
58
63
 
59
64
  it 'should add seen subjects' do
60
- should_send action: :put, url: 'workflows/random/users/123/add_seen?subject_id=456', to: 1
61
- connection.add_seen subject_id: 456, host: '1', user_id: 123, workflow_id: 'random'
65
+ should_send action: :put, url: 'workflows/random/users/123/add_seen?subject_id=456', to: '1.2.3.4'
66
+ connection.add_seen subject_id: 456, host: '1.2.3.4', user_id: 123, workflow_id: 'random'
62
67
  end
63
68
 
64
69
  it 'should get subjects' do
65
- should_send action: :get, url: 'workflows/random?user_id=1', to: 1
66
- connection.get_subjects host: '1', workflow_id: 'random', user_id: 1
70
+ should_send action: :get, url: 'workflows/random?user_id=1', to: '1.2.3.4'
71
+ connection.get_subjects host: '1.2.3.4', workflow_id: 'random', user_id: 1
67
72
  end
68
73
 
69
74
  it 'should get grouped subjects' do
70
- should_send action: :get, url: 'workflows/random?user_id=1&group_id=1&limit=10', to: 1
71
- connection.get_subjects host: '1', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
75
+ should_send action: :get, url: 'workflows/random?user_id=1&group_id=1&limit=10', to: '1.2.3.4'
76
+ connection.get_subjects host: '1.2.3.4', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
72
77
  end
73
78
 
74
79
  context 'getting subjects' do
75
80
  def get_subjects
76
- connection.get_subjects host: '1', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
81
+ connection.get_subjects host: '1.2.3.4', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
77
82
  end
78
83
 
79
84
  it 'should return subjects as an array' do
80
85
  response = HTTP::Response.new 200, '1.1', nil, '[1, 2, 3, 4, 5]'
81
- allow(HTTP).to receive(:send).and_return response
86
+ send_double = double
87
+ expect(HTTP).to receive(:timeout).with(:global, connect: Connection.timeout).and_return send_double
88
+ expect(send_double).to receive(:send).and_return response
82
89
  expect(get_subjects).to eq [1, 2, 3, 4, 5]
83
90
  end
84
91
 
85
92
  it 'should raise an error for unexpected responses' do
86
93
  response = HTTP::Response.new 404, '1.1', nil, ''
87
- allow(HTTP).to receive(:send).and_return response
88
- expect{ get_subjects }.to raise_error Cellect::Client::CellectServerError, 'Server Responded 404'
94
+ send_double = double
95
+ expect(HTTP).to receive(:timeout).with(:global, connect: Connection.timeout).and_return send_double
96
+ expect(send_double).to receive(:send).and_return response
97
+ expect{ get_subjects }.to raise_error CellectServerError, 'Server Responded 404'
89
98
  end
90
99
  end
91
100
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Cellect::Client
4
+ describe NodeSet do
5
+ let!(:node_set){ Cellect::Client.node_set }
6
+
7
+ # Allow listener to subscribe to Redis
8
+ def wait_for_listener
9
+ pass_until(timeout: 3) do
10
+ _, listeners = Redis.new.pubsub 'numsub', 'cellect:instance'
11
+ listeners > 0
12
+ end
13
+ end
14
+
15
+ # Allow redis to publish to listener
16
+ def wait_for_nodes(count)
17
+ pass_until(timeout: 3) do
18
+ node_set.nodes.length == count
19
+ end
20
+ end
21
+
22
+ it 'should initialize without nodes' do
23
+ expect(node_set.nodes).to be_empty
24
+ end
25
+
26
+ it 'should update the node list when activating' do
27
+ wait_for_listener
28
+ Attention.activate
29
+ wait_for_nodes 1
30
+ expect(node_set.nodes).to_not be_empty
31
+ end
32
+
33
+ it 'should update the node list when deactivating' do
34
+ wait_for_listener
35
+ Attention.activate
36
+ wait_for_nodes 1
37
+ Attention.deactivate
38
+ wait_for_nodes 0
39
+ expect(node_set.nodes).to be_empty
40
+ end
41
+ end
42
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,11 +10,8 @@ end
10
10
 
11
11
  Bundler.require :test, :development
12
12
 
13
- ENV['CELLECT_POOL_SIZE'] = '3'
14
- SPAWN_ZK = !ENV['ZK_URL']
15
13
  require 'pry'
16
14
  require 'oj'
17
- require './spec/support/zk_setup.rb'
18
15
  require 'cellect/server'
19
16
  require 'cellect/client'
20
17
  require 'celluloid/rspec'
@@ -33,12 +30,11 @@ RSpec.configure do |config|
33
30
  config.include CellectHelper
34
31
 
35
32
  config.around(:each) do |example|
33
+ Redis.new.flushdb
36
34
  Celluloid.boot
35
+ Attention.deactivate
37
36
  example.run
38
37
  Celluloid.shutdown
39
- end
40
-
41
- config.after(:suite) do
42
- ZK_Setup.stop_zk
38
+ Attention.deactivate
43
39
  end
44
40
  end
@@ -1,8 +1,8 @@
1
1
  require 'timeout'
2
2
 
3
3
  module CellectHelper
4
- def pass_until(&block)
5
- Timeout::timeout(1) do
4
+ def pass_until(timeout: 1, &block)
5
+ Timeout::timeout(timeout) do
6
6
  Thread.pass until block.call
7
7
  end
8
8
  rescue => e
@@ -10,7 +10,7 @@ module CellectHelper
10
10
  raise e
11
11
  end
12
12
 
13
- def pass_until_state_of(obj, is:)
13
+ def pass_until_state_of(obj, timeout: 1, is:)
14
14
  Timeout::timeout(1) do
15
15
  Thread.pass until obj.state == is
16
16
  end
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: 1.3.3
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: guard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: zk-server
70
+ name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rack-test
84
+ name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: rack-test
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,21 +109,21 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: celluloid
112
+ name: pry
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.16.0
118
- type: :runtime
117
+ version: '0'
118
+ type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.16.0
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: celluloid-io
126
+ name: celluloid
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
@@ -151,19 +151,19 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'
153
153
  - !ruby/object:Gem::Dependency
154
- name: zk
154
+ name: attention
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.9'
159
+ version: 0.0.4
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.9'
166
+ version: 0.0.4
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: multi_json
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -181,7 +181,9 @@ dependencies:
181
181
  description: ''
182
182
  email:
183
183
  - michael@zooniverse.org
184
- executables: []
184
+ executables:
185
+ - console
186
+ - setup
185
187
  extensions: []
186
188
  extra_rdoc_files: []
187
189
  files:
@@ -189,9 +191,12 @@ files:
189
191
  - ".rspec"
190
192
  - ".travis.yml"
191
193
  - Gemfile
194
+ - Guardfile
192
195
  - LICENSE
193
196
  - README.md
194
197
  - Rakefile
198
+ - bin/console
199
+ - bin/setup
195
200
  - cellect-client.gemspec
196
201
  - cellect.gemspec
197
202
  - data/.gitkeep
@@ -199,12 +204,10 @@ files:
199
204
  - lib/cellect/client.rb
200
205
  - lib/cellect/client/connection.rb
201
206
  - lib/cellect/client/node_set.rb
202
- - lib/cellect/node_set.rb
203
- - lib/cellect/testing.rb
204
207
  - lib/cellect/version.rb
205
208
  - log/.gitkeep
206
- - spec/client/connection_spec.rb
207
- - spec/client/node_set_spec.rb
209
+ - spec/cellect/client/connection_spec.rb
210
+ - spec/cellect/client/node_set_spec.rb
208
211
  - spec/fixtures/user_data/complete_user.json
209
212
  - spec/fixtures/user_data/new_user.json
210
213
  - spec/fixtures/user_data/partial_user.json
@@ -219,11 +222,9 @@ files:
219
222
  - spec/spec_helper.rb
220
223
  - spec/support/cellect_helper.rb
221
224
  - spec/support/shared_api_context.rb
222
- - spec/support/shared_examples_for_node_set.rb
223
225
  - spec/support/shared_examples_for_set.rb
224
226
  - spec/support/shared_examples_for_workflow.rb
225
227
  - spec/support/spec_adapter.rb
226
- - spec/support/zk_setup.rb
227
228
  - tmp/.gitkeep
228
229
  homepage: https://github.com/parrish/Cellect
229
230
  licenses:
@@ -240,9 +241,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
241
  version: '0'
241
242
  required_rubygems_version: !ruby/object:Gem::Requirement
242
243
  requirements:
243
- - - ">="
244
+ - - ">"
244
245
  - !ruby/object:Gem::Version
245
- version: '0'
246
+ version: 1.3.1
246
247
  requirements: []
247
248
  rubyforge_project:
248
249
  rubygems_version: 2.4.2
@@ -250,8 +251,8 @@ signing_key:
250
251
  specification_version: 4
251
252
  summary: ''
252
253
  test_files:
253
- - spec/client/connection_spec.rb
254
- - spec/client/node_set_spec.rb
254
+ - spec/cellect/client/connection_spec.rb
255
+ - spec/cellect/client/node_set_spec.rb
255
256
  - spec/fixtures/user_data/complete_user.json
256
257
  - spec/fixtures/user_data/new_user.json
257
258
  - spec/fixtures/user_data/partial_user.json
@@ -266,8 +267,6 @@ test_files:
266
267
  - spec/spec_helper.rb
267
268
  - spec/support/cellect_helper.rb
268
269
  - spec/support/shared_api_context.rb
269
- - spec/support/shared_examples_for_node_set.rb
270
270
  - spec/support/shared_examples_for_set.rb
271
271
  - spec/support/shared_examples_for_workflow.rb
272
272
  - spec/support/spec_adapter.rb
273
- - spec/support/zk_setup.rb
@@ -1,44 +0,0 @@
1
- require 'zk'
2
-
3
- module Cellect
4
- class NodeSet
5
- include Celluloid
6
- ConnectionError = Class.new(StandardError)
7
-
8
- attr_accessor :zk, :state
9
-
10
- # Sets up the node set and starts connecting to ZooKeeper
11
- def initialize(zk_url = nil)
12
- @zk_url = zk_url
13
- self.state = :initializing
14
- after(0.001){ async.initialize_zk } # don't block waiting for ZK to connect
15
- end
16
-
17
- # Connect to ZooKeeper, setup this node, and change state
18
- def initialize_zk
19
- Timeout::timeout(timeout_duration) do
20
- self.zk = ZK.new zk_url, chroot: '/cellect'
21
- end
22
- setup
23
- self.state = :ready
24
- end
25
-
26
- def ready?
27
- state == :ready
28
- end
29
-
30
- protected
31
-
32
- def timeout_duration
33
- ENV.fetch('ZK_TIMEOUT', 5).to_i
34
- end
35
-
36
- def zk_url
37
- @zk_url || ENV.fetch('ZK_URL', 'localhost:2181')
38
- end
39
-
40
- def setup
41
- # Specialized in subclasses
42
- end
43
- end
44
- end
@@ -1,7 +0,0 @@
1
- module Cellect
2
- module Client
3
- def self.mock_zookeeper?
4
- true
5
- end
6
- end
7
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Cellect::Client
4
- describe NodeSet do
5
- it_behaves_like 'node set'
6
- let(:node_set){ Cellect::Client.node_set }
7
-
8
- #@note: node_set.nodes has state from intial code loading
9
- # the above def which is really a cached celluloid actor from boot
10
- # see Cellect::Client / Cellect::Server
11
- it 'should update the node list when changing' do
12
- begin
13
- pass_until_state_of node_set, is: :ready
14
- node_set.zk.create '/nodes/node', data: 'foo', mode: :ephemeral_sequential
15
- 100.times do |i|
16
- break if node_set.nodes['node0000000001']
17
- Thread.pass
18
- end
19
- expect(node_set.nodes['node0000000001']).to eq 'foo'
20
- ensure
21
- node_set.zk.delete '/nodes/node0000000001'
22
- end
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- shared_examples_for 'node set' do
2
- let(:node_set){ Cellect::NodeSet.new }
3
-
4
- it 'should connect to zoo keeper' do
5
- expect(node_set.zk).to be_nil
6
- pass_until_state_of node_set, is: :ready
7
- expect(node_set.zk).to be_connected
8
- end
9
-
10
- it 'should know the connection state' do
11
- expect(node_set.state).to be :initializing
12
- pass_until_state_of node_set, is: :ready
13
- expect(node_set).to be_ready
14
- end
15
-
16
- it 'should accept a connection string' do
17
- url_before = ENV['ZK_URL']
18
- begin
19
- pass_until_state_of node_set, is: :ready
20
- ENV['ZK_URL'] = 'foobar'
21
- expect(node_set.send(:zk_url)).to eq 'foobar'
22
- ENV.delete 'ZK_URL'
23
- expect(node_set.send(:zk_url)).to eq 'localhost:2181'
24
- ensure
25
- ENV['ZK_URL'] = url_before
26
- end
27
- end
28
- end
@@ -1,51 +0,0 @@
1
- module ZK_Setup
2
- def self.start_zk(port=21811)
3
- @port = port
4
- if SPAWN_ZK
5
- kill_old_zk_servers
6
- remove_zk_data
7
- server = ZK::Server.new do |config|
8
- config.client_port = port
9
- config.client_port_address = 'localhost'
10
- config.force_sync = false
11
- config.tick_time = 2000
12
- config.init_limit = 10
13
- config.sync_limit = 5
14
- config.snap_count = 1000000
15
- config.base_dir = zk_dir
16
- end
17
- server.run
18
- @zk_server = server
19
- ENV['ZK_URL'] = "localhost:#{port}"
20
- end
21
- end
22
-
23
- def self.stop_zk
24
- if SPAWN_ZK
25
- @zk_server.shutdown
26
- end
27
- end
28
-
29
- def self.zk_dir
30
- File.join CELLECT_ROOT, 'tmp/zookeeper'
31
- end
32
-
33
- def self.zk_ok?
34
- `echo ruok | nc 127.0.0.1 #{@port}`.chomp == 'imok'
35
- end
36
-
37
- def self.kill_old_zk_servers
38
- if zk_ok?
39
- pid = `ps aux | grep -e 'Cellect[\/]tmp[\/]zookeeper'`.split[1]
40
- puts "Killing rogue zookeeper process: #{ pid }..."
41
- `kill -s TERM #{ pid }`
42
- sleep 1
43
- end
44
- end
45
-
46
- def self.remove_zk_data
47
- `rm -rf #{ zk_dir }; mkdir -p #{ zk_dir }`
48
- end
49
- end
50
-
51
- ZK_Setup.start_zk