couchbase-jruby-client 0.1.0-java → 0.1.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.jrubyrc +722 -0
  3. data/.ruby-version +1 -1
  4. data/README.md +12 -90
  5. data/couchbase-jruby-client.gemspec +6 -6
  6. data/lib/couchbase/async.rb +18 -0
  7. data/lib/couchbase/bucket.rb +90 -180
  8. data/lib/couchbase/constants.rb +17 -0
  9. data/lib/couchbase/design_doc.rb +83 -0
  10. data/lib/couchbase/error.rb +31 -0
  11. data/lib/couchbase/operations/arithmetic.rb +17 -0
  12. data/lib/couchbase/operations/delete.rb +17 -0
  13. data/lib/couchbase/operations/design_docs.rb +99 -0
  14. data/lib/couchbase/operations/get.rb +73 -67
  15. data/lib/couchbase/operations/stats.rb +28 -1
  16. data/lib/couchbase/operations/store.rb +114 -97
  17. data/lib/couchbase/operations/touch.rb +49 -19
  18. data/lib/couchbase/operations/unlock.rb +209 -0
  19. data/lib/couchbase/operations/utils.rb +22 -10
  20. data/lib/couchbase/operations.rb +21 -0
  21. data/lib/couchbase/query.rb +92 -0
  22. data/lib/couchbase/result.rb +18 -1
  23. data/lib/couchbase/transcoder.rb +36 -42
  24. data/lib/couchbase/version.rb +18 -1
  25. data/lib/couchbase/view.rb +30 -172
  26. data/lib/couchbase/view_row.rb +38 -98
  27. data/lib/couchbase.rb +74 -72
  28. data/test/profile/.jrubyrc +722 -0
  29. data/test/profile/Gemfile +5 -5
  30. data/test/profile/benchmark.rb +106 -124
  31. data/test/profile/profile.rb +59 -0
  32. data/test/setup.rb +10 -145
  33. data/test/test_arithmetic.rb +54 -77
  34. data/test/test_async.rb +74 -102
  35. data/test/test_bucket.rb +74 -60
  36. data/test/test_cas.rb +10 -23
  37. data/test/test_couchbase.rb +11 -3
  38. data/test/test_delete.rb +41 -43
  39. data/test/test_design_docs.rb +62 -0
  40. data/test/test_errors.rb +9 -18
  41. data/test/test_format.rb +21 -31
  42. data/test/test_get.rb +107 -151
  43. data/test/test_query.rb +23 -0
  44. data/test/test_stats.rb +9 -24
  45. data/test/test_store.rb +52 -65
  46. data/test/test_timer.rb +4 -12
  47. data/test/test_touch.rb +26 -33
  48. data/test/test_unlock.rb +47 -78
  49. data/test/test_utils.rb +2 -11
  50. data/test/test_version.rb +5 -14
  51. data/test/test_view.rb +87 -0
  52. metadata +27 -14
  53. data/lib/couchbase/jruby/couchbase_client.rb +0 -22
  54. data/lib/couchbase/jruby/future.rb +0 -8
data/test/test_format.rb CHANGED
@@ -25,20 +25,11 @@ class TestFormat < MiniTest::Test
25
25
  undef to_json rescue nil
26
26
  end
27
27
 
28
- def setup
29
- @mock = start_mock
30
- end
31
-
32
- def teardown
33
- stop_mock(@mock)
34
- end
35
-
36
28
  def test_default_document_format
37
29
  orig_doc = {'name' => 'Twoflower', 'role' => 'The tourist'}
38
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
39
- assert_equal :document, connection.default_format
40
- connection.set(uniq_id, orig_doc)
41
- doc, flags, cas = connection.get(uniq_id, :extended => true)
30
+ assert_equal :document, cb.default_format
31
+ cb.set(uniq_id, orig_doc)
32
+ doc, flags, cas = cb.get(uniq_id, :extended => true)
42
33
  # assert_equal 0x00, flags & 0x11
43
34
  assert doc.is_a?(Hash)
44
35
  assert_equal 'Twoflower', doc['name']
