cellect-server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +2 -0
  5. data/README.md +19 -0
  6. data/Rakefile +9 -0
  7. data/cellect-server.gemspec +40 -0
  8. data/cellect.gemspec +33 -0
  9. data/lib/cellect.rb +7 -0
  10. data/lib/cellect/node_set.rb +38 -0
  11. data/lib/cellect/server.rb +30 -0
  12. data/lib/cellect/server/adapters.rb +13 -0
  13. data/lib/cellect/server/adapters/default.rb +60 -0
  14. data/lib/cellect/server/adapters/postgres.rb +64 -0
  15. data/lib/cellect/server/api.rb +48 -0
  16. data/lib/cellect/server/api/helpers.rb +44 -0
  17. data/lib/cellect/server/api/sets.rb +21 -0
  18. data/lib/cellect/server/api/users.rb +32 -0
  19. data/lib/cellect/server/grouped_project.rb +65 -0
  20. data/lib/cellect/server/node_set.rb +19 -0
  21. data/lib/cellect/server/project.rb +123 -0
  22. data/lib/cellect/server/user.rb +66 -0
  23. data/lib/cellect/version.rb +3 -0
  24. data/spec/fixtures/project_data/grouped_pairwise_priority.json +109 -0
  25. data/spec/fixtures/project_data/grouped_pairwise_random.json +89 -0
  26. data/spec/fixtures/project_data/grouped_priority.json +59 -0
  27. data/spec/fixtures/project_data/grouped_random.json +49 -0
  28. data/spec/fixtures/project_data/pairwise_priority.json +49 -0
  29. data/spec/fixtures/project_data/pairwise_random.json +39 -0
  30. data/spec/fixtures/project_data/priority.json +49 -0
  31. data/spec/fixtures/project_data/random.json +39 -0
  32. data/spec/fixtures/user_data/complete_user.json +118 -0
  33. data/spec/fixtures/user_data/new_user.json +26 -0
  34. data/spec/fixtures/user_data/partial_user.json +58 -0
  35. data/spec/server/api/add_seen_spec.rb +26 -0
  36. data/spec/server/api/add_spec.rb +40 -0
  37. data/spec/server/api/remove_spec.rb +35 -0
  38. data/spec/server/api/sample_spec.rb +34 -0
  39. data/spec/server/api/user_load_spec.rb +25 -0
  40. data/spec/server/grouped_project_spec.rb +76 -0
  41. data/spec/server/node_set_spec.rb +13 -0
  42. data/spec/server/project_spec.rb +62 -0
  43. data/spec/server/server_spec.rb +24 -0
  44. data/spec/server/user_spec.rb +32 -0
  45. data/spec/spec_helper.rb +43 -0
  46. data/spec/support/cellect_helper.rb +12 -0
  47. data/spec/support/shared_api_context.rb +11 -0
  48. data/spec/support/shared_examples_for_node_set.rb +27 -0
  49. data/spec/support/shared_examples_for_project.rb +26 -0
  50. data/spec/support/shared_examples_for_set.rb +34 -0
  51. data/spec/support/spec_adapter.rb +43 -0
  52. data/spec/support/zk_setup.rb +26 -0
  53. metadata +337 -0
