scalaroid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,375 @@
1
+ require_relative "test_helper"
2
+
3
+ class TestTransactionSingleOp < Minitest::Test
4
+ def setup
5
+ @testTime = (Time.now.to_f * 1000).to_i
6
+ end
7
+
8
+ # Test method for TransactionSingleOp()
9
+ def test_transaction_single_op1()
10
+ conn = Scalaroid::TransactionSingleOp.new()
11
+ conn.close_connection()
12
+ end
13
+
14
+ # Test method for TransactionSingleOp(conn)
15
+ def test_transaction_single_op2()
16
+ conn = Scalaroid::TransactionSingleOp.new(conn = Scalaroid::JSONConnection.new(url = Scalaroid::DEFAULT_URL))
17
+ conn.close_connection()
18
+ end
19
+
20
+ # Test method for TransactionSingleOp.close_connection() trying to close the connection twice.
21
+ def test_double_close()
22
+ conn = Scalaroid::TransactionSingleOp.new()
23
+ conn.close_connection()
24
+ conn.close_connection()
25
+ end
26
+
27
+ # Test method for TransactionSingleOp.read(key)
28
+ def test_read_NotFound()
29
+ key = "_Read_NotFound"
30
+ conn = Scalaroid::TransactionSingleOp.new()
31
+ assert_raises( Scalaroid::NotFoundError ) { conn.read(@testTime.to_s + key) }
32
+ conn.close_connection()
33
+ end
34
+
35
+ # Test method for TransactionSingleOp.read(key) with a closed connection.
36
+ def test_read_not_connected()
37
+ key = "_Read_NotConnected"
38
+ conn = Scalaroid::TransactionSingleOp.new()
39
+ conn.close_connection()
40
+ #assert_raises( Scalaroid::ConnectionError ) { conn.read(@testTime.to_s + key) }
41
+ assert_raises( Scalaroid::NotFoundError ) { conn.read(@testTime.to_s + key) }
42
+ conn.close_connection()
43
+ end
44
+
45
+ # Test method for TransactionSingleOp.write(key, value=str()) with a closed connection.
46
+ def test_write_string_not_connected()
47
+ key = "_WriteString_NotConnected"
48
+ conn = Scalaroid::TransactionSingleOp.new()
49
+ conn.close_connection()
50
+ #assert_raises( Scalaroid::ConnectionError ) { conn.write(@testTime.to_s + key, $_TEST_DATA[0]) }
51
+ conn.write(@testTime.to_s + key, $_TEST_DATA[0])
52
+ conn.close_connection()
53
+ end
54
+
55
+ # Test method for TransactionSingleOp.write(key, value=str()) and TransactionSingleOp.read(key).
56
+ # Writes strings and uses a distinct key for each value. Tries to read the data afterwards.
57
+ def test_write_string1()
58
+ key = "_WriteString1_"
59
+ conn = Scalaroid::TransactionSingleOp.new()
60
+
61
+ (0..($_TEST_DATA.length - 1)).each do |i|
62
+ conn.write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
63
+ end
64
+
65
+ # now try to read the data:
66
+ (0..($_TEST_DATA.length - 1)).each do |i|
67
+ actual = conn.read(@testTime.to_s + key + i.to_s)
68
+ assert_equal($_TEST_DATA[i], actual)
69
+ end
70
+
71
+ conn.close_connection()
72
+ end
73
+
74
+ # Test method for TransactionSingleOp.write(key, value=str()) and TransactionSingleOp.read(key).
75
+ # Writes strings and uses a single key for all the values. Tries to read the data afterwards.
76
+ def test_write_string2()
77
+ key = "_WriteString2"
78
+ conn = Scalaroid::TransactionSingleOp.new()
79
+
80
+ (0..($_TEST_DATA.length - 1)).each do |i|
81
+ conn.write(@testTime.to_s + key.to_s, $_TEST_DATA[i])
82
+ end
83
+
84
+ # now try to read the data:
85
+ actual = conn.read(@testTime.to_s + key.to_s)
86
+ assert_equal($_TEST_DATA[$_TEST_DATA.length - 1], actual)
87
+ conn.close_connection()
88
+ end
89
+
90
+ # Test method for TransactionSingleOp.write(key, value=list()) with a closed connection.
91
+ def test_write_list_not_connected()
92
+ key = "_WriteList_NotConnected"
93
+ conn = Scalaroid::TransactionSingleOp.new()
94
+ conn.close_connection()
95
+ #assert_raises( Scalaroid::ConnectionError ) { conn.write(@testTime.to_s + key, [$_TEST_DATA[0], $_TEST_DATA[1]]) }
96
+ conn.write(@testTime.to_s + key, [$_TEST_DATA[0], $_TEST_DATA[1]])
97
+ conn.close_connection()
98
+ end
99
+
100
+ # Test method for TransactionSingleOp.write(key, value=list()) and TransactionSingleOp.read(key).
101
+ # Writes strings and uses a distinct key for each value. Tries to read the data afterwards.
102
+ def test_write_list1()
103
+ key = "_WriteList1_"
104
+ conn = Scalaroid::TransactionSingleOp.new()
105
+
106
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
107
+ conn.write(@testTime.to_s + key + i.to_s, [$_TEST_DATA[i], $_TEST_DATA[i + 1]])
108
+ end
109
+
110
+ # now try to read the data:
111
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
112
+ actual = conn.read(@testTime.to_s + key + i.to_s)
113
+ assert_equal([$_TEST_DATA[i], $_TEST_DATA[i + 1]], actual)
114
+ end
115
+
116
+ conn.close_connection()
117
+ end
118
+
119
+ # Test method for TransactionSingleOp.write(key, value=list()) and TransactionSingleOp.read(key).
120
+ # Writes strings and uses a single key for all the values. Tries to read the data afterwards.
121
+ def test_write_list2()
122
+ key = "_WriteList2"
123
+ conn = Scalaroid::TransactionSingleOp.new()
124
+
125
+ list = []
126
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
127
+ list = [$_TEST_DATA[i], $_TEST_DATA[i + 1]]
128
+ conn.write(@testTime.to_s + key, list)
129
+ end
130
+
131
+ # now try to read the data:
132
+ actual = conn.read(@testTime.to_s + key)
133
+ assert_equal(list, actual)
134
+ conn.close_connection()
135
+ end
136
+
137
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=str()) with a closed connection.
138
+ def test_test_and_set_string_not_connected()
139
+ key = "_TestAndSetString_NotConnected"
140
+ conn = Scalaroid::TransactionSingleOp.new()
141
+ conn.close_connection()
142
+ #assert_raises( Scalaroid::ConnectionError ) { conn.test_and_set(@testTime.to_s + key, $_TEST_DATA[0], $_TEST_DATA[1]) }
143
+ assert_raises( Scalaroid::NotFoundError ) { conn.test_and_set(@testTime.to_s + key, $_TEST_DATA[0], $_TEST_DATA[1]) }
144
+ conn.close_connection()
145
+ end
146
+
147
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=str()).
148
+ # Tries test_and_set with a non-existing key.
149
+ def test_test_and_set_string_not_found()
150
+ key = "_TestAndSetString_NotFound"
151
+ conn = Scalaroid::TransactionSingleOp.new()
152
+ assert_raises( Scalaroid::NotFoundError ) { conn.test_and_set(@testTime.to_s + key, $_TEST_DATA[0], $_TEST_DATA[1]) }
153
+ conn.close_connection()
154
+ end
155
+
156
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=str()),
157
+ # TransactionSingleOp.read(key) and TransactionSingleOp.write(key, value=str()).
158
+ # Writes a string and tries to overwrite it using test_and_set
159
+ # knowing the correct old value. Tries to read the string afterwards.
160
+ def test_test_and_set_string1()
161
+ key = "_TestAndSetString1"
162
+ conn = Scalaroid::TransactionSingleOp.new()
163
+
164
+ # first write all values:
165
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
166
+ conn.write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
167
+ end
168
+
169
+ # now try to overwrite them using test_and_set:
170
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
171
+ conn.test_and_set(@testTime.to_s + key + i.to_s, $_TEST_DATA[i], $_TEST_DATA[i + 1])
172
+ end
173
+
174
+ # now try to read the data:
175
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
176
+ actual = conn.read(@testTime.to_s + key + i.to_s)
177
+ assert_equal($_TEST_DATA[i + 1], actual)
178
+ end
179
+
180
+ conn.close_connection()
181
+ end
182
+
183
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=str()),
184
+ # TransactionSingleOp.read(key) and TransactionSingleOp.write(key, value=str()).
185
+ # Writes a string and tries to overwrite it using test_and_set
186
+ # knowing the wrong old value. Tries to read the string afterwards.
187
+ def test_test_and_set_string2()
188
+ key = "_TestAndSetString2"
189
+ conn = Scalaroid::TransactionSingleOp.new()
190
+
191
+ # first write all values:
192
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
193
+ conn.write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
194
+ end
195
+
196
+ # now try to overwrite them using test_and_set:
197
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
198
+ begin
199
+ conn.test_and_set(@testTime.to_s + key + i.to_s, $_TEST_DATA[i + 1], "fail")
200
+ assert(false, 'expected a KeyChangedError')
201
+ rescue Scalaroid::KeyChangedError => exception
202
+ assert_equal($_TEST_DATA[i], exception.old_value)
203
+ end
204
+ end
205
+
206
+ # now try to read the data:
207
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
208
+ actual = conn.read(@testTime.to_s + key + i.to_s)
209
+ assert_equal($_TEST_DATA[i], actual)
210
+ end
211
+
212
+ conn.close_connection()
213
+ end
214
+
215
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=list()) with a closed connection.
216
+ def test_test_and_set_list_not_connected()
217
+ key = "_TestAndSetList_NotConnected"
218
+ conn = Scalaroid::TransactionSingleOp.new()
219
+ conn.close_connection()
220
+ #assert_raises( Scalaroid::ConnectionError ) { conn.test_and_set(@testTime.to_s + key, "fail", [$_TEST_DATA[0], $_TEST_DATA[1]]) }
221
+ assert_raises( Scalaroid::NotFoundError ) { conn.test_and_set(@testTime.to_s + key, "fail", [$_TEST_DATA[0], $_TEST_DATA[1]]) }
222
+ conn.close_connection()
223
+ end
224
+
225
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=list()).
226
+ # Tries test_and_set with a non-existing key.
227
+ def test_test_and_set_list_not_found()
228
+ key = "_TestAndSetList_NotFound"
229
+ conn = Scalaroid::TransactionSingleOp.new()
230
+ assert_raises( Scalaroid::NotFoundError ) { conn.test_and_set(@testTime.to_s + key, "fail", [$_TEST_DATA[0], $_TEST_DATA[1]]) }
231
+ conn.close_connection()
232
+ end
233
+
234
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=list()),
235
+ # TransactionSingleOp.read(key) and TransactionSingleOp.write(key, value=list()).
236
+ # Writes a list and tries to overwrite it using test_and_set
237
+ # knowing the correct old value. Tries to read the string afterwards.
238
+ def test_test_and_set_list1()
239
+ key = "_TestAndSetList1"
240
+ conn = Scalaroid::TransactionSingleOp.new()
241
+
242
+ # first write all values:
243
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
244
+ conn.write(@testTime.to_s + key + i.to_s, [$_TEST_DATA[i], $_TEST_DATA[i + 1]])
245
+ end
246
+
247
+ # now try to overwrite them using test_and_set:
248
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
249
+ conn.test_and_set(@testTime.to_s + key + i.to_s, [$_TEST_DATA[i], $_TEST_DATA[i + 1]], [$_TEST_DATA[i + 1], $_TEST_DATA[i]])
250
+ end
251
+
252
+ # now try to read the data:
253
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
254
+ actual = conn.read(@testTime.to_s + key + i.to_s)
255
+ assert_equal([$_TEST_DATA[i + 1], $_TEST_DATA[i]], actual)
256
+ end
257
+
258
+ conn.close_connection()
259
+ end
260
+
261
+ # Test method for TransactionSingleOp.test_and_set(key, oldvalue=str(), newvalue=list()),
262
+ # TransactionSingleOp.read(key) and TransactionSingleOp.write(key, value=list()).
263
+ # Writes a string and tries to overwrite it using test_and_set
264
+ # knowing the wrong old value. Tries to read the string afterwards.
265
+ def test_test_and_set_list2()
266
+ key = "_TestAndSetList2"
267
+ conn = Scalaroid::TransactionSingleOp.new()
268
+
269
+ # first write all values:
270
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
271
+ conn.write(@testTime.to_s + key + i.to_s, [$_TEST_DATA[i], $_TEST_DATA[i + 1]])
272
+ end
273
+
274
+ # now try to overwrite them using test_and_set:
275
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
276
+ begin
277
+ conn.test_and_set(@testTime.to_s + key + i.to_s, "fail", 1)
278
+ assert(false, 'expected a KeyChangedError')
279
+ rescue Scalaroid::KeyChangedError => exception
280
+ assert_equal([$_TEST_DATA[i], $_TEST_DATA[i + 1]], exception.old_value)
281
+ end
282
+ end
283
+
284
+ # now try to read the data:
285
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
286
+ actual = conn.read(@testTime.to_s + key + i.to_s)
287
+ assert_equal([$_TEST_DATA[i], $_TEST_DATA[i + 1]], actual)
288
+ end
289
+
290
+ conn.close_connection()
291
+ end
292
+
293
+ # Test method for TransactionSingleOp.req_list(RequestList) with an
294
+ # empty request list.
295
+ def test_req_list_empty()
296
+ conn = Scalaroid::TransactionSingleOp.new()
297
+ conn.req_list(conn.new_req_list())
298
+ conn.close_connection()
299
+ end
300
+
301
+ # Test method for TransactionSingleOp.req_list(RequestList) with a
302
+ # mixed request list.
303
+ def test_req_list1()
304
+ key = "_ReqList1_"
305
+ conn = Scalaroid::TransactionSingleOp.new()
306
+
307
+ readRequests = conn.new_req_list()
308
+ firstWriteRequests = conn.new_req_list()
309
+ writeRequests = conn.new_req_list()
310
+ (0..($_TEST_DATA.length - 1)).each do |i|
311
+ if (i % 2) == 0
312
+ firstWriteRequests.add_write(@testTime.to_s + key + i.to_s, "first_" + $_TEST_DATA[i])
313
+ end
314
+ writeRequests.add_write(@testTime.to_s + key + i.to_s, "second_" + $_TEST_DATA[i])
315
+ readRequests.add_read(@testTime.to_s + key + i.to_s)
316
+ end
317
+
318
+ results = conn.req_list(firstWriteRequests)
319
+ # evaluate the first write results:
320
+ (0..(firstWriteRequests.size() - 1)).step(2) do |i|
321
+ conn.process_result_write(results[i])
322
+ end
323
+
324
+ results = conn.req_list(readRequests)
325
+ assert_equal(readRequests.size(), results.length)
326
+ # now evaluate the read results:
327
+ (0..(readRequests.size() - 1)).step(2) do |i|
328
+ if (i % 2) == 0
329
+ actual = conn.process_result_read(results[i])
330
+ assert_equal("first_" + $_TEST_DATA[i], actual)
331
+ else
332
+ begin
333
+ conn.process_result_read(results[i])
334
+ # a not found exception must be thrown
335
+ assert(false, 'expected a NotFoundError')
336
+ rescue Scalaroid::NotFoundError
337
+ end
338
+ end
339
+ end
340
+
341
+ results = conn.req_list(writeRequests)
342
+ assert_equal(writeRequests.size(), results.length)
343
+ # now evaluate the write results:
344
+ (0..(writeRequests.size() - 1)).step(2) do |i|
345
+ conn.process_result_write(results[i])
346
+ end
347
+
348
+ # once again test reads - now all reads should be successful
349
+ results = conn.req_list(readRequests)
350
+ assert_equal(readRequests.size(), results.length)
351
+
352
+ # now evaluate the read results:
353
+ (0..(readRequests.size() - 1)).step(2) do |i|
354
+ actual = conn.process_result_read(results[i])
355
+ assert_equal("second_" + $_TEST_DATA[i], actual)
356
+ end
357
+
358
+ conn.close_connection();
359
+ end
360
+
361
+ # Test method for TransactionSingleOp.write(key, value=bytearray()) with a
362
+ # request that is too large.
363
+ def test_req_too_large()
364
+ conn = Scalaroid::TransactionSingleOp.new()
365
+ data = (0..($_TOO_LARGE_REQUEST_SIZE)).map{0}.join()
366
+ key = "_ReqTooLarge"
367
+ begin
368
+ conn.write(@testTime.to_s + key, data)
369
+ assert(false, 'The write should have failed unless yaws_max_post_data was set larger than ' + $_TOO_LARGE_REQUEST_SIZE.to_s())
370
+ rescue Scalaroid::ConnectionError
371
+ end
372
+
373
+ conn.close_connection()
374
+ end
375
+ end
@@ -0,0 +1,267 @@
1
+ require_relative "test_helper"
2
+
3
+ class TestTransaction < Minitest::Test
4
+ def setup
5
+ @testTime = (Time.now.to_f * 1000).to_i
6
+ end
7
+
8
+ # Test method for Transaction()
9
+ def test_transaction1()
10
+ t = Scalaroid::Transaction.new()
11
+ t.close_connection()
12
+ end
13
+
14
+ # Test method for Transaction(conn)
15
+ def test_transaction3()
16
+ t = Scalaroid::Transaction.new(conn = Scalaroid::JSONConnection.new(url = Scalaroid::DEFAULT_URL))
17
+ t.close_connection()
18
+ end
19
+
20
+ # Test method for Transaction.close_connection() trying to close the connection twice.
21
+ def test_double_close()
22
+ t = Scalaroid::Transaction.new()
23
+ t.close_connection()
24
+ t.close_connection()
25
+ end
26
+
27
+ # Test method for Transaction.commit() with a closed connection.
28
+ def test_commit_not_connected()
29
+ t = Scalaroid::Transaction.new()
30
+ t.close_connection()
31
+ #assert_raises( Scalaroid::ConnectionError ) { t.commit() }
32
+ t.commit()
33
+ t.close_connection()
34
+ end
35
+
36
+ # Test method for Transaction.commit() which commits an empty transaction.
37
+ def test_commit_empty()
38
+ t = Scalaroid::Transaction.new()
39
+ t.commit()
40
+ t.close_connection()
41
+ end
42
+
43
+ # Test method for Transaction.abort() with a closed connection.
44
+ def test_abort_not_connected()
45
+ t = Scalaroid::Transaction.new()
46
+ t.close_connection()
47
+ #assert_raises( Scalaroid::ConnectionError ) { t.abort() }
48
+ t.abort()
49
+ t.close_connection()
50
+ end
51
+
52
+ # Test method for Transaction.abort() which aborts an empty transaction.
53
+ def test_abort_empty()
54
+ t = Scalaroid::Transaction.new()
55
+ t.abort()
56
+ t.close_connection()
57
+ end
58
+
59
+ # Test method for Transaction.read(key)
60
+ def test_read_not_found()
61
+ key = "_Read_NotFound"
62
+ t = Scalaroid::Transaction.new()
63
+ assert_raises( Scalaroid::NotFoundError ) { t.read(@testTime.to_s + key) }
64
+ t.close_connection()
65
+ end
66
+
67
+ # Test method for Transaction.read(key) with a closed connection.
68
+ def test_read_not_connected()
69
+ key = "_Read_NotConnected"
70
+ t = Scalaroid::Transaction.new()
71
+ t.close_connection()
72
+ #assert_raises( Scalaroid::ConnectionError ) { t.read(@testTime.to_s + key) }
73
+ assert_raises( Scalaroid::NotFoundError ) { t.read(@testTime.to_s + key) }
74
+ t.close_connection()
75
+ end
76
+
77
+ # Test method for Transaction.write(key, value=str()) with a closed connection.
78
+ def test_write_string_not_connected()
79
+ key = "_WriteString_NotConnected"
80
+ t = Scalaroid::Transaction.new()
81
+ t.close_connection()
82
+ #assert_raises( Scalaroid::ConnectionError ) { t.write(@testTime.to_s + key, $_TEST_DATA[0]) }
83
+ t.write(@testTime.to_s + key, $_TEST_DATA[0])
84
+ t.close_connection()
85
+ end
86
+
87
+ # Test method for Transaction.read(key) and Transaction.write(key, value=str())
88
+ # which should show that writing a value for a key for which a previous read
89
+ # returned a NotFoundError is possible.
90
+ def test_write_string_not_found()
91
+ key = "_WriteString_notFound"
92
+ t = Scalaroid::Transaction.new()
93
+ notFound = false
94
+ begin
95
+ t.read(@testTime.to_s + key)
96
+ rescue Scalaroid::NotFoundError
97
+ notFound = true
98
+ end
99
+
100
+ assert(notFound)
101
+ t.write(@testTime.to_s + key, $_TEST_DATA[0])
102
+ assert_equal($_TEST_DATA[0], t.read(@testTime.to_s + key))
103
+ t.close_connection()
104
+ end
105
+
106
+ # Test method for Transaction.write(key, value=str()) and Transaction.read(key).
107
+ # Writes strings and uses a distinct key for each value. Tries to read the data afterwards.
108
+ def test_write_string()
109
+ key = "_testWriteString1_"
110
+ t = Scalaroid::Transaction.new()
111
+
112
+ (0..($_TEST_DATA.length - 1)).each do |i|
113
+ t.write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
114
+ end
115
+
116
+ # now try to read the data:
117
+ (0..($_TEST_DATA.length - 1)).each do |i|
118
+ actual = t.read(@testTime.to_s + key + i.to_s)
119
+ assert_equal($_TEST_DATA[i], actual)
120
+ end
121
+
122
+ # commit the transaction and try to read the data with a new one:
123
+ t.commit()
124
+ t = Scalaroid::Transaction.new()
125
+ (0..($_TEST_DATA.length - 1)).each do |i|
126
+ actual = t.read(@testTime.to_s + key + i.to_s)
127
+ assert_equal($_TEST_DATA[i], actual)
128
+ end
129
+
130
+ t.close_connection()
131
+ end
132
+
133
+ # Test method for Transaction.write(key, value=list()) and Transaction.read(key).
134
+ # Writes a list and uses a distinct key for each value. Tries to read the data afterwards.
135
+ def test_write_list1()
136
+ key = "_testWriteList1_"
137
+ t = Scalaroid::Transaction.new()
138
+
139
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
140
+ t.write(@testTime.to_s + key + i.to_s, [$_TEST_DATA[i], $_TEST_DATA[i + 1]])
141
+ end
142
+
143
+ # now try to read the data:
144
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
145
+ actual = t.read(@testTime.to_s + key + i.to_s)
146
+ assert_equal([$_TEST_DATA[i], $_TEST_DATA[i + 1]], actual)
147
+ end
148
+
149
+ t.close_connection()
150
+
151
+ # commit the transaction and try to read the data with a new one:
152
+ t.commit()
153
+ t = Scalaroid::Transaction.new()
154
+ (0..($_TEST_DATA.length - 2)).step(2) do |i|
155
+ actual = t.read(@testTime.to_s + key + i.to_s)
156
+ assert_equal([$_TEST_DATA[i], $_TEST_DATA[i + 1]], actual)
157
+ end
158
+
159
+ t.close_connection()
160
+ end
161
+
162
+ # Test method for Transaction.req_list(RequestList) with an
163
+ # empty request list.
164
+ def test_req_list_empty()
165
+ conn = Scalaroid::Transaction.new()
166
+ conn.req_list(conn.new_req_list())
167
+ conn.close_connection()
168
+ end
169
+
170
+ # Test method for Transaction.req_list(RequestList) with a
171
+ # mixed request list.
172
+ def test_req_list1()
173
+ key = "_ReqList1_"
174
+ conn = Scalaroid::Transaction.new()
175
+
176
+ readRequests = conn.new_req_list()
177
+ firstWriteRequests = conn.new_req_list()
178
+ writeRequests = conn.new_req_list()
179
+ (0..($_TEST_DATA.length - 1)).each do |i|
180
+ if (i % 2) == 0
181
+ firstWriteRequests.add_write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
182
+ end
183
+ writeRequests.add_write(@testTime.to_s + key + i.to_s, $_TEST_DATA[i])
184
+ readRequests.add_read(@testTime.to_s + key + i.to_s)
185
+ end
186
+
187
+ results = conn.req_list(firstWriteRequests)
188
+ # evaluate the first write results:
189
+ (0..(firstWriteRequests.size() - 1)).each do |i|
190
+ conn.process_result_write(results[i])
191
+ end
192
+
193
+ requests = conn.new_req_list(readRequests).concat(writeRequests).add_commit()
194
+ results = conn.req_list(requests)
195
+ assert_equal(requests.size(), results.length)
196
+
197
+ # now evaluate the read results:
198
+ (0..(readRequests.size() - 1)).each do |i|
199
+ if (i % 2) == 0
200
+ actual = conn.process_result_read(results[i])
201
+ assert_equal($_TEST_DATA[i], actual)
202
+ else
203
+ begin
204
+ conn.process_result_read(results[i])
205
+ # a not found exception must be thrown
206
+ assert(false, 'expected a NotFoundError')
207
+ rescue Scalaroid::NotFoundError
208
+ end
209
+ end
210
+ end
211
+
212
+ # now evaluate the write results:
213
+ (0..(writeRequests.size() - 1)).each do |i|
214
+ pos = readRequests.size() + i
215
+ conn.process_result_write(results[pos])
216
+ end
217
+
218
+ # once again test reads - now all reads should be successful
219
+ results = conn.req_list(readRequests)
220
+ assert_equal(readRequests.size(), results.length)
221
+
222
+ # now evaluate the read results:
223
+ (0..(readRequests.size() - 1)).each do |i|
224
+ actual = conn.process_result_read(results[i])
225
+ assert_equal($_TEST_DATA[i], actual)
226
+ end
227
+
228
+ conn.close_connection();
229
+ end
230
+
231
+ # Test method for Transaction.write(key, value=bytearray()) with a
232
+ # request that is too large.
233
+ def test_req_too_large()
234
+ conn = Scalaroid::Transaction.new()
235
+ data = (0..($_TOO_LARGE_REQUEST_SIZE)).map{0}.join()
236
+ key = "_ReqTooLarge"
237
+ begin
238
+ conn.write(@testTime.to_s + key, data)
239
+ assert(false, 'The write should have failed unless yaws_max_post_data was set larger than ' + $_TOO_LARGE_REQUEST_SIZE.to_s())
240
+ rescue Scalaroid::ConnectionError
241
+ end
242
+
243
+ conn.close_connection()
244
+ end
245
+
246
+ # Various tests.
247
+ def test_various()
248
+ _writeSingleTest("_0:" + [0x0160].pack("U*") + "arplaninac:page_", $_TEST_DATA[0])
249
+ end
250
+
251
+ # Helper function for single write tests.
252
+ # Writes a strings to some key and tries to read it afterwards.
253
+ def _writeSingleTest(key, data)
254
+ t = Scalaroid::Transaction.new()
255
+
256
+ t.write(@testTime.to_s + key, data)
257
+ # now try to read the data:
258
+ assert_equal(data, t.read(@testTime.to_s + key))
259
+ # commit the transaction and try to read the data with a new one:
260
+ t.commit()
261
+ t = Scalaroid::Transaction.new()
262
+ assert_equal(data, t.read(@testTime.to_s + key))
263
+
264
+ t.close_connection()
265
+ end
266
+ private :_writeSingleTest
267
+ end