@@ -51,9 +42,8 @@ class TestFormat < MiniTest::Test
51
42
  refute orig_doc.respond_to?(:to_s)
52
43
  refute orig_doc.respond_to?(:to_json)
53
44
 
54
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :document)
55
45
  assert_raises(Couchbase::Error::ValueFormat) do
56
- connection.set(uniq_id, orig_doc)
46
+ cb.set(uniq_id, orig_doc)
57
47
  end
58
48
 
59
49
  class << orig_doc
@@ -61,7 +51,7 @@ class TestFormat < MiniTest::Test
61
51
  MultiJson.dump(:name => name, :role => role)
62
52
  end
63
53
  end
64
- connection.set(uniq_id, orig_doc) # OK
54
+ cb.set(uniq_id, orig_doc) # OK
65
55
 
66
56
  class << orig_doc
67
57
  undef to_json
@@ -69,15 +59,14 @@ class TestFormat < MiniTest::Test
69
59
  MultiJson.dump(:name => name, :role => role)
70
60
  end
71
61
  end
72
- connection.set(uniq_id, orig_doc) # OK
62
+ cb.set(uniq_id, orig_doc) # OK
73
63
  end
74
64
  end
75
65
 
76
66
  def test_it_could_dump_arbitrary_class_using_marshal_format
77
67
  orig_doc = ArbitraryClass.new("Twoflower", "The tourist")
78
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
79
- connection.set(uniq_id, orig_doc, :format => :marshal)
80
- doc, flags, cas = connection.get(uniq_id, :extended => true)
68
+ cb.set(uniq_id, orig_doc, :format => :marshal)
69
+ doc, flags, cas = cb.get(uniq_id, :extended => true)
81
70
  # assert_equal Couchbase::Bucket::FMT_MARSHAL, flags & Couchbase::Bucket::FMT_MASK
82
71
  assert doc.is_a?(ArbitraryClass)
83
72
  assert_equal 'Twoflower', doc.name
@@ -85,32 +74,34 @@ class TestFormat < MiniTest::Test
85
74
  end
86
75
 
87
76
  def test_it_accepts_only_string_in_plain_mode
77
+ skip
88
78
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
89
- connection.set(uniq_id, "1")
79
+ cb.set(uniq_id, "1")
90
80
 
91
81
  assert_raises(Couchbase::Error::ValueFormat) do
92
- connection.set(uniq_id, 1)
82
+ cb.set(uniq_id, 1)
93
83
  end
94
84
 
95
85
  assert_raises(Couchbase::Error::ValueFormat) do
96
- connection.set(uniq_id, {:foo => "bar"})
86
+ cb.set(uniq_id, {:foo => "bar"})
97
87
  end
98
88
  end
99
89
 
100
90
  def test_bignum_conversion
91
+ skip
101
92
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
102
93
  cas = 0xffff_ffff_ffff_ffff
103
94
  assert cas.is_a?(Bignum)
104
95
  assert_raises(Couchbase::Error::NotFound) do
105
- connection.delete(uniq_id => cas)
96
+ cb.delete(uniq_id => cas)
106
97
  end
107
98
  end
108
99
 
109
100
  def test_it_allows_to_turn_off_transcoder
110
101
  skip
111
102
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :transcoder => nil)
112
- connection.set(uniq_id, "value", :flags => 0xffff_ffff)
113
- doc, flags, _ = connection.get(uniq_id, :extended => true)
103
+ cb.set(uniq_id, "value", :flags => 0xffff_ffff)
104
+ doc, flags, _ = cb.get(uniq_id, :extended => true)
114
105
  assert_equal "value", doc
115
106
  assert_equal 0xffff_ffff, flags
116
107
  end
@@ -147,14 +138,13 @@ class TestFormat < MiniTest::Test
147
138
 
148
139
  def test_it_can_use_custom_transcoder
149
140
  skip