@@ -0,0 +1,43 @@
1
+ CELLECT_ROOT = File.expand_path File.join(File.dirname(__FILE__), '../')
2
+
3
+ %w(lib ext).each do |name|
4
+ dir = File.join CELLECT_ROOT, name
5
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include? dir
6
+ end
7
+
8
+ Bundler.require :test, :development
9
+
10
+ ENV['CELLECT_POOL_SIZE'] = '3'
11
+
12
+ require 'pry'
13
+ require 'oj'
14
+ require './spec/support/zk_setup.rb'
15
+ require 'cellect/server'
16
+ require 'cellect/client'
17
+ require 'celluloid/rspec'
18
+ require 'rack/test'
19
+ Celluloid.shutdown_timeout = 1
20
+ Celluloid.logger = nil
21
+
22
+ Dir["./spec/support/**/*.rb"].sort.each{ |f| require f }
23
+
24
+ Cellect::Server.adapter = SpecAdapter.new
25
+ SET_TYPES = %w(random priority pairwise_random pairwise_priority)
26
+
27
+ RSpec.configure do |config|
28
+ config.treat_symbols_as_metadata_keys_with_true_values = true
29
+ config.run_all_when_everything_filtered = true
30
+ config.filter_run :focus
31
+ config.order = 'random'
32
+ config.include CellectHelper
33
+
34
+ config.around(:each) do |example|
35
+ Celluloid.boot
36
+ example.run
37
+ Celluloid.shutdown
38
+ end
39
+
40
+ config.after(:suite) do
41
+ `zkServer stop #{ CELLECT_ZK_CONFIG } > /dev/null 2>&1`
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ require 'timeout'
2
+
3
+ module CellectHelper
4
+ def pass_until(obj, is: is)
5
+ Timeout::timeout(1) do
6
+ Thread.pass until obj.state == is
7
+ end
8
+ rescue => e
9
+ puts "Timeout waiting for #{ obj.inspect } to be #{ is }"
10
+ raise e
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ shared_context 'API' do
2
+ include Rack::Test::Methods
3
+
4
+ def app
5
+ $app ||= Cellect::Server::API.new
6
+ end
7
+
8
+ def json
9
+ Oj.strict_load last_response.body
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ shared_examples_for 'node set' do
2
+ let(:node_set){ Cellect::NodeSet.new }
3
+
4
+ it 'should connect to zoo keeper' do
5
+ node_set.zk.should be_nil
6
+ pass_until node_set, is: :ready
7
+ node_set.zk.should be_connected
8
+ end
9
+
10
+ it 'should know the connection state' do
11
+ node_set.state.should be :initializing
12
+ pass_until node_set, is: :ready
13
+ node_set.should be_ready
14
+ end
15
+
16
+ it 'should accept a connection string' do
17
+ begin
18
+ pass_until node_set, is: :ready
19
+ ENV['ZK_URL'] = 'foobar'
20
+ node_set.send(:zk_url).should == 'foobar'
21
+ ENV.delete 'ZK_URL'
22
+ node_set.send(:zk_url).should == 'localhost:2181'
23
+ ensure
24
+ ENV['ZK_URL'] = 'localhost:21811'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ shared_examples_for 'project' do |name|
2
+ let(:obj){ send name }
3
+
4
+ before(:each) do
5
+ Cellect::Server.adapter.load_project obj.name
6
+ end
7
+
8
+ it 'should add singleton instances to the registry' do
9
+ obj.class[:foo].should be_a_kind_of Cellect::Server::Project
10
+ obj.class[:foo].object_id.should == obj.class[:foo].object_id
11
+ end
12
+
13
+ it 'should initialize empty' do
14
+ obj.name.should be_a String
15
+ obj.users.should be_a Hash
16
+
17
+ set_klass = obj.prioritized? ? DiffSet::PrioritySet : DiffSet::RandomSet
18
+ obj.subjects.should be_a set_klass
19
+ end
20
+
21
+ it 'should provide a user lookup' do
22
+ obj.user(1).should be_a Cellect::Server::User
23
+ obj.user(1).object_id.should == obj.user(1).object_id
24
+ obj.users.keys.should include 1
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ shared_examples_for 'a set' do
2
+ it 'should convert to an Array' do
3
+ set.to_a.should =~ (1..5).to_a
4
+ end
5
+
6
+ it 'should add elements' do
7
+ set.add 100
8
+ set.to_a.should include 100
9
+ end
10
+
11
+ it 'should remove elements' do
12
+ set.remove 1
13
+ set.to_a.should_not include 1
14
+ end
15
+
16
+ it 'should sample elements' do
17
+ set.sample(2).length.should == 2
18
+ end
19
+
20
+ it 'should not include removed elements in samples' do
21
+ set.remove 5
22
+ set.sample(5).should_not include 5
23
+ end
24
+
25
+ it 'should know how many elements it contains' do
26
+ expect{ set.add 100 }.to change{ set.size }.from(5).to 6
27
+ end
28
+
29
+ it 'should know if it contains an element' do
30
+ set.should_not include 100
31
+ set.add 100
32
+ set.should include 100
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'oj'
2
+
3
+ class SpecAdapter < Cellect::Server::Adapters::Default
4
+ def project_list
5
+ fixtures.values
6
+ end
7
+
8
+ def load_data_for(project_name)
9
+ fixtures.fetch(project_name, { }).fetch 'entries', []
10
+ end
11
+
12
+ def fixtures
13
+ @fixtures ||= { }.tap do |fixtures|
14
+ Dir["#{ _fixture_path }/project_data/*.json"].collect do |f|
15
+ name = File.basename(f).sub /\.json$/, ''
16
+ data = Oj.strict_load File.read f
17
+ fixtures[name] = data
18
+ end
19
+ end
20
+ end
21
+
22
+ def user_fixtures
23
+ @user_fixtures ||= { }.tap do |user_fixtures|
24
+ Dir["#{ _fixture_path }/user_data/*.json"].sort.collect.with_index do |f, i|
25
+ name = File.basename(f).sub /\.json$/, ''
26
+ data = Oj.strict_load File.read f
27
+ user_fixtures[name] = data
28
+ user_fixtures[i + 1] = data
29
+ end
30
+ end
31
+ end
32
+
33
+ def load_user(project_name, id)
34
+ user = user_fixtures[id]
35
+ user ? user[project_name] : user_fixtures['new_user'][project_name]
36
+ end
37
+
38
+ protected
39
+
40
+ def _fixture_path
41
+ File.expand_path File.join(__FILE__, '../../fixtures')
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ zk_dir = File.join CELLECT_ROOT, 'tmp/zookeeper'
2
+
3
+ `rm -rf #{ zk_dir }; mkdir -p #{ zk_dir }`
4
+
5
+ CELLECT_ZK_CONFIG = "#{ zk_dir }/zoo.cfg"
6
+ File.open(CELLECT_ZK_CONFIG, 'w') do |out|
7
+ out.puts <<-TEXT
8
+ tickTime=2000
9
+ initLimit=10
10
+ syncLimit=5
11
+ dataDir=#{ zk_dir }
12
+ clientPort=21811
13
+ forceSync=no
14
+ snapCount=1000000
15
+ TEXT
16
+ 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 ADDED
@@ -0,0 +1,337 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cellect-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Parrish
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: connection_pool
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: diff_set
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: celluloid
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 0.16.0.pre
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 0.16.0.pre
167
+ - !ruby/object:Gem::Dependency
168
+ name: celluloid-io
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '='
172
+ - !ruby/object:Gem::Version
173
+ version: 0.16.0.pre
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '='
179
+ - !ruby/object:Gem::Version
180
+ version: 0.16.0.pre
181
+ - !ruby/object:Gem::Dependency
182
+ name: http
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.6'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.6'
195
+ - !ruby/object:Gem::Dependency
196
+ name: zk
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '1.9'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.9'
209
+ - !ruby/object:Gem::Dependency
210
+ name: grape
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.7'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.7'
223
+ description: ''
224
+ email:
225
+ - michael@zooniverse.org
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - ".gitignore"
231
+ - ".rspec"
232
+ - Gemfile
233
+ - README.md
234
+ - Rakefile
235
+ - cellect-server.gemspec
236
+ - cellect.gemspec
237
+ - data/.gitkeep
238
+ - lib/cellect.rb
239
+ - lib/cellect/node_set.rb
240
+ - lib/cellect/server.rb
241
+ - lib/cellect/server/adapters.rb
242
+ - lib/cellect/server/adapters/default.rb
243
+ - lib/cellect/server/adapters/postgres.rb
244
+ - lib/cellect/server/api.rb
245
+ - lib/cellect/server/api/helpers.rb
246
+ - lib/cellect/server/api/sets.rb
247
+ - lib/cellect/server/api/users.rb
248
+ - lib/cellect/server/grouped_project.rb
249
+ - lib/cellect/server/node_set.rb
250
+ - lib/cellect/server/project.rb
251
+ - lib/cellect/server/user.rb
252
+ - lib/cellect/version.rb
253
+ - log/.gitkeep
254
+ - spec/fixtures/project_data/grouped_pairwise_priority.json
255
+ - spec/fixtures/project_data/grouped_pairwise_random.json
256
+ - spec/fixtures/project_data/grouped_priority.json
257
+ - spec/fixtures/project_data/grouped_random.json
258
+ - spec/fixtures/project_data/pairwise_priority.json
259
+ - spec/fixtures/project_data/pairwise_random.json
260
+ - spec/fixtures/project_data/priority.json
261
+ - spec/fixtures/project_data/random.json
262
+ - spec/fixtures/user_data/complete_user.json
263
+ - spec/fixtures/user_data/new_user.json
264
+ - spec/fixtures/user_data/partial_user.json
265
+ - spec/server/api/add_seen_spec.rb
266
+ - spec/server/api/add_spec.rb
267
+ - spec/server/api/remove_spec.rb
268
+ - spec/server/api/sample_spec.rb
269
+ - spec/server/api/user_load_spec.rb
270
+ - spec/server/grouped_project_spec.rb
271
+ - spec/server/node_set_spec.rb
272
+ - spec/server/project_spec.rb
273
+ - spec/server/server_spec.rb
274
+ - spec/server/user_spec.rb
275
+ - spec/spec_helper.rb
276
+ - spec/support/cellect_helper.rb
277
+ - spec/support/shared_api_context.rb
278
+ - spec/support/shared_examples_for_node_set.rb
279
+ - spec/support/shared_examples_for_project.rb
280
+ - spec/support/shared_examples_for_set.rb
281
+ - spec/support/spec_adapter.rb
282
+ - spec/support/zk_setup.rb
283
+ - tmp/.gitkeep
284
+ homepage: https://github.com/parrish/Cellect
285
+ licenses:
286
+ - MIT
287
+ metadata: {}
288
+ post_install_message:
289
+ rdoc_options: []
290
+ require_paths:
291
+ - lib
292
+ required_ruby_version: !ruby/object:Gem::Requirement
293
+ requirements:
294
+ - - ">="
295
+ - !ruby/object:Gem::Version
296
+ version: '0'
297
+ required_rubygems_version: !ruby/object:Gem::Requirement
298
+ requirements:
299
+ - - ">="
300
+ - !ruby/object:Gem::Version
301
+ version: '0'
302
+ requirements: []
303
+ rubyforge_project:
304
+ rubygems_version: 2.2.2
305
+ signing_key:
306
+ specification_version: 4
307
+ summary: ''
308
+ test_files:
309
+ - spec/fixtures/project_data/grouped_pairwise_priority.json
310
+ - spec/fixtures/project_data/grouped_pairwise_random.json
311
+ - spec/fixtures/project_data/grouped_priority.json
312
+ - spec/fixtures/project_data/grouped_random.json
313
+ - spec/fixtures/project_data/pairwise_priority.json
314
+ - spec/fixtures/project_data/pairwise_random.json
315
+ - spec/fixtures/project_data/priority.json
316
+ - spec/fixtures/project_data/random.json
317
+ - spec/fixtures/user_data/complete_user.json
318
+ - spec/fixtures/user_data/new_user.json
319
+ - spec/fixtures/user_data/partial_user.json
320
+ - spec/server/api/add_seen_spec.rb
321
+ - spec/server/api/add_spec.rb
322
+ - spec/server/api/remove_spec.rb
323
+ - spec/server/api/sample_spec.rb
324
+ - spec/server/api/user_load_spec.rb
325
+ - spec/server/grouped_project_spec.rb
326
+ - spec/server/node_set_spec.rb
327
+ - spec/server/project_spec.rb
328
+ - spec/server/server_spec.rb
329
+ - spec/server/user_spec.rb
330
+ - spec/spec_helper.rb
331
+ - spec/support/cellect_helper.rb
332
+ - spec/support/shared_api_context.rb
333
+ - spec/support/shared_examples_for_node_set.rb
334
+ - spec/support/shared_examples_for_project.rb
335
+ - spec/support/shared_examples_for_set.rb
336
+ - spec/support/spec_adapter.rb
337
+ - spec/support/zk_setup.rb