couchbase-jruby-client 0.1.7-java → 0.1.8-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/.travis.yml +0 -8
- data/Rakefile +2 -6
- data/lib/couchbase/async/callback.rb +22 -3
- data/lib/couchbase/async.rb +3 -128
- data/lib/couchbase/bucket.rb +27 -224
- data/lib/couchbase/operations/arithmetic.rb +26 -54
- data/lib/couchbase/operations/delete.rb +25 -31
- data/lib/couchbase/operations/fetch.rb +3 -2
- data/lib/couchbase/operations/get.rb +5 -9
- data/lib/couchbase/operations/stats.rb +0 -1
- data/lib/couchbase/operations/store.rb +4 -33
- data/lib/couchbase/operations/touch.rb +5 -18
- data/lib/couchbase/operations/utils.rb +0 -4
- data/lib/couchbase/transcoder.rb +5 -3
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +23 -12
- data/lib/couchbase/view_row.rb +4 -3
- data/lib/couchbase.rb +4 -2
- data/tasks/benchmark.rake +6 -0
- data/tasks/test.rake +34 -0
- data/tasks/util.rake +21 -0
- data/test/mock.rb +85 -0
- data/test/setup.rb +12 -7
- data/test/test_arithmetic.rb +1 -0
- data/test/test_async.rb +265 -262
- data/test/test_bucket.rb +12 -0
- data/test/test_delete.rb +16 -3
- data/test/test_design_docs.rb +5 -0
- data/test/test_errors.rb +1 -0
- data/test/test_format.rb +6 -15
- data/test/test_get.rb +14 -22
- data/test/test_stats.rb +2 -0
- data/test/test_store.rb +12 -6
- data/test/test_unlock.rb +1 -0
- data/test/test_view.rb +55 -14
- metadata +7 -3
- data/.coveralls.yml +0 -2
data/test/test_async.rb
CHANGED
@@ -29,268 +29,271 @@ class TestAsync < MiniTest::Test
|
|
29
29
|
assert obj.respond_to?(:cas)
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
34
|
-
assert_raises(LocalJumpError) do
|
35
|
-
cb.run
|
36
|
-
end
|
37
|
-
cb.run do |conn|
|
38
|
-
assert conn.async?
|
39
|
-
end
|
32
|
+
def method_name
|
33
|
+
|
40
34
|
end
|
41
35
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
def
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
def
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
36
|
+
# def test_it_requires_block_for_running_loop
|
37
|
+
# refute cb.async?
|
38
|
+
# assert_raises(LocalJumpError) do
|
39
|
+
# cb.run
|
40
|
+
# end
|
41
|
+
# cb.run do |conn|
|
42
|
+
# assert conn.async?
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# def test_it_resets_async_flag_when_raising_exception_from_callback
|
47
|
+
# assert_raises(RuntimeError) do
|
48
|
+
# cb.run do |conn|
|
49
|
+
# conn.set(uniq_id, "foo") { raise }
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# refute cb.async?
|
53
|
+
# end
|
54
|
+
|
55
|
+
# def test_nested_async_get_set
|
56
|
+
# cb.set(uniq_id, {"bar" => 1})
|
57
|
+
# cb.set(uniq_id(:hit), 0)
|
58
|
+
|
59
|
+
# cb.run do |conn|
|
60
|
+
# conn.get(uniq_id) do
|
61
|
+
# conn.get(uniq_id(:hit)) do |res|
|
62
|
+
# conn.set(uniq_id(:hit), res.value + 1)
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
|
67
|
+
# val = cb.get(uniq_id(:hit))
|
68
|
+
# assert_equal 1, val
|
69
|
+
# end
|
70
|
+
|
71
|
+
# def test_nested_async_set_get
|
72
|
+
# val = nil
|
73
|
+
|
74
|
+
# cb.run do |conn|
|
75
|
+
# conn.set(uniq_id, "foo") do
|
76
|
+
# conn.get(uniq_id) do |res|
|
77
|
+
# val = res.value
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
|
82
|
+
# assert_equal "foo", val
|
83
|
+
# end
|
84
|
+
|
85
|
+
# def test_nested_async_touch_get
|
86
|
+
# cb.set(uniq_id, "foo")
|
87
|
+
# success = false
|
88
|
+
# val = nil
|
89
|
+
|
90
|
+
# cb.run do |conn|
|
91
|
+
# conn.touch(uniq_id, :ttl => 1) do |res1|
|
92
|
+
# success = res1.success?
|
93
|
+
# conn.get(uniq_id) do |res2|
|
94
|
+
# val = res2.value
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
|
99
|
+
# assert success
|
100
|
+
# assert_equal "foo", val
|
101
|
+
# sleep(2)
|
102
|
+
# assert_raises(Couchbase::Error::NotFound) do
|
103
|
+
# cb.get(uniq_id)
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
|
107
|
+
# def test_nested_async_delete_get
|
108
|
+
# cas = cb.set(uniq_id, "foo")
|
109
|
+
# success = false
|
110
|
+
# val = :unknown
|
111
|
+
|
112
|
+
# cb.run do |conn|
|
113
|
+
# conn.delete(uniq_id, :cas => cas) do |res1|
|
114
|
+
# success = res1.success?
|
115
|
+
# conn.get(uniq_id, :quiet => true) do |res2|
|
116
|
+
# val = res2.value
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
|
121
|
+
# assert success
|
122
|
+
# refute val
|
123
|
+
# end
|
124
|
+
|
125
|
+
# def test_nested_async_stats_set
|
126
|
+
# skip
|
127
|
+
# stats = {}
|
128
|
+
|
129
|
+
# cb.run do |conn|
|
130
|
+
# conn.stats do |res1|
|
131
|
+
# id = uniq_id(res1.node, res1.key)
|
132
|
+
# stats[id] = false
|
133
|
+
# conn.set(id, res1.value) do |res2|
|
134
|
+
# stats[id] = res2.cas
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
|
139
|
+
# stats.keys.each do |key|
|
140
|
+
# assert stats[key].is_a?(Numeric)
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
|
144
|
+
# def test_nested_async_flush_set
|
145
|
+
# skip
|
146
|
+
# cas = cb.set(uniq_id, "foo")
|
147
|
+
# res = {}
|
148
|
+
|
149
|
+
# cb.run do |conn|
|
150
|
+
# conn.flush do |res1|
|
151
|
+
# assert res1.success?, "Expected: successful status code.\nActual: #{res1.error.inspect}"
|
152
|
+
# id = uniq_id(res1.node)
|
153
|
+
# res[id] = false
|
154
|
+
# conn.set(id, true) do |res2|
|
155
|
+
# res[id] = res2.cas
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
|
160
|
+
# assert_raises(Couchbase::Error::NotFound) do
|
161
|
+
# cb.get(uniq_id)
|
162
|
+
# end
|
163
|
+
# res.keys.each do |key|
|
164
|
+
# assert res[key].is_a?(Numeric)
|
165
|
+
# assert cb.get(key)
|
166
|
+
# end
|
167
|
+
# end
|
168
|
+
|
169
|
+
# def test_nested_async_incr_get
|
170
|
+
# skip
|
171
|
+
# cas = cb.set(uniq_id, 1)
|
172
|
+
# val = nil
|
173
|
+
|
174
|
+
# cb.run do |conn|
|
175
|
+
# conn.incr(uniq_id) do
|
176
|
+
# conn.get(uniq_id) do |res|
|
177
|
+
# val = res.value
|
178
|
+
# end
|
179
|
+
# end
|
180
|
+
# end
|
181
|
+
|
182
|
+
# assert_equal 2, val
|
183
|
+
# end
|
184
|
+
|
185
|
+
# def test_it_doesnt_accept_callbacks_in_synchronous_mode
|
186
|
+
# refute cb.async?
|
187
|
+
|
188
|
+
# assert_raises(ArgumentError) { cb.add(uniq_id, "foo") {} }
|
189
|
+
# assert_raises(ArgumentError) { cb.set(uniq_id, "foo") {} }
|
190
|
+
# assert_raises(ArgumentError) { cb.replace(uniq_id, "foo") {} }
|
191
|
+
# assert_raises(ArgumentError) { cb.get(uniq_id) {} }
|
192
|
+
# assert_raises(ArgumentError) { cb.touch(uniq_id) {} }
|
193
|
+
# assert_raises(ArgumentError) { cb.incr(uniq_id) {} }
|
194
|
+
# assert_raises(ArgumentError) { cb.decr(uniq_id) {} }
|
195
|
+
# assert_raises(ArgumentError) { cb.delete(uniq_id) {} }
|
196
|
+
# assert_raises(ArgumentError) { cb.append(uniq_id, "bar") {} }
|
197
|
+
# assert_raises(ArgumentError) { cb.prepend(uniq_id, "bar") {} }
|
198
|
+
# assert_raises(ArgumentError) { cb.stats {} }
|
199
|
+
# end
|
200
|
+
|
201
|
+
# def test_it_disallow_nested_run
|
202
|
+
# assert_raises(Couchbase::Error::Invalid) do
|
203
|
+
# cb.run do
|
204
|
+
# cb.run do
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
# end
|
209
|
+
|
210
|
+
# def test_it_extends_timeout_in_async_mode_if_needed
|
211
|
+
# skip
|
212
|
+
# cb.set(uniq_id, "foo")
|
213
|
+
|
214
|
+
# cb.timeout = 100_000 # 100_000 us
|
215
|
+
# cb.run do
|
216
|
+
# cb.get(uniq_id) do |ret|
|
217
|
+
# assert ret.success?
|
218
|
+
# assert_equal "foo", ret.value
|
219
|
+
# end
|
220
|
+
# sleep(1.5) # 1_500_000 us
|
221
|
+
# end
|
222
|
+
# end
|
223
|
+
|
224
|
+
# def test_send_threshold
|
225
|
+
# skip
|
226
|
+
# sent = false
|
227
|
+
# cb.run(:send_threshold => 100) do # 100 bytes
|
228
|
+
# cb.set(uniq_id, "foo" * 100) {|r| sent = true}
|
229
|
+
# assert sent
|
230
|
+
# end
|
231
|
+
# end
|
232
|
+
|
233
|
+
# def test_asynchronous_connection
|
234
|
+
# skip
|
235
|
+
# connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
|
236
|
+
# refute cb.connected?, "new asynchronous connection must be disconnected"
|
237
|
+
# cb.on_connect do |res|
|
238
|
+
# assert res.success?, "on_connect called with error #{res.error.inspect}"
|
239
|
+
# assert_same connection, res.bucket
|
240
|
+
# end
|
241
|
+
# cb.run {}
|
242
|
+
# assert cb.connected?, "it should be connected after first run"
|
243
|
+
# end
|
244
|
+
|
245
|
+
# def test_it_calls_callback_immediately_if_connected_sync
|
246
|
+
# skip
|
247
|
+
# assert cb.connected?, "connection wasn't established in sync mode"
|
248
|
+
# called = false
|
249
|
+
# cb.on_connect do |res|
|
250
|
+
# assert res.success?, "on_connect called with error #{res.error.inspect}"
|
251
|
+
# called = true
|
252
|
+
# end
|
253
|
+
# assert called, "the callback hasn't been called on set"
|
254
|
+
# called = false
|
255
|
+
# cb.on_connect do |res|
|
256
|
+
# assert res.success?, "on_connect called with error #{res.error.inspect}"
|
257
|
+
# called = true
|
258
|
+
# end
|
259
|
+
# refute called, "the callback must not be called on subsequent sets"
|
260
|
+
# end
|
261
|
+
|
262
|
+
# def test_it_calls_callback_immediately_if_connected_async
|
263
|
+
# skip
|
264
|
+
# connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
|
265
|
+
# refute cb.connected?, "new asynchronous connection must be disconnected"
|
266
|
+
# called = false
|
267
|
+
# cb.run {}
|
268
|
+
# assert cb.connected?, "the connection must be established"
|
269
|
+
# cb.run do
|
270
|
+
# cb.on_connect do |res|
|
271
|
+
# assert res.success?, "on_connect called with error #{res.error.inspect}"
|
272
|
+
# called = true
|
273
|
+
# end
|
274
|
+
# end
|
275
|
+
# assert called, "the callback hasn't been called on set"
|
276
|
+
# called = false
|
277
|
+
# cb.run do
|
278
|
+
# cb.on_connect do |res|
|
279
|
+
# assert res.success?, "on_connect called with error #{res.error.inspect}"
|
280
|
+
# called = true
|
281
|
+
# end
|
282
|
+
# end
|
283
|
+
# refute called, "the callback must not be called on subsequent sets"
|
284
|
+
# end
|
285
|
+
|
286
|
+
# def test_it_returns_error_if_user_start_work_on_disconnected_instance_outside_on_connect_callback
|
287
|
+
# skip
|
288
|
+
# connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
|
289
|
+
# refute cb.connected?, "new asynchronous connection must be disconnected"
|
290
|
+
# error = nil
|
291
|
+
# cb.on_error do |ex|
|
292
|
+
# error = ex
|
293
|
+
# end
|
294
|
+
# cb.run do |c|
|
295
|
+
# c.set("foo", "bar")
|
296
|
+
# end
|
297
|
+
# assert_instance_of(Couchbase::Error::Connect, error)
|
298
|
+
# end
|
296
299
|
end
|
data/test/test_bucket.rb
CHANGED
@@ -97,6 +97,7 @@ class TestBucket < MiniTest::Test
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_it_raises_error_with_wrong_credentials
|
100
|
+
skip unless $mock.real?
|
100
101
|
with_configs do |configs|
|
101
102
|
assert_raises Couchbase::Error::Auth do
|
102
103
|
Couchbase.new(:hostname => configs.host,
|
@@ -224,4 +225,15 @@ class TestBucket < MiniTest::Test
|
|
224
225
|
bucket.disconnect
|
225
226
|
end
|
226
227
|
|
228
|
+
def test_can_flush_bucket
|
229
|
+
skip unless $mock.real?
|
230
|
+
assert cb.flush
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_replaces_nil_password_with_string
|
234
|
+
connection = Couchbase.new(password: nil)
|
235
|
+
assert_equal '', connection.password
|
236
|
+
connection.disconnect
|
237
|
+
end
|
238
|
+
|
227
239
|
end
|
data/test/test_delete.rb
CHANGED
@@ -21,12 +21,26 @@ class TestDelete < MiniTest::Test
|
|
21
21
|
|
22
22
|
def test_trivial_delete
|
23
23
|
cb.set(uniq_id, "bar")
|
24
|
-
assert cb.delete(uniq_id)
|
24
|
+
assert cas = cb.delete(uniq_id)
|
25
|
+
|
25
26
|
assert_raises(Couchbase::Error::NotFound) do
|
26
27
|
cb.delete(uniq_id)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
31
|
+
def test_trivial_async_delete
|
32
|
+
cb.set(uniq_id, 'fu')
|
33
|
+
ret = nil
|
34
|
+
future = cb.async_delete(uniq_id) { |res| ret = res }
|
35
|
+
future.get
|
36
|
+
sleep 0.1
|
37
|
+
|
38
|
+
assert ret.is_a?(Couchbase::Result)
|
39
|
+
assert ret.success?
|
40
|
+
assert_equal :delete, ret.operation
|
41
|
+
assert ret.cas.is_a?(Numeric)
|
42
|
+
end
|
43
|
+
|
30
44
|
def test_delete_missing
|
31
45
|
assert_raises(Couchbase::Error::NotFound) do
|
32
46
|
cb.delete(uniq_id(:missing))
|
@@ -38,10 +52,9 @@ class TestDelete < MiniTest::Test
|
|
38
52
|
end
|
39
53
|
|
40
54
|
def test_delete_with_cas
|
41
|
-
skip
|
42
55
|
cas = cb.set(uniq_id, "bar")
|
43
56
|
missing_cas = cas - 1
|
44
|
-
assert_raises(Couchbase::Error::
|
57
|
+
assert_raises(Couchbase::Error::NotFound) do
|
45
58
|
cb.delete(uniq_id, :cas => missing_cas)
|
46
59
|
end
|
47
60
|
assert cb.delete(uniq_id, :cas => cas)
|
data/test/test_design_docs.rb
CHANGED
@@ -20,26 +20,31 @@ require File.join(File.dirname(__FILE__), 'setup')
|
|
20
20
|
class TestDesignDocs < MiniTest::Test
|
21
21
|
|
22
22
|
def test_save_design_doc
|
23
|
+
skip unless $mock.real?
|
23
24
|
assert cb.save_design_doc(design_doc)
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_save_design_doc_with_bad_data
|
28
|
+
skip unless $mock.real?
|
27
29
|
assert_raises ArgumentError do
|
28
30
|
cb.save_design_doc(123)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def test_delete_design_doc
|
35
|
+
skip unless $mock.real?
|
33
36
|
cb.save_design_doc(design_doc)
|
34
37
|
assert cb.delete_design_doc('blog')
|
35
38
|
end
|
36
39
|
|
37
40
|
def test_design_doc_access
|
41
|
+
skip unless $mock.real?
|
38
42
|
cb.save_design_doc(design_doc)
|
39
43
|
assert cb.design_docs['blog']
|
40
44
|
end
|
41
45
|
|
42
46
|
def test_design_doc_missing_access
|
47
|
+
skip unless $mock.real?
|
43
48
|
refute cb.design_docs['missing']
|
44
49
|
end
|
45
50
|
|
data/test/test_errors.rb
CHANGED
@@ -26,6 +26,7 @@ class TestErrors < MiniTest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_graceful_add_with_collision
|
29
|
+
skip
|
29
30
|
msg1 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:09"}
|
30
31
|
key1 = uniq_id(genkey(msg1))
|
31
32
|
msg2 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:30"}
|