150
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
151
- connection.transcoder = ZlibTranscoder.new(Couchbase::Transcoder::Document)
152
- connection.set(uniq_id, {"foo" => "bar"})
153
- doc, flags, _ = connection.get(uniq_id, :extended => true)
141
+ cb.transcoder = ZlibTranscoder.new(Couchbase::Transcoder::Document)
142
+ cb.set(uniq_id, {"foo" => "bar"})
143
+ doc, flags, _ = cb.get(uniq_id, :extended => true)
154
144
  assert_equal({"foo" => "bar"}, doc)
155
145
  assert_equal(ZlibTranscoder::FMT_ZLIB|Couchbase::Bucket::FMT_DOCUMENT, flags)
156
- connection.transcoder = nil
157
- doc = connection.get(uniq_id)
146
+ cb.transcoder = nil
147
+ doc = cb.get(uniq_id)
158
148
  assert_equal "x\x01\xABVJ\xCB\xCFW\xB2RJJ,R\xAA\x05\0\x1Dz\x044", doc
159
149
  end
160
150
 
data/test/test_get.rb CHANGED
@@ -19,156 +19,136 @@ require File.join(File.dirname(__FILE__), 'setup')
19
19
 
20
20
  class TestGet < MiniTest::Test
21
21
 
22
- def setup
23
- @mock = start_mock
24
- end
25
-
26
- def teardown
27
- stop_mock(@mock)
28
- end
29
-
30
22
  def test_trivial_get
31
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
- connection.set(uniq_id, "bar")
33
- val = connection.get(uniq_id)
23
+ cb.set(uniq_id, "bar")
24
+ val = cb.get(uniq_id)
34
25
  assert_equal "bar", val
35
26
  end
36
27
 
37
28
  def test_extended_get
38
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
39
-
40
- orig_cas = connection.set(uniq_id, "bar")
41
- val, flags, cas = connection.get(uniq_id, :extended => true)
29
+ orig_cas = cb.set(uniq_id, "bar")
30
+ val, flags, cas = cb.get(uniq_id, :extended => true)
42
31
  assert_equal "bar", val
43
32
  #assert_equal 0x0, flags
44
33
  assert_equal orig_cas, cas
45
34
 
46
- orig_cas = connection.set(uniq_id, "bar", :flags => 0x1000)
47
- val, flags, cas = connection.get(uniq_id, :extended => true)
35
+ orig_cas = cb.set(uniq_id, "bar", :flags => 0x1000)
36
+ val, flags, cas = cb.get(uniq_id, :extended => true)
48
37
  assert_equal "bar", val
49
38
  #assert_equal 0x1000, flags
50
39
  assert_equal orig_cas, cas
51
40
  end
52
41
 
53
42
  def test_multi_get
54
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
43
+ cb.set(uniq_id(1), "foo1")
44
+ cb.set(uniq_id(2), "foo2")
55
45
 
56
- connection.set(uniq_id(1), "foo1")
57
- connection.set(uniq_id(2), "foo2")
58
-
59
- val1, val2 = connection.get(uniq_id(1), uniq_id(2))
46
+ val1, val2 = cb.get(uniq_id(1), uniq_id(2))
60
47
  assert_equal "foo1", val1
61
48
  assert_equal "foo2", val2
62
49
  end
63
50
 
64
51
  def test_multi_get_extended
65
52
  skip 'Looking like Java client doesnt support multi_get_extended'
66
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
67
53
 
68
- cas1 = connection.set(uniq_id(1), "foo1")
69
- cas2 = connection.set(uniq_id(2), "foo2")
54
+ cas1 = cb.set(uniq_id(1), "foo1")
55
+ cas2 = cb.set(uniq_id(2), "foo2")
70
56
 
71
- results = connection.get(uniq_id(1), uniq_id(2), :extended => true)
57
+ results = cb.get(uniq_id(1), uniq_id(2), :extended => true)
72
58
  assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
73
59
  assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
74
60
  end
75
61
 
76
62
  def test_multi_get_and_touch
77
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
78
- connection.set(uniq_id(1), "foo1")
79
- connection.set(uniq_id(2), "foo2")
63
+ cb.set(uniq_id(1), "foo1")
64
+ cb.set(uniq_id(2), "foo2")
80
65
 
