tupelo 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,28 +56,16 @@ class TestOps < Minitest::Test
56
56
  client.update; assert_equal [1], reader.resume
57
57
  end
58
58
 
59
- def test_two_clients
60
- t = ["c0"]
61
- cl = make_clients(2)
62
-
63
- cl[0].write t
64
-
65
- cl.each do |c|
66
- reader = Fiber.new { c.read [nil] }; reader.resume
67
- c.update; assert_equal t, reader.resume
68
- end
69
- end
70
-
71
59
  def test_read_existing
72
60
  t = ["foo"]
73
61
  cl = make_clients(2)
74
62
 
75
- wr = cl[0].write t
76
- cl[0].update; assert_equal 1, wr.global_tick
77
-
63
+ w = cl[0].now {write t}
64
+ assert_equal 1, w.global_tick
65
+
78
66
  cl.each do |c|
79
- reader = Fiber.new { c.read [nil] }; reader.resume
80
- c.update; assert_equal t, reader.resume
67
+ c.will {read [nil]}
68
+ assert_equal t, c.run
81
69
  end
82
70
  end
83
71
 
@@ -85,15 +73,16 @@ class TestOps < Minitest::Test
85
73
  t = ["bar"]
86
74
  cl = make_clients(2)
87
75
 
88
- reader = Fiber.new { cl[1].read [nil] }; reader.resume
76
+ cl[1].will {read [nil]}.run_until_blocked
77
+
78
+ w = cl[0].now {write t}
79
+ assert_equal 1, w.global_tick
89
80
 
90
- wr = cl[0].write t
91
- cl[0].update; assert_equal 1, wr.global_tick
92
- cl[1].update; assert_equal t, reader.resume
81
+ assert_equal t, cl[1].run
93
82
 
94
83
  cl.each do |c|
95
- reader = Fiber.new { c.read [nil] }; reader.resume
96
- c.update; assert_equal t, reader.resume
84
+ c.will {read [nil]}
85
+ assert_equal t, c.run
97
86
  end
98
87
  end
99
88
 
@@ -101,97 +90,99 @@ class TestOps < Minitest::Test
101
90
  t = ["foo"]
102
91
  cl = make_clients(2)
103
92
 
104
- wr = cl[0].write t
105
- cl[0].update; assert_equal 1, wr.global_tick
93
+ w = cl[0].now {write t}
94
+ assert_equal 1, w.global_tick
106
95
 
107
- taker = Fiber.new { cl[1].take [nil] }; taker.resume
108
- cl[1].update; taker.resume
109
- cl[1].update; assert_equal t, taker.resume
110
- cl[0].update
96
+ cl[1].will {take [nil]}
97
+ assert_equal t, cl[1].run
111
98
 
112
99
  cl.each do |c|
113
- reader = Fiber.new { c.read_all [nil] }; reader.resume
114
- c.update; assert_empty reader.resume
100
+ c.will {read_all [nil]}
101
+ assert_empty c.run
115
102
  end
116
103
  end
117
104
 
118
105
  def test_take_waiting
119
106
  t = ["bar"]
120
- cl = make_clients(2)
107
+ taker, writer = make_clients(2)
108
+
109
+ taker.will {take [nil]}.run_until_blocked
121
110
 
122
- taker = Fiber.new { cl[1].take [nil] }; taker.resume
123
- cl[1].update; taker.resume
124
- cl[1].update; assert_equal :block, taker.resume
111
+ w = writer.now {write t}
112
+ assert_equal 1, w.global_tick
125
113
 
126
- wr = cl[0].write t
127
- cl[0].update; assert_equal 1, wr.global_tick
128
- cl[1].update; taker.resume
129
- cl[1].update; assert_equal t, taker.resume
130
- cl[0].update
114
+ assert_equal t, taker.run
131
115
 
132
- cl.each do |c|
133
- reader = Fiber.new { c.read_all [nil] }; reader.resume
134
- c.update; assert_empty reader.resume
116
+ [taker, writer].each do |c|
117
+ c.will {read_all [nil]}
118
+ assert_empty c.run
135
119
  end
136
120
  end
137
121
 
138
122
  def test_transaction_existing
139
- w = [1]; t = [2]
140
- cl = make_clients(2)
123
+ r = [0]; w = [1]; t = [2]
124
+ writer, transactor = make_clients(2)
141
125
 
142
- wr = cl[0].write t
143
- cl[0].update; assert_equal 1, wr.global_tick
126
+ w_op = writer.now {write r, t}
127
+ assert_equal 1, w_op.global_tick
144
128
 
