dp_stm_map 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +622 -0
  5. data/README.md +115 -0
  6. data/Rakefile +1 -0
  7. data/bin/dp_map_manager.rb +47 -0
  8. data/cucumber.yml +2 -0
  9. data/dp_stm_map.gemspec +29 -0
  10. data/features/client_reconnect.feature +13 -0
  11. data/features/persistence.feature +12 -0
  12. data/features/replication.feature +9 -0
  13. data/features/running_manager.feature +19 -0
  14. data/features/step_definitions/client_reconnect_steps.rb +28 -0
  15. data/features/step_definitions/persistence_steps.rb +49 -0
  16. data/features/step_definitions/replication_steps.rb +15 -0
  17. data/features/step_definitions/running_server_steps.rb +10 -0
  18. data/features/step_definitions/transaction_fail_steps.rb +11 -0
  19. data/features/support/env.rb +80 -0
  20. data/features/transaction_fail.feature +7 -0
  21. data/lib/dp_stm_map/Client.rb +268 -0
  22. data/lib/dp_stm_map/ClientLocalStore.rb +119 -0
  23. data/lib/dp_stm_map/InMemoryStmMap.rb +147 -0
  24. data/lib/dp_stm_map/Manager.rb +370 -0
  25. data/lib/dp_stm_map/Message.rb +126 -0
  26. data/lib/dp_stm_map/ObjectStore.rb +99 -0
  27. data/lib/dp_stm_map/version.rb +16 -0
  28. data/lib/dp_stm_map.rb +20 -0
  29. data/server.profile +547 -0
  30. data/spec/dp_stm_map/ClientLocalStore_spec.rb +78 -0
  31. data/spec/dp_stm_map/Client_spec.rb +133 -0
  32. data/spec/dp_stm_map/InMemoryStmMap_spec.rb +10 -0
  33. data/spec/dp_stm_map/Manager_spec.rb +323 -0
  34. data/spec/dp_stm_map/Message_spec.rb +21 -0
  35. data/spec/dp_stm_map/ObjectStore_spec.rb +87 -0
  36. data/spec/dp_stm_map/StmMap_shared.rb +432 -0
  37. metadata +235 -0