81
- results = connection.get(uniq_id(1) => 1, uniq_id(2) => 1)
66
+ results = cb.get(uniq_id(1) => 1, uniq_id(2) => 1)
82
67
  assert results.is_a?(Hash)
83
68
  assert_equal "foo1", results[uniq_id(1)]
84
69
  assert_equal "foo2", results[uniq_id(2)]
85
70
  sleep(2)
86
71
  assert_raises(Couchbase::Error::NotFound) do
87
- connection.get(uniq_id(1), uniq_id(2))
72
+ cb.get(uniq_id(1), uniq_id(2))
88
73
  end
89
- assert connection.get(uniq_id(1), uniq_id(2), :quiet => true).compact.empty?
74
+ assert cb.get(uniq_id(1), uniq_id(2), :quiet => true).compact.empty?
90
75
  end
91
76
 
92
77
  def test_multi_get_and_touch_extended
93
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
94
-
95
- cas1 = connection.set(uniq_id(1), "foo1")
96
- cas2 = connection.set(uniq_id(2), "foo2")
78
+ cas1 = cb.set(uniq_id(1), "foo1")
79
+ cas2 = cb.set(uniq_id(2), "foo2")
97
80
 
98
- results = connection.get({uniq_id(1) => 1, uniq_id(2) => 1}, :extended => true)
81
+ results = cb.get({uniq_id(1) => 1, uniq_id(2) => 1}, :extended => true)
99
82
  assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
100
83
  assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
101
84
  end
102
85
 
103
86
  def test_multi_get_and_touch_with_single_key
104
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
105
- connection.set(uniq_id, "foo1")
87
+ cb.set(uniq_id, "foo1")
106
88
 
107
- results = connection.get(uniq_id => 1)
89
+ results = cb.get(uniq_id => 1)
108
90
  assert results.is_a?(Hash)
109
91
  assert_equal "foo1", results[uniq_id]
110
92
  sleep(2)
111
93
  assert_raises(Couchbase::Error::NotFound) do
112
- connection.get(uniq_id)
94
+ cb.get(uniq_id)
113
95
  end
114
96
  end
115
97
 
116
98
  def test_missing_in_quiet_mode
117
- skip
118
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
119
- cas1 = connection.set(uniq_id(1), "foo1")
120
- cas2 = connection.set(uniq_id(2), "foo2")
99
+ cb.quiet = true
100
+ cas1 = cb.set(uniq_id(1), "foo1")
101
+ cas2 = cb.set(uniq_id(2), "foo2")
121
102
 
122
- val = connection.get(uniq_id(:missing))
103
+ val = cb.get(uniq_id(:missing))
123
104
  refute(val)
124
- val = connection.get(uniq_id(:missing), :extended => true)
105
+ val = cb.get(uniq_id(:missing), :extended => true)
125
106
  refute(val)
126
107
 
127
- val1, missing, val2 = connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
108
+ val1, missing, val2 = cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
128
109
  assert_equal "foo1", val1
129
110
  refute missing
130
111
  assert_equal "foo2", val2
131
112
 
132
113
  # TODO: multi get with cas
133
- # results = connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
114
+ # results = cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
134
115
  # assert_equal ["foo1", nil, cas1], results[uniq_id(1)]
135
116
  # refute results[uniq_id(:missing)]
136
117
  # assert_equal ["foo2", nil, cas2], results[uniq_id(2)]
118
+ ensure
119
+ cb.quiet = false
137
120
  end
138
121
 
139
122
  def test_it_allows_temporary_quiet_flag
140
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => false)
141
123
  assert_raises(Couchbase::Error::NotFound) do
142
- connection.get(uniq_id(:missing))
124
+ cb.get(uniq_id(:missing))
143
125
  end
144
- refute connection.get(uniq_id(:missing), :quiet => true)
126
+ refute cb.get(uniq_id(:missing), :quiet => true)
145
127
  end
146
128
 
147
129
  def test_missing_in_verbose_mode
