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.
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 test_it_requires_block_for_running_loop
33
- refute cb.async?
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 test_it_resets_async_flag_when_raising_exception_from_callback
43
- assert_raises(RuntimeError) do
44
- cb.run do |conn|
45
- conn.set(uniq_id, "foo") { raise }
46
- end
47
- end
48
- refute cb.async?
49
- end
50
-
51
- def test_nested_async_get_set
52
- cb.set(uniq_id, {"bar" => 1})
53
- cb.set(uniq_id(:hit), 0)
54
-
55
- cb.run do |conn|
56
- conn.get(uniq_id) do
57
- conn.get(uniq_id(:hit)) do |res|
58
- conn.set(uniq_id(:hit), res.value + 1)
59
- end
60
- end
61
- end
62
-
63
- val = cb.get(uniq_id(:hit))
64
- assert_equal 1, val
65
- end
66
-
67
- def test_nested_async_set_get
68
- val = nil
69
-
70
- cb.run do |conn|
71
- conn.set(uniq_id, "foo") do
72
- conn.get(uniq_id) do |res|
73
- val = res.value
74
- end
75
- end
76
- end
77
-
78
- assert_equal "foo", val
79
- end
80
-
81
- def test_nested_async_touch_get
82
- cb.set(uniq_id, "foo")
83
- success = false
84
- val = nil
85
-
86
- cb.run do |conn|
87
- conn.touch(uniq_id, :ttl => 1) do |res1|
88
- success = res1.success?
89
- conn.get(uniq_id) do |res2|
90
- val = res2.value
91
- end
92
- end
93
- end
94
-
95
- assert success
96
- assert_equal "foo", val
97
- sleep(2)
98
- assert_raises(Couchbase::Error::NotFound) do
99
- cb.get(uniq_id)
100
- end
101
- end
102
-
103
- def test_nested_async_delete_get
104
- cas = cb.set(uniq_id, "foo")
105
- success = false
106
- val = :unknown
107
-
108
- cb.run do |conn|
109
- conn.delete(uniq_id, :cas => cas) do |res1|
110
- success = res1.success?
111
- conn.get(uniq_id, :quiet => true) do |res2|
112
- val = res2.value
113
- end
114
- end
115
- end
116
-
117
- assert success
118
- refute val
119
- end
120
-
121
- def test_nested_async_stats_set
122
- skip
123
- stats = {}
124
-
125
- cb.run do |conn|
126
- conn.stats do |res1|
127
- id = uniq_id(res1.node, res1.key)
128
- stats[id] = false
129
- conn.set(id, res1.value) do |res2|
130
- stats[id] = res2.cas
131
- end
132
- end
133
- end
134
-
135
- stats.keys.each do |key|
136
- assert stats[key].is_a?(Numeric)
137
- end
138
- end
139
-
140
- def test_nested_async_flush_set
141
- skip
142
- cas = cb.set(uniq_id, "foo")
143
- res = {}
144
-
145
- cb.run do |conn|
146
- conn.flush do |res1|
147
- assert res1.success?, "Expected: successful status code.\nActual: #{res1.error.inspect}"
148
- id = uniq_id(res1.node)
149
- res[id] = false
150
- conn.set(id, true) do |res2|
151
- res[id] = res2.cas
152
- end
153
- end
154
- end
155
-
156
- assert_raises(Couchbase::Error::NotFound) do
157
- cb.get(uniq_id)
158
- end
159
- res.keys.each do |key|
160
- assert res[key].is_a?(Numeric)
161
- assert cb.get(key)
162
- end
163
- end
164
-
165
- def test_nested_async_incr_get
166
- skip
167
- cas = cb.set(uniq_id, 1)
168
- val = nil
169
-
170
- cb.run do |conn|
171
- conn.incr(uniq_id) do
172
- conn.get(uniq_id) do |res|
173
- val = res.value
174
- end
175
- end
176
- end
177
-
178
- assert_equal 2, val
179
- end
180
-
181
- def test_it_doesnt_accept_callbacks_in_synchronous_mode
182
- refute cb.async?
183
-
184
- assert_raises(ArgumentError) { cb.add(uniq_id, "foo") {} }
185
- assert_raises(ArgumentError) { cb.set(uniq_id, "foo") {} }
186
- assert_raises(ArgumentError) { cb.replace(uniq_id, "foo") {} }
187
- assert_raises(ArgumentError) { cb.get(uniq_id) {} }
188
- assert_raises(ArgumentError) { cb.touch(uniq_id) {} }
189
- assert_raises(ArgumentError) { cb.incr(uniq_id) {} }
190
- assert_raises(ArgumentError) { cb.decr(uniq_id) {} }
191
- assert_raises(ArgumentError) { cb.delete(uniq_id) {} }
192
- assert_raises(ArgumentError) { cb.append(uniq_id, "bar") {} }
193
- assert_raises(ArgumentError) { cb.prepend(uniq_id, "bar") {} }
194
- assert_raises(ArgumentError) { cb.flush {} }
195
- assert_raises(ArgumentError) { cb.stats {} }
196
- end
197
-
198
- def test_it_disallow_nested_run
199
- assert_raises(Couchbase::Error::Invalid) do
200
- cb.run do
201
- cb.run do
202
- end
203
- end
204
- end
205
- end
206
-
207
- def test_it_extends_timeout_in_async_mode_if_needed
208
- skip
209
- cb.set(uniq_id, "foo")
210
-
211
- cb.timeout = 100_000 # 100_000 us
212
- cb.run do
213
- cb.get(uniq_id) do |ret|
214
- assert ret.success?
215
- assert_equal "foo", ret.value
216
- end
217
- sleep(1.5) # 1_500_000 us
218
- end
219
- end
220
-
221
- def test_send_threshold
222
- skip
223
- sent = false
224
- cb.run(:send_threshold => 100) do # 100 bytes
225
- cb.set(uniq_id, "foo" * 100) {|r| sent = true}
226
- assert sent
227
- end
228
- end
229
-
230
- def test_asynchronous_connection
231
- skip
232
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
233
- refute cb.connected?, "new asynchronous connection must be disconnected"
234
- cb.on_connect do |res|
235
- assert res.success?, "on_connect called with error #{res.error.inspect}"
236
- assert_same connection, res.bucket
237
- end
238
- cb.run {}
239
- assert cb.connected?, "it should be connected after first run"
240
- end
241
-
242
- def test_it_calls_callback_immediately_if_connected_sync
243
- skip
244
- assert cb.connected?, "connection wasn't established in sync mode"
245
- called = false
246
- cb.on_connect do |res|
247
- assert res.success?, "on_connect called with error #{res.error.inspect}"
248
- called = true
249
- end
250
- assert called, "the callback hasn't been called on set"
251
- called = false
252
- cb.on_connect do |res|
253
- assert res.success?, "on_connect called with error #{res.error.inspect}"
254
- called = true
255
- end
256
- refute called, "the callback must not be called on subsequent sets"
257
- end
258
-
259
- def test_it_calls_callback_immediately_if_connected_async
260
- skip
261
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
262
- refute cb.connected?, "new asynchronous connection must be disconnected"
263
- called = false
264
- cb.run {}
265
- assert cb.connected?, "the connection must be established"
266
- cb.run do
267
- cb.on_connect do |res|
268
- assert res.success?, "on_connect called with error #{res.error.inspect}"
269
- called = true
270
- end
271
- end
272
- assert called, "the callback hasn't been called on set"
273
- called = false
274
- cb.run do
275
- cb.on_connect do |res|
276
- assert res.success?, "on_connect called with error #{res.error.inspect}"
277
- called = true
278
- end
279
- end
280
- refute called, "the callback must not be called on subsequent sets"
281
- end
282
-
283
- def test_it_returns_error_if_user_start_work_on_disconnected_instance_outside_on_connect_callback
284
- skip
285
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :async => true)
286
- refute cb.connected?, "new asynchronous connection must be disconnected"
287
- error = nil
288
- cb.on_error do |ex|
289
- error = ex
290
- end
291
- cb.run do |c|
292
- c.set("foo", "bar")
293
- end
294
- assert_instance_of(Couchbase::Error::Connect, error)
295
- end
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::KeyExists) do
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)
@@ -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"}