@@ -0,0 +1,432 @@
1
+ require 'dp_stm_map'
2
+ require 'timeout'
3
+
4
+ # RSpec.configure do |c|
5
+ # c.around(:each) do |example|
6
+ # Timeout::timeout(2) {
7
+ # example.run
8
+ # }
9
+ # end
10
+ # end
11
+
12
+ module DpStmMap
13
+
14
+ shared_examples_for "StmMap" do
15
+
16
+
17
+ describe :on_atomic do
18
+ it "should be executed after commiting atomic changes" do
19
+ executed=false
20
+ subject.on_atomic do |changes|
21
+ executed=true
22
+
23
+ end
24
+ subject.atomic do |map|
25
+ map['x']='y'
26
+ end
27
+ executed.should be true
28
+ end
29
+
30
+
31
+ context "when listener raises an error" do
32
+ it "should still commit atomic changes" do
33
+ subject.on_atomic do
34
+ raise "listener failed"
35
+ end
36
+ subject.atomic do |map|
37
+ map['x']='y'
38
+ end
39
+
40
+ subject.atomic_read do |map|
41
+ map['x'].should == 'y'
42
+ end
43
+ end
44
+ it "should execute all listeners" do
45
+ executed=false
46
+ subject.on_atomic do
47
+ raise "listener failed"
48
+ end
49
+ subject.on_atomic do |changes|
50
+ executed=true
51
+ end
52
+ subject.atomic do |map|
53
+ map['x']='y'
54
+ end
55
+ executed.should be true
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+ describe :validate_atomic do
62
+ it "should be executed before commiting atomic changes" do
63
+ executed=false
64
+ subject.validate_atomic do |changes|
65
+ executed=true
66
+ end
67
+ subject.atomic do |map|
68
+ map['x']='y'
69
+ end
70
+ executed.should be true
71
+ end
72
+
73
+ it "should roll back transaction when validator raises exception" do
74
+ subject.validate_atomic do |changes|
75
+ raise "validation error"
76
+ end
77
+
78
+ expect do
79
+ subject.atomic do |map|
80
+ map['x']='y'
81
+ end
82
+ end.to raise_error "validation error"
83
+
84
+ subject.atomic_read do |map|
85
+ map.should_not have_key 'x'
86
+ end
87
+
88
+ end
89
+
90
+
91
+ it "should contain changes of creation of new value" do
92
+ subject.validate_atomic do |changes|
93
+ changes.should == {'x' => [nil,'y']}
94
+ end
95
+ subject.atomic do |map|
96
+ map['x']='y'
97
+ end
98
+ end
99
+
100
+ it "should contain change to new value" do
101
+ subject.atomic do |map|
102
+ map['x']='y'
103
+ end
104
+ subject.validate_atomic do |changes|
105
+ changes.should == {'x' => ['y','z']}
106
+ end
107
+ subject.atomic do |map|
108
+ map['x']='z'
109
+ end
110
+ end
111
+
112
+ it "should contain deleting existing value" do
113
+ subject.atomic do |map|
114
+ map['x']='y'
115
+ end
116
+ subject.validate_atomic do |changes|
117
+ changes.should == {'x' => ['y',nil]}
118
+ end
119
+ subject.atomic do |map|
120
+ map.delete 'x'
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+
127
+ describe :atomic_read do
128
+ it "should return evaluation result" do
129
+ subject.atomic_read{ |map| "test"}.should == 'test'
130
+ end
131
+
132
+ it "should propagate raised error" do
133
+ expect{subject.atomic_read{|map| raise "some error"}}.to raise_error "some error"
134
+ end
135
+
136
+ describe :[] do
137
+ it "should return nil for unset key" do
138
+ subject.atomic_read do |map|
139
+ map['x'].should == nil
140
+ end
141
+ end
142
+
143
+ it "should return value for set key" do
144
+ subject.atomic do |map|
145
+ map['x']='y'
146
+ end
147
+ subject.atomic_read do |map|
148
+ map['x'].should == 'y'
149
+ end
150
+ end
151
+
152
+ it "should not create new key when looking up unset key" do
153
+ subject.atomic_read do |map|
154
+ map['x']
155
+ map.should_not have_key 'x'
156
+ end
157
+ end
158
+
159
+ end
160
+
161
+
162
+ describe :has_key? do
163
+ context "when value is previosly set" do
164
+ before do
165
+ subject.atomic do |map|
166
+ map['x']='y'
167
+ end
168
+ end
169
+ it "should return true" do
170
+ subject.atomic_read do |map|
171
+ map.has_key?('x').should be_true
172
+ end
173
+ end
174
+ end
175
+
176
+ context "when value is not set" do
177
+ it "should return true" do
178
+ subject.atomic_read do |map|
179
+ map.has_key?('x').should be_false
180
+ end
181
+ end
182
+ end
183
+
184
+ end
185
+ end
186
+
187
+ describe :atomic do
188
+
189
+ it "should return evaluation result" do
190
+ subject.atomic{ |map| "test"}.should == 'test'
191
+ end
192
+
193
+ it "should roll back changes when error is raised" do
194
+ expect{subject.atomic{|map| map['x'] = 'y'; raise "some error"}}.to raise_error "some error"
195
+ subject.atomic do |map|
196
+ map.should_not have_key('x')
197
+ end
198
+ end
199
+
200
+ describe :has_key? do
201
+ context "when value is previosly set" do
202
+ before do
203
+ subject.atomic do |map|
204
+ map['x']='y'
205
+ end
206
+ end
207
+ it "should return true" do
208
+ subject.atomic do |map|
209
+ map.has_key?('x').should be_true
210
+ end
211
+ end
212
+ end
213
+
214
+ context "when value is not set" do
215
+ it "should return true" do
216
+ subject.atomic do |map|
217
+ map.has_key?('x').should be_false
218
+ end
219
+ end
220
+ end
221
+
222
+ context "when value is set within transaction" do
223
+ it "should return true" do
224
+ subject.atomic do |map|
225
+ map['x']='y'
226
+ map.has_key?('x').should be_true
227
+ end
228
+ end
229
+ end
230
+
231
+ context "when value has been deleted within the transaction" do
232
+ before do
233
+ subject.atomic do |map|
234
+ map['x']='y'
235
+ end
236
+ end
237
+ it "should return false" do
238
+ subject.atomic do |map|
239
+ map.delete 'x'
240
+ map.has_key?('x').should be_false
241
+ end
242
+ end
243
+ end
244
+
245
+
246
+ end
247
+
248
+
249
+
250
+ describe :delete do
251
+
252
+ context "when value does not exist" do
253
+ it "should make no difference" do
254
+ subject.atomic do |map|
255
+ map.delete 'x'
256
+ map.has_key?('x').should be_false
257
+ end
258
+ end
259
+ end
260
+
261
+ context "when value exists in the global context" do
262
+ before do
263
+ subject.atomic do |map|
264
+ map['x']='y'
265
+ end
266
+ end
267
+ it "should delete value for the same transaction scope" do
268
+ subject.atomic do |map|
269
+ map.delete 'x'
270
+ map.has_key?('x').should be_false
271
+ end
272
+ end
273
+ it "should delete value for the next transaction scope" do
274
+ subject.atomic do |map|
275
+ map.delete 'x'
276
+ end
277
+ subject.atomic do |map|
278
+ map.has_key?('x').should be_false
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ describe :[]= do
285
+ it "should store new value" do
286
+ subject.atomic do |map|
287
+ map['x']='y'
288
+ end
289
+ subject.atomic_read do |map|
290
+ map['x'].should == 'y'
291
+ end
292
+ end
293
+
294
+ it "should change existing value" do
295
+ subject.atomic do |map|
296
+ map['x']='y'
297
+ end
298
+ subject.atomic do |map|
299
+ map['x']='z'
300
+ end
301
+ subject.atomic_read do |map|
302
+ map['x'].should == 'z'
303
+ end
304
+ end
305
+
306
+ context "when new value is nil" do
307
+ before do
308
+ subject.atomic {|map| map['x']='y'}
309
+ end
310
+
311
+ it "should delete the key in the same transaction scope" do
312
+ subject.atomic do |map|
313
+ map['x']=nil
314
+ map.should_not have_key 'x'
315
+ end
316
+ end
317
+
318
+ it "should delete the key in the global scope after transaction" do
319
+ subject.atomic do |map|
320
+ map['x']=nil
321
+ end
322
+ subject.atomic do |map|
323
+ map.should_not have_key 'x'
324
+ end
325
+ end
326
+
327
+ end
328
+
329
+
330
+ context "when value has been previosly deleted in the same transaction scope" do
331
+ it "should store the new value visible within the transaction scope" do
332
+ subject.atomic do |map|
333
+ map['x'] = 'y'
334
+ map.delete 'x'
335
+ map['x'] = 'z'
336
+ map['x'].should == 'z'
337
+ end
338
+ end
339
+
340
+ it "should store the new value visible within scope of next transaction" do
341
+ subject.atomic do |map|
342
+ map['x'] = 'y'
343
+ map.delete 'x'
344
+ map['x'] = 'z'
345
+ end
346
+ subject.atomic do |map|
347
+ map['x'].should == 'z'
348
+ end
349
+ end
350
+ end
351
+
352
+
353
+ end
354
+
355
+ describe :[] do
356
+
357
+
358
+ it "should record reading values" do
359
+ subject.atomic do |map|
360
+ map['x']='y'
361
+ end
362
+
363
+ subject.validate_atomic do |changes|
364
+ changes.should == {'x' => ['y','y']}
365
+ end
366
+
367
+ subject.atomic do |map|
368
+ map['x']
369
+ end
370
+
371
+ end
372
+
373
+ it "should record changing values" do
374
+ subject.atomic do |map|
375
+ map['x']='y'
376
+ end
377
+
378
+ subject.validate_atomic do |changes|
379
+ changes.should == {'x' => ['y','z']}
380
+ end
381
+
382
+ subject.atomic do |map|
383
+ map['x']='z'
384
+ end
385
+
386
+ end
387
+
388
+ it "should return nil for unset key" do
389
+ subject.atomic do |map|
390
+ map['x'].should == nil
391
+ end
392
+ end
393
+
394
+ it "should not create new key when looking up unset key" do
395
+ subject.atomic do |map|
396
+ map['x']
397
+ map.should_not have_key 'x'
398
+ end
399
+ end
400
+
401
+ context "when value is not set in local atomic context" do
402
+ before do
403
+ subject.atomic do |map|
404
+ map['x']='y'
405
+ end
406
+ end
407
+ it "should return value from global state" do
408
+ subject.atomic do |map|
409
+ map['x'].should == 'y'
410
+ end
411
+ end
412
+ end
413
+
414
+ context "when value is set in local atomic context" do
415
+ it "should return value from the local state" do
416
+ subject.atomic do |map|
417
+ map['x']= 'z'
418
+ map['x'].should == 'z'
419
+ end
420
+ end
421
+ end
422
+
423
+
424
+ end
425
+
426
+ end
427
+
428
+
429
+
430
+ end
431
+
432
+ end
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dp_stm_map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dragan Milic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: autotest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: aruba
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: threadsafe-lru
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: xray
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: distributed and persistent software transaction memory map
143
+ email:
144
+ - dragan@netice9.com
145
+ executables:
146
+ - dp_map_manager.rb
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .rspec
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/dp_map_manager.rb
157
+ - cucumber.yml
158
+ - dp_stm_map.gemspec
159
+ - features/client_reconnect.feature
160
+ - features/persistence.feature
161
+ - features/replication.feature
162
+ - features/running_manager.feature
163
+ - features/step_definitions/client_reconnect_steps.rb
164
+ - features/step_definitions/persistence_steps.rb
165
+ - features/step_definitions/replication_steps.rb
166
+ - features/step_definitions/running_server_steps.rb
167
+ - features/step_definitions/transaction_fail_steps.rb
168
+ - features/support/env.rb
169
+ - features/transaction_fail.feature
170
+ - lib/dp_stm_map.rb
171
+ - lib/dp_stm_map/Client.rb
172
+ - lib/dp_stm_map/ClientLocalStore.rb
173
+ - lib/dp_stm_map/InMemoryStmMap.rb
174
+ - lib/dp_stm_map/Manager.rb
175
+ - lib/dp_stm_map/Message.rb
176
+ - lib/dp_stm_map/ObjectStore.rb
177
+ - lib/dp_stm_map/version.rb
178
+ - server.profile
179
+ - spec/dp_stm_map/ClientLocalStore_spec.rb
180
+ - spec/dp_stm_map/Client_spec.rb
181
+ - spec/dp_stm_map/InMemoryStmMap_spec.rb
182
+ - spec/dp_stm_map/Manager_spec.rb
183
+ - spec/dp_stm_map/Message_spec.rb
184
+ - spec/dp_stm_map/ObjectStore_spec.rb
185
+ - spec/dp_stm_map/StmMap_shared.rb
186
+ homepage: ''
187
+ licenses:
188
+ - GPLv3
189
+ post_install_message:
190
+ rdoc_options: []
191
+ require_paths:
192
+ - lib
193
+ required_ruby_version: !ruby/object:Gem::Requirement
194
+ none: false
195
+ requirements:
196
+ - - ! '>='
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ segments:
200
+ - 0
201
+ hash: 1329683666885119216
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
209
+ - 0
210
+ hash: 1329683666885119216
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 1.8.25
214
+ signing_key:
215
+ specification_version: 3
216
+ summary: distributed and persistent software transaction memory map
217
+ test_files:
218
+ - features/client_reconnect.feature
219
+ - features/persistence.feature
220
+ - features/replication.feature
221
+ - features/running_manager.feature
222
+ - features/step_definitions/client_reconnect_steps.rb
223
+ - features/step_definitions/persistence_steps.rb
224
+ - features/step_definitions/replication_steps.rb
225
+ - features/step_definitions/running_server_steps.rb
226
+ - features/step_definitions/transaction_fail_steps.rb
227
+ - features/support/env.rb
228
+ - features/transaction_fail.feature
229
+ - spec/dp_stm_map/ClientLocalStore_spec.rb
230
+ - spec/dp_stm_map/Client_spec.rb
231
+ - spec/dp_stm_map/InMemoryStmMap_spec.rb
232
+ - spec/dp_stm_map/Manager_spec.rb
233
+ - spec/dp_stm_map/Message_spec.rb
234
+ - spec/dp_stm_map/ObjectStore_spec.rb
235
+ - spec/dp_stm_map/StmMap_shared.rb