148
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => false)
149
- connection.set(uniq_id(1), "foo1")
150
- connection.set(uniq_id(2), "foo2")
130
+ cb.set(uniq_id(1), "foo1")
131
+ cb.set(uniq_id(2), "foo2")
151
132
 
152
133
  assert_raises(Couchbase::Error::NotFound) do
153
- connection.get(uniq_id(:missing))
134
+ cb.get(uniq_id(:missing))
154
135
  end
155
136
 
156
137
  assert_raises(Couchbase::Error::NotFound) do
157
- connection.get(uniq_id(:missing), :extended => true)
138
+ cb.get(uniq_id(:missing), :extended => true)
158
139
  end
159
140
 
160
141
  assert_raises(Couchbase::Error::NotFound) do
161
- connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
142
+ cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
162
143
  end
163
144
 
164
145
  assert_raises(Couchbase::Error::NotFound) do
165
- connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
146
+ cb.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
166
147
  end
167
148
  end
168
149
 
169
150
  def test_asynchronous_get
170
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
171
- cas = connection.set(uniq_id, "foo")
151
+ cas = cb.set(uniq_id, "foo")
172
152
  res = []
173
153
 
174
154
  suite = lambda do |conn|
@@ -189,21 +169,20 @@ class TestGet < MiniTest::Test
189
169
  end
190
170
  end
191
171
 
192
- connection.run(&suite)
172
+ cb.run(&suite)
193
173
  checks.call
194
174
 
195
- connection.run{ suite.call(connection) }
175
+ cb.run{ suite.call(cb) }
196
176
  checks.call
197
177
  end
198
178
 
199
179
  def test_asynchronous_multi_get
200
180
  skip
201
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
202
- connection.set(uniq_id(1), "foo")
203
- connection.set(uniq_id(2), "bar")
181
+ cb.set(uniq_id(1), "foo")
182
+ cb.set(uniq_id(2), "bar")
204
183
 
205
184
  res = {}
206
- connection.run do |conn|
185
+ cb.run do |conn|
207
186
  conn.get(uniq_id(1), uniq_id(2)) {|ret| res[ret.key] = ret.value}
208
187
  end
209
188
 
@@ -215,8 +194,7 @@ class TestGet < MiniTest::Test
215
194
 
216
195
  def test_asynchronous_get_missing
217
196
  skip
218
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
219
- connection.set(uniq_id, "foo")
197
+ cb.set(uniq_id, "foo")
220
198
  res = {}
221
199
  missing = []
222
200
 
@@ -240,14 +218,14 @@ class TestGet < MiniTest::Test
240
218
  conn.get(uniq_id, uniq_id(:missing2), &get_handler)
241
219
  end
242
220
 
243
- connection.run(&suite)
221
+ cb.run(&suite)
244
222
  refute res.has_key?(uniq_id(:missing1))
245
223
  refute res.has_key?(uniq_id(:missing2))
246
224
  assert_equal [uniq_id(:missing1), uniq_id(:missing2)], missing.sort
247
225
  assert_equal "foo", res[uniq_id]
248
226
 
249
- connection.quiet = true
250
- connection.run(&suite)
227
+ cb.quiet = true
228
+ cb.run(&suite)
251
229
  assert_equal "foo", res[uniq_id]
252
230
  assert res.has_key?(uniq_id(:missing1)) # handler was called with nil
253
231
  refute res[uniq_id(:missing1)]
@@ -257,16 +235,14 @@ class TestGet < MiniTest::Test
257
235
  end
258
236
 
259
237
  def test_get_using_brackets
260
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
261
-
262
- orig_cas = connection.set(uniq_id, "foo", :flags => 0x1100)
238
+ orig_cas = cb.set(uniq_id, "foo", :flags => 0x1100)
263
239
 
264
- val = connection[uniq_id]
240
+ val = cb[uniq_id]
265
241
  assert_equal "foo", val
266
242
 
267
243
  if RUBY_VERSION =~ /^1\.9/
268
244
  eval <<-EOC