145
- trans = Fiber.new do
146
- cl[1].transaction do |tr|
147
- tr.write w
148
- tr.take t
129
+ transactor.will do
130
+ transaction do
131
+ write w
132
+ [read(r), take(t)]
149
133
  end
150
134
  end
151
- trans.resume
152
135
 
153
- cl[1].update; trans.resume
154
- cl[1].update; assert_equal t, trans.resume
155
- cl[0].update
136
+ assert_equal [r, t], transactor.run
156
137
 
157
- cl.each do |c|
158
- reader = Fiber.new { c.read_all [nil] }; reader.resume
159
- c.update; assert_equal [w], reader.resume
138
+ [writer, transactor].each do |c|
139
+ c.will {read_all [nil]}
140
+ assert_equal [r, w], c.run
160
141
  end
161
142
  end
162
143
 
163
144
  def test_transaction_waiting
164
- w = [1]; t = [2]
165
- cl = make_clients(2)
145
+ r = [0]; w = [1]; t = [2]
146
+ writer, transactor = make_clients(2)
166
147
 
167
- trans = Fiber.new do
168
- cl[1].transaction do |tr|
169
- tr.write w
170
- tr.take t
148
+ transactor.will do
149
+ transaction do
150
+ write w
151
+ [read(r), take(t)]
171
152
  end
172
153
  end
173
- trans.resume
154
+ transactor.run_until_blocked
174
155
 
175
- wr = cl[0].write t
176
- cl[0].update; assert_equal 1, wr.global_tick
156
+ w_op = writer.now {write r, t}
157
+ assert_equal 1, w_op.global_tick
177
158
 
178
- cl[1].update; trans.resume
179
- cl[1].update; assert_equal t, trans.resume
180
- cl[0].update
159
+ assert_equal [r, t], transactor.run
181
160
 
182
- cl.each do |c|
183
- reader = Fiber.new { c.read_all [nil] }; reader.resume
184
- c.update; assert_equal [w], reader.resume
161
+ [writer, transactor].each do |c|
162
+ c.will {read_all [nil]}
163
+ assert_equal [r, w], c.run
185
164
  end
186
165
  end
187
166
 
167
+ def test_transaction_empty
168
+ transactor = make_client(0)
169
+
170
+ transactor.will do
171
+ transaction do
172
+ end
173
+ end
174
+
175
+ assert_equal nil, transactor.run
176
+ assert_equal 0, transactor.worker.global_tick
177
+ end
178
+
188
179
  def test_transaction_cancel
189
180
  w = [1]; t = [2]
190
- cl = make_clients(2)
181
+ writer, transactor = make_clients(2)
191
182
 
192
183
  tr = nil
193
- trans = Fiber.new do
194
- tr = cl[1].transaction
184
+ transactor.will do
185
+ tr = transaction
195
186
  tr.write w
196
187
  begin
197
188
  tr.take t
@@ -200,23 +191,66 @@ class TestOps < Minitest::Test
200
191
  Fiber.yield :abort
201
192
  end
202
193
  end
203
- cl[1].update; assert_equal :block, trans.resume
204
-
194
+ assert_equal :block, transactor.step
205
195
  tr.cancel
206
- cl[1].update; assert_equal :abort, trans.resume
196
+ assert_equal :abort, transactor.step
207
197
 
208
- wr = cl[0].write t
209
- cl[0].update; assert_equal 1, wr.global_tick
210
- cl[1].update
198
+ w_op = writer.now {write t}
199
+ assert_equal 1, w_op.global_tick
211
200
 
212
- cl.each do |c|
213
- reader = Fiber.new { c.read_all [nil] }; reader.resume
214
- c.update; assert_equal [t], reader.resume
201
+ [writer, transactor].each do |c|
202
+ c.will {read_all [nil]}
203
+ assert_equal [t], c.run
204
+ end
205
+ end
206
+
207
+ def test_transaction_fail_retry
208
+ winner, loser = make_clients(2)
209
+ winner.now {write ["token", 1]}
210
+
211
+ run_count = 0
212
+ result = nil
213
+ loser.will do
214
+ result = transaction do
215
+ run_count += 1
216
+ a = []
217
+ write ["test", 1]
218
+ a << (take ["token", 1])
219
+ write ["test", 2]
220
+ a << (take ["token", 2])
221
+ write ["test", 3]
222
+ a
223
+ end
224
+ end
225
+ loser.run_until_blocked
226
+ assert_equal 1, run_count
227
+
228
+ winner.will do
229
+ take ["token", 1]
215
230
  end