269
- val, flags, cas = connection[uniq_id, :extended => true]
245
+ val, flags, cas = cb[uniq_id, :extended => true]
270
246
  assert_equal "foo", val
271
247
  #assert_equal 0x1100, flags
272
248
  assert_equal orig_cas, cas
@@ -276,16 +252,15 @@ class TestGet < MiniTest::Test
276
252
 
277
253
  def test_it_allows_to_store_nil
278
254
  skip "TODO: figure out nil storage"
279
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
280
255
 
281
- orig_cas = connection.set(uniq_id, nil)
256
+ orig_cas = cb.set(uniq_id, nil)
282
257
  assert orig_cas.is_a?(Numeric)
283
258
 
284
- refute connection.get(uniq_id)
259
+ refute cb.get(uniq_id)
285
260
  # doesn't raise NotFound exception
286
- refute connection.get(uniq_id, :quiet => false)
261
+ refute cb.get(uniq_id, :quiet => false)
287
262
  # returns CAS
288
- value, flags, cas = connection.get(uniq_id, :extended => true)
263
+ value, flags, cas = cb.get(uniq_id, :extended => true)
289
264
  refute value
290
265
  #assert_equal 0x00, flags
291
266
  assert_equal orig_cas, cas
@@ -293,125 +268,106 @@ class TestGet < MiniTest::Test
293
268
 
294
269
  def test_zero_length_string_is_not_nil
295
270
  skip("zero length string")
296
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
297
271
 
298
- connection.set(uniq_id, "", :format => :document)
299
- assert_equal "", connection.get(uniq_id)
272
+ cb.set(uniq_id, "", :format => :document)
273
+ assert_equal "", cb.get(uniq_id)
300
274
 
301
- connection.set(uniq_id, "", :format => :plain)
302
- assert_equal "", connection.get(uniq_id)
275
+ cb.set(uniq_id, "", :format => :plain)
276
+ assert_equal "", cb.get(uniq_id)
303
277
 
304
- connection.set(uniq_id, "", :format => :marshal)
305
- assert_equal "", connection.get(uniq_id)
278
+ cb.set(uniq_id, "", :format => :marshal)
279
+ assert_equal "", cb.get(uniq_id)
306
280
 
307
- connection.set(uniq_id, nil, :format => :document)
308
- assert_equal nil, connection.get(uniq_id, :quiet => false)
281
+ cb.set(uniq_id, nil, :format => :document)
282
+ assert_equal nil, cb.get(uniq_id, :quiet => false)
309
283
 
310
284
  assert_raises Couchbase::Error::ValueFormat do
311
- connection.set(uniq_id, nil, :format => :plain)
285
+ cb.set(uniq_id, nil, :format => :plain)
312
286
  end
313
287
 
314
- connection.set(uniq_id, nil, :format => :marshal)
315
- assert_equal nil, connection.get(uniq_id, :quiet => false)
288
+ cb.set(uniq_id, nil, :format => :marshal)
289
+ assert_equal nil, cb.get(uniq_id, :quiet => false)
316
290
  end
317
291
 
318
292
  def test_format_forcing
319
293
  skip("format forcing")
320
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
321
294
 
322
- connection.set(uniq_id, '{"foo":"bar"}', :format => :plain)
323
- value, flags, _ = connection.get(uniq_id, :extended => true)
295
+ cb.set(uniq_id, '{"foo":"bar"}', :format => :plain)
296
+ value, flags, _ = cb.get(uniq_id, :extended => true)
324
297
  assert_equal '{"foo":"bar"}', value
325
298
  assert_equal 0x02, flags
326
299
 
327
- value, flags, _ = connection.get(uniq_id, :extended => true, :format => :document)
300
+ value, flags, _ = cb.get(uniq_id, :extended => true, :format => :document)
328
301
  expected = {"foo" => "bar"}
329
302
  assert_equal expected, value
330
303
  assert_equal 0x02, flags
331
304
 
332
- connection.prepend(uniq_id, "NOT-A-JSON")
305
+ cb.prepend(uniq_id, "NOT-A-JSON")
333
306
  assert_raises Couchbase::Error::ValueFormat do
334
- connection.get(uniq_id, :format => :document)
307
+ cb.get(uniq_id, :format => :document)
335
308
  end
336
309
  end
337
310
 
338
311
  # http://www.couchbase.com/issues/browse/RCBC-31
339
312
  def test_consistent_behaviour_for_arrays
340
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
341
313
 
342
- cas = connection.set(uniq_id("foo"), "foo")
343
- connection.set(uniq_id("bar"), "bar")
314
+ cas = cb.set(uniq_id("foo"), "foo")
315
+ cb.set(uniq_id("bar"), "bar")
344
316
 
345
- assert_equal "foo", connection.get(uniq_id("foo"))
346
- assert_equal ["foo"], connection.get([uniq_id("foo")])
347
- assert_equal ["foo", "bar"], connection.get([uniq_id("foo"), uniq_id("bar")])
348
- assert_equal ["foo", "bar"], connection.get(uniq_id("foo"), uniq_id("bar"))
317
+ assert_equal "foo", cb.get(uniq_id("foo"))
318
+ assert_equal ["foo"], cb.get([uniq_id("foo")])
319
+ assert_equal ["foo", "bar"], cb.get([uniq_id("foo"), uniq_id("bar")])
320
+ assert_equal ["foo", "bar"], cb.get(uniq_id("foo"), uniq_id("bar"))
349
321
  # expected = {uniq_id("foo") => ["foo", nil, cas]}
350
- # assert_equal expected, connection.get([uniq_id("foo")], :extended => true)
322
+ # assert_equal expected, cb.get([uniq_id("foo")], :extended => true)
351
323
  assert_raises TypeError do
352
- connection.get([uniq_id("foo"), uniq_id("bar")], [uniq_id("foo")])
324
+ cb.get([uniq_id("foo"), uniq_id("bar")], [uniq_id("foo")])
353
325
  end
354
326
  end
355
327
 
356
328
  def test_get_with_lock_trivial
357
- if @mock.real?
358
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
359
- connection.set(uniq_id, "foo")
329
+ cb.set(uniq_id, "foo")
360
330
 
361
- assert_equal "foo", connection.get(uniq_id, :lock => 1)
362
- assert_raises Couchbase::Error::KeyExists do
363
- connection.set(uniq_id, "bar")
364
- end
365
- sleep(2)
366
- connection.set(uniq_id, "bar")
367
- else
368
- skip("implement GETL in CouchbaseMock.jar")
331
+ assert_equal "foo", cb.get(uniq_id, :lock => 1)
332
+ assert_raises Couchbase::Error::KeyExists do
333
+ cb.set(uniq_id, "bar")
369
334
  end
335
+ sleep(2)
336
+ cb.set(uniq_id, "bar")
370
337
  end
371
338
 
372
339
  def test_multi_get_with_lock
373
340
  skip("multi_get_with_lock")
374
- if @mock.real?
375
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
376
- connection.set(uniq_id(1), "foo1")
377
- connection.set(uniq_id(2), "foo2")
378
- assert_equal ["foo1", "foo2"], connection.get([uniq_id(1), uniq_id(2)], :lock => 1)
379
- assert_raises Couchbase::Error::KeyExists do
380
- connection.set(uniq_id(1), "bar")
381
- end
382
- assert_raises Couchbase::Error::KeyExists do
383
- connection.set(uniq_id(2), "bar")
384
- end
385
- else
386
- skip("implement GETL in CouchbaseMock.jar")
341
+ cb.set(uniq_id(1), "foo1")
342
+ cb.set(uniq_id(2), "foo2")
343
+ assert_equal ["foo1", "foo2"], cb.get([uniq_id(1), uniq_id(2)], :lock => 1)
344
+ assert_raises Couchbase::Error::KeyExists do
345
+ cb.set(uniq_id(1), "bar")
346
+ end
347
+ assert_raises Couchbase::Error::KeyExists do
348
+ cb.set(uniq_id(2), "bar")
387
349
  end
388
350
  end
389
351
 
390
352
  def test_multi_get_with_custom_locks
391
353
  skip("multi_get_with_custom_locks")
392
- if @mock.real?
393
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
394
- connection.set(uniq_id(1), "foo1")
395
- connection.set(uniq_id(2), "foo2")
396
- expected = {uniq_id(1) => "foo1", uniq_id(2) => "foo2"}
397
- assert_equal expected, connection.get({uniq_id(1) => 1, uniq_id(2) => 2}, :lock => true)
398
- assert_raises Couchbase::Error::KeyExists do
399
- connection.set(uniq_id(1), "foo")
400
- end
401
- assert_raises Couchbase::Error::KeyExists do
402
- connection.set(uniq_id(2), "foo")
403
- end
404
- else
405
- skip("implement GETL in CouchbaseMock.jar")
354
+ cb.set(uniq_id(1), "foo1")
355
+ cb.set(uniq_id(2), "foo2")
356
+ expected = {uniq_id(1) => "foo1", uniq_id(2) => "foo2"}
357
+ assert_equal expected, cb.get({uniq_id(1) => 1, uniq_id(2) => 2}, :lock => true)
358
+ assert_raises Couchbase::Error::KeyExists do
359
+ cb.set(uniq_id(1), "foo")
360
+ end
361
+ assert_raises Couchbase::Error::KeyExists do
362
+ cb.set(uniq_id(2), "foo")
406
363
  end
407
364
  end
408
365
 
409
366
  def test_multi_get_result_hash_assembling
410
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
411
- connection.set(uniq_id(1), "foo")
412
- connection.set(uniq_id(2), "bar")
367
+ cb.set(uniq_id(1), "foo")
368
+ cb.set(uniq_id(2), "bar")
413
369
 
414
370
  expected = {uniq_id(1) => "foo", uniq_id(2) => "bar"}
415
- assert_equal expected, connection.get(uniq_id(1), uniq_id(2), :assemble_hash => true)
371
+ assert_equal expected, cb.get(uniq_id(1), uniq_id(2), :assemble_hash => true)
416
372
  end
417
373
  end
@@ -0,0 +1,23 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require File.join(File.dirname(__FILE__), 'setup')
19
+
20
+ class TestQuery < MiniTest::Test
21
+
22
+
23
+ end
data/test/test_stats.rb CHANGED
@@ -19,39 +19,24 @@ require File.join(File.dirname(__FILE__), 'setup')
19
19
 
20
20
  class TestStats < MiniTest::Test
21
21
 
22
- def setup
23
- @mock = start_mock(:num_nodes => 4)
24
- end
25
-
26
- def teardown
27
- stop_mock(@mock)
28
- end
29
-
30
22
  def test_trivial_stats_without_argument
31
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
- stats = connection.stats
23
+ stats = cb.stats
33
24
  assert stats.is_a?(Hash)
34
25
  assert stats.has_key?("pid")
35
26
  key, info = stats.first
36
27
  assert key.is_a?(String)
37
28
  assert info.is_a?(Hash)
38
- assert_equal @mock.num_nodes, info.size
29
+ assert_equal 1, info.size
39
30
  end
40
31
 
41
32
  def test_stats_with_argument
42
- if @mock.real?
43
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
44
- stats = connection.stats("memory")
45
- assert stats.is_a?(Hash)
46
- assert stats.has_key?("mem_used")
47
- key, info = stats.first
48
- assert key.is_a?(String)
49
- assert info.is_a?(Hash)
50
- assert_equal @mock.num_nodes, info.size
51
- else
52
- # FIXME
53
- skip("make CouchbaseMock.jar STATS more real-life")
54
- end
33
+ stats = cb.stats("memory")
34
+ assert stats.is_a?(Hash)
35
+ assert stats.has_key?("mem_used")
36
+ key, info = stats.first
37
+ assert key.is_a?(String)
38
+ assert info.is_a?(Hash)
39
+ assert_equal 1, info.size
55
40
  end
56
41
 
57
42
  end