231
+ winner.run
232
+ loser.run_until_blocked
233
+
234
+ assert_equal 2, run_count
235
+ assert_empty winner.now {read_all [nil, nil]}
236
+
237
+ winner.now {write ["token", 2]}
238
+ assert_raises(MockClient::IsBlocked) {loser.run}
239
+
240
+ winner.now {write ["token", 1]}
241
+ assert_equal [["token", 1], ["token", 2]], loser.run
242
+
243
+ result = winner.now {read_all [nil, nil]}
244
+ assert_equal [["test", 1], ["test", 2], ["test", 3]], result
216
245
  end
217
246
 
218
- ## test Transaction#read
219
- ## test failure
220
- ## test pulse
221
- ## test optimistic
247
+ def test_pulse
248
+ t = ["c0"]
249
+ reader, pulser = make_clients(2)
250
+
251
+ reader.will {read [nil]}.run_until_blocked
252
+ pulser.now {pulse t}
253
+ assert_equal t, reader.run
254
+ assert_empty reader.now {read_all [nil]}
255
+ end
222
256
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tupelo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel VanderWerf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-31 00:00:00.000000000 Z
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: atdo
@@ -89,9 +89,15 @@ files:
89
89
  - lib/tupelo/client/common.rb
90
90
  - lib/tupelo/client/tuplespace.rb
91
91
  - lib/tupelo/client/transaction.rb
92
+ - lib/tupelo/client/atdo.rb
92
93
  - lib/tupelo/client/reader.rb
94
+ - lib/tupelo/tuplets/persistent-archiver/worker.rb
95
+ - lib/tupelo/tuplets/persistent-archiver/tuplespace.rb
96
+ - lib/tupelo/tuplets/persistent-archiver.rb
97
+ - lib/tupelo/archiver/persister.rb
93
98
  - lib/tupelo/archiver/worker.rb
94
99
  - lib/tupelo/archiver/tuplespace.rb
100
+ - lib/tupelo/archiver/persistent-tuplespace.rb
95
101
  - lib/tupelo/util/boolean.rb
96
102
  - lib/tupelo/version.rb
97
103
  - bench/pipeline.rb
@@ -106,6 +112,7 @@ files:
106
112
  - example/small.rb
107
113
  - example/bounded-retry.rb
108
114
  - example/map-reduce-v2.rb
115
+ - example/zk/lock.rb
109
116
  - example/concurrent-transactions.rb
110
117
  - example/cancel.rb
111
118
  - example/tiny-server.rb
@@ -120,6 +127,7 @@ files:
120
127
  - example/transaction-logic.rb
121
128
  - example/remote-map-reduce.rb
122
129
  - example/map-reduce.rb
130
+ - example/lease.rb
123
131
  - example/balance-xfer.rb
124
132
  - example/add-dsl.rb
125
133
  - example/lock-mgr.rb
@@ -134,6 +142,7 @@ files:
134
142
  - example/message-bus.rb
135
143
  - example/balance-xfer-locking.rb
136
144
  - example/increment.rb
145
+ - example/child-of-child.rb
137
146
  - example/custom-class.rb
138
147
  - example/matching.rb
139
148
  - example/custom-search.rb
@@ -145,6 +154,7 @@ files:
145
154
  - example/boolean-match.rb
146
155
  - example/load-balancer.rb
147
156
  - example/take-many.rb
157
+ - example/deadlock.rb
148
158
  - example/dphil.rb
149
159
  - test/lib/testable-worker.rb
150
160
  - test/lib/mock-seq.rb
@@ -154,6 +164,7 @@ files:
154
164
  - test/lib/mock-client.rb
155
165
  - test/system/test-archiver.rb
156
166
  - test/unit/test-ops.rb
167
+ - test/unit/test-mock-client.rb
157
168
  - test/unit/test-mock-seq.rb
158
169
  - test/unit/test-mock-queue.rb
159
170
  - test/stress/concurrent-transactions.rb
@@ -187,12 +198,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
198
  version: '0'
188
199
  requirements: []
189
200
  rubyforge_project:
190
- rubygems_version: 2.0.4
201
+ rubygems_version: 2.1.3
191
202
  signing_key:
192
203
  specification_version: 4
193
204
  summary: Distributed tuplespace
194
205
  test_files:
195
206
  - test/unit/test-ops.rb
207
+ - test/unit/test-mock-client.rb
196
208
  - test/unit/test-mock-seq.rb
197
209
  - test/unit/test-mock-queue.rb
198
210
  has_rdoc: