couchbase-jruby-client 0.1.9-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ff8556640816f6cb67c87afb0aaeb5fc7001f2f
4
- data.tar.gz: 08314e3ea7bec37d1010bad128a106fb61c73127
3
+ metadata.gz: 71bccd5819d83c3e1493076d252d676a36fe311f
4
+ data.tar.gz: ca2c16285b9d3fc2672d6af3467db5a14d19b8ca
5
5
  SHA512:
6
- metadata.gz: 1c6218643d51c032b95aad0cb00944c617eb79c753fe095a4ae8f909be2ceb83e838aa629f9da3751a97862c9e1b18b645fd017bd88f9297f529aed6e74141ad
7
- data.tar.gz: 46970dc0dcf1342ff99982058d5b768c28f3d57b66b4bd93d8f1732b5bf96146b094d13914bd06222b6d6e3507a34d27483c875f9a5b280c1dccac8a17b109d1
6
+ metadata.gz: df3f4ddb4342333fe81bc7ed140b934cefcd4f3ce3d5e204c1b3409b88ebe2c7eb7baed3380fe8d11bc8f7efd2682021664f721e6ac4d0fb1d0184a3871af6ae
7
+ data.tar.gz: e557ddfa428849542ea131d55d98ac3a0280d367dfd46624391e6402f564932040e4afd73f5ee6070418b6588cb461fee3d10f62be32711a11a56e7deb91c717
data/README.md CHANGED
@@ -5,8 +5,7 @@
5
5
  [![Coverage Status](https://coveralls.io/repos/mje113/couchbase-jruby-client/badge.png)](https://coveralls.io/r/mje113/couchbase-jruby-client)
6
6
  [![Dependency Status](https://gemnasium.com/mje113/couchbase-jruby-client.png)](https://gemnasium.com/mje113/couchbase-jruby-client)
7
7
 
8
- Attempt to recreate the ruby Couchbase client api in JRuby and the
9
- Couchbase Java SDK.
8
+ JRuby wrapper of the Couchbase Java SDK that attempts to adhere to Ruby client API.
10
9
 
11
10
  ## Installation
12
11
 
@@ -22,14 +21,17 @@ Or install it yourself as:
22
21
 
23
22
  $ gem install couchbase-jruby-client
24
23
 
25
- ## Caveat
24
+ ## Caveats
26
25
 
27
- Please consider this project a very incomplete "alpha" version at best. I'm getting close
28
- to full coverage, though there are still some missing features. In fact, as I've gotten
29
- more familiar with the differences between the native ruby api and the java, there are
30
- definitely some features that don't make sense to implement.
26
+ Do to the very different approaches that the Ruby and Java SDKs take, 100% compatibility with the Ruby
27
+ API isn't practical. That said, enough compatibility exists today for the couchbase-ruby-model gem
28
+ to function properly.
31
29
 
32
- Ultimately hoping to get to 100% support of the couchbase-ruby-model gem.
30
+ * Since the original [couchbase-ruby-model](https://github.com/couchbase/couchbase-ruby-model) gem has a dependency
31
+ on the ruby client, use my fork instead: [couchbase-jruby-model](https://github.com/mje113/couchbase-jruby-model).
32
+ * The ruby client async `run` blocks aren't supported as they were not truly asynchronous (the code executed within
33
+ the block uses libcouchbase's async calls, but the clock itself blocks until everything is complete).
34
+ * The Java SDK's aysnc methods are exposed to truly async operations and registered callbacks.
33
35
 
34
36
  ## Usage
35
37
 
@@ -38,115 +40,129 @@ they are largely the same. Important bits copied below:
38
40
 
39
41
  First of all you need to load library:
40
42
 
41
- require 'couchbase'
43
+ ```ruby
44
+ require 'couchbase'
45
+ ```
42
46
 
43
47
  There are several ways to establish new connection to Couchbase Server.
44
48
  By default it uses the `http://localhost:8091/pools/default/buckets/default`
45
49
  as the endpoint. The client will automatically adjust configuration when
46
50
  the cluster will rebalance its nodes when nodes are added or deleted
47
- therefore this client is "smart".
51
+ therefore this client is 'smart'.
48
52
 
49
- c = Couchbase.connect
53
+ ```ruby
54
+ c = Couchbase.connect
55
+ ```
50
56
 
51
57
  This is equivalent to following forms:
52
58
 
53
- c = Couchbase.connect("http://localhost:8091/pools/default/buckets/default")
54
- c = Couchbase.connect("http://localhost:8091/pools/default")
55
- c = Couchbase.connect("http://localhost:8091")
56
- c = Couchbase.connect(:hostname => "localhost")
57
- c = Couchbase.connect(:hostname => "localhost", :port => 8091)
58
- c = Couchbase.connect(:pool => "default", :bucket => "default")
59
+ ```ruby
60
+ c = Couchbase.connect('http://localhost:8091/pools/default/buckets/default')
61
+ c = Couchbase.connect('http://localhost:8091/pools/default')
62
+ c = Couchbase.connect('http://localhost:8091')
63
+ c = Couchbase.connect(:hostname => 'localhost')
64
+ c = Couchbase.connect(:hostname => 'localhost', :port => 8091)
65
+ c = Couchbase.connect(:pool => 'default', :bucket => 'default')
66
+ ```
59
67
 
60
68
  The hash parameters take precedence on string URL.
61
69
 
62
70
  If you worry about state of your nodes or not sure what node is alive,
63
71
  you can pass the list of nodes and the library will iterate over it
64
72
  until finds the working one. From that moment it won't use **your**
65
- list, because node list from cluster config is more actual.
73
+ list, because node list from cluster config is more accurate.
66
74
 
67
- c = Couchbase.connect(:bucket => "mybucket",
68
- :node_list => ['example.com:8091', example.net'])
75
+ ```ruby
76
+ c = Couchbase.connect(:bucket => 'mybucket',
77
+ :node_list => ['example.com:8091', example.net'])
78
+ ```
69
79
 
70
80
  There is also handy method `Couchbase.bucket` which uses thread local
71
81
  storage to keep the reference to default connection. You can set the
72
82
  connection options via `Couchbase.connection_options`:
73
83
 
74
- Couchbase.connection_options = {:bucket => 'blog'}
75
- Couchbase.bucket.name #=> "blog"
76
- Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
84
+ ```ruby
85
+ Couchbase.connection_options = { bucket: 'blog' }
86
+ Couchbase.bucket.name #=> 'blog'
87
+ Couchbase.bucket.set('foo', 'bar') #=> 3289400178357895424
88
+ ```
77
89
 
78
90
  ### Get
79
91
 
80
- val = c.get("foo")
81
- val, flags, cas = c.get("foo", :extended => true)
92
+ ```ruby
93
+ val = c.get('foo')
94
+ val, flags, cas = c.get('foo', extended: true)
95
+ ```
82
96
 
83
97
  Get and touch
84
98
 
85
- val = c.get("foo", :ttl => 10)
99
+ ```ruby
100
+ val = c.get('foo', :ttl => 10)
101
+ ```
86
102
 
87
103
  Get multiple values. In quiet mode will put `nil` values on missing
88
104
  positions:
89
105
 
90
- vals = c.get("foo", "bar", "baz")
91
- val_foo, val_bar, val_baz = c.get("foo", "bar", "baz")
92
- c.run do
93
- c.get("foo") do |ret|
94
- ret.success?
95
- ret.error
96
- ret.key
97
- ret.value
98
- ret.flags
99
- ret.cas
100
- end
101
- end
106
+ ```ruby
107
+ vals = c.get('foo', 'bar', 'baz')
108
+ val_foo, val_bar, val_baz = c.get('foo', 'bar', 'baz')
109
+ ```
102
110
 
103
111
  Get multiple values with extended information. The result will
104
112
  represented by hash with tuples `[value, flags, cas]` as a value.
105
113
 
106
- vals = c.get("foo", "bar", "baz", :extended => true)
107
- vals.inspect #=> {"baz"=>["3", 0, 4784582192793125888],
108
- "foo"=>["1", 0, 8835713818674332672],
109
- "bar"=>["2", 0, 10805929834096100352]}
114
+ ```ruby
115
+ vals = c.get('foo', 'bar', 'baz', extended: true)
116
+ vals.inspect #=> {'baz'=>['3', 0, 4784582192793125888],
117
+ 'foo'=>['1', 0, 8835713818674332672],
118
+ 'bar'=>['2', 0, 10805929834096100352]}
119
+ ```
110
120
 
111
121
  Hash-like syntax
112
122
 
113
- c["foo"]
114
- c["foo", "bar", "baz"]
115
- c["foo", {:extended => true}]
116
- c["foo", :extended => true] # for ruby 1.9.x only
123
+ ```ruby
124
+ c['foo']
125
+ c['foo', 'bar', 'baz']
126
+ c['foo', extended: true]
127
+ ```
117
128
 
118
129
  ### Touch
119
130
 
120
- c.touch("foo") # use :default_ttl
121
- c.touch("foo", 10)
122
- c.touch("foo", :ttl => 10)
123
- c.touch("foo" => 10, "bar" => 20)
124
- c.touch("foo" => 10, "bar" => 20){|key, success| }
131
+ ```ruby
132
+ c.touch('foo') # use :default_ttl
133
+ c.touch('foo', 10)
134
+ c.touch('foo', ttl: 10)
135
+ c.touch('foo' => 10, 'bar' => 20)
136
+ ```
125
137
 
126
138
  ### Set
127
139
 
128
- c.set("foo", "bar")
129
- c.set("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
130
- c["foo"] = "bar"
131
- c["foo", {:flags => 0x1000, :format => :plain}] = "bar"
132
- c["foo", :flags => 0x1000] = "bar" # for ruby 1.9.x only
133
- c.set("foo", "bar", :cas => 8835713818674332672)
134
- c.set("foo", "bar"){|cas, key, operation| }
140
+ ```ruby
141
+ c.set('foo', 'bar')
142
+ c.set('foo', 'bar', ttl: 30, format: :plain)
143
+ c['foo'] = 'bar'
144
+ c['foo', format: :plain}] = 'bar'
145
+ c.set('foo', 'bar', cas: 8835713818674332672)
146
+ ```
135
147
 
136
148
  ### Add
137
149
 
138
150
  Add command will fail if the key already exists. It accepts the same
139
151
  options as set command above.
140
152
 
141
- c.add("foo", "bar")
142
- c.add("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
153
+ ```ruby
154
+ c.add('foo', 'bar')
155
+ c.add('foo', 'bar', ttl: 30, format: :plain)
156
+ ```
143
157
 
144
158
  ### Replace
145
159
 
146
160
  The replace command will fail if the key already exists. It accepts the same
147
161
  options as set command above.
148
162
 
149
- c.replace("foo", "bar")
163
+ ```ruby
164
+ c.replace('foo', 'bar')
165
+ ```
150
166
 
151
167
  ### Prepend/Append
152
168
 
@@ -155,115 +171,110 @@ because the concatenation is performed by server which has no idea how
155
171
  to merge to JSON values or values in ruby Marshal format. You may receive
156
172
  an `Couchbase::Error::ValueFormat` error.
157
173
 
158
- c.set("foo", "world")
159
- c.append("foo", "!")
160
- c.prepend("foo", "Hello, ")
161
- c.get("foo") #=> "Hello, world!"
174
+ ```ruby
175
+ c.set('foo', 'world')
176
+ c.append('foo', '!')
177
+ c.prepend('foo', 'Hello, ')
178
+ c.get('foo') #=> 'Hello, world!'
179
+ ```
162
180
 
163
181
  ### Increment/Decrement
164
182
 
165
183
  These commands increment the value assigned to the key. It will raise
166
184
  Couchbase::Error::DeltaBadval if the delta or value is not a number.
167
185
 
168
- c.set("foo", 1)
169
- c.incr("foo") #=> 2
170
- c.incr("foo", :delta => 2) #=> 4
171
- c.incr("foo", 4) #=> 8
172
- c.incr("foo", -1) #=> 7
173
- c.incr("foo", -100) #=> 0
174
- c.run do
175
- c.incr("foo") do |ret|
176
- ret.success?
177
- ret.value
178
- ret.cas
179
- end
180
- end
181
-
182
- c.set("foo", 10)
183
- c.decr("foo", 1) #=> 9
184
- c.decr("foo", 100) #=> 0
185
- c.run do
186
- c.decr("foo") do |ret|
187
- ret.success?
188
- ret.value
189
- ret.cas
190
- end
191
- end
192
-
193
- c.incr("missing1", :initial => 10) #=> 10
194
- c.incr("missing1", :initial => 10) #=> 11
195
- c.incr("missing2", :create => true) #=> 0
196
- c.incr("missing2", :create => true) #=> 1
186
+ ```ruby
187
+ c.set('foo', 1)
188
+ c.incr('foo') #=> 2
189
+ c.incr('foo', delta: 2) #=> 4
190
+ c.incr('foo', 4) #=> 8
191
+ c.incr('foo', -1) #=> 7
192
+ c.incr('foo', -100) #=> 0
193
+
194
+ c.set('foo', 10)
195
+ c.decr('foo', 1) #=> 9
196
+ c.decr('foo', 100) #=> 0
197
+
198
+ c.incr('missing1', :initial => 10) #=> 10
199
+ c.incr('missing1', :initial => 10) #=> 11
200
+ c.incr('missing2', :create => true) #=> 0
201
+ c.incr('missing2', :create => true) #=> 1
202
+ ```
197
203
 
198
204
  Note that it isn't the same as increment/decrement in ruby, which is
199
205
  performed on client side with following `set` operation:
200
206
 
201
- c["foo"] = 10
202
- c["foo"] -= 20 #=> -10
207
+ ```ruby
208
+ c['foo'] = 10
209
+ c['foo'] -= 20 #=> -10
210
+ ```
203
211
 
204
212
  ### Delete
205
213
 
206
- c.delete("foo")
207
- c.delete("foo", :cas => 8835713818674332672)
208
- c.delete("foo", 8835713818674332672)
209
- c.run do
210
- c.delete do |ret|
211
- ret.success?
212
- ret.key
213
- end
214
- end
214
+ ```ruby
215
+ c.delete('foo')
216
+ c.delete('foo', :cas => 8835713818674332672)
217
+ c.delete('foo', 8835713818674332672)
218
+ ```
215
219
 
216
220
  ### Flush
217
221
 
218
222
  Flush the items in the cluster.
219
223
 
220
- c.flush
221
- c.run do
222
- c.flush do |ret|
223
- ret.success?
224
- ret.node
225
- end
226
- end
224
+ ```ruby
225
+ c.flush
226
+ ```
227
227
 
228
228
  ### Stats
229
229
 
230
230
  Return statistics from each node in the cluster
231
231
 
232
- c.stats
233
- c.stats(:memory)
234
- c.run do
235
- c.stats do |ret|
236
- ret.success?
237
- ret.node
238
- ret.key
239
- ret.value
240
- end
241
- end
232
+ ```ruby
233
+ c.stats
234
+ c.stats(:memory)
235
+ ```
242
236
 
243
237
  The result is represented as a hash with the server node address as
244
238
  the key and stats as key-value pairs.
245
239
 
240
+ ```ruby
241
+ {
242
+ 'threads'=>
243
+ {
244
+ '172.16.16.76:12008'=>'4',
245
+ '172.16.16.76:12000'=>'4',
246
+ # ...
247
+ },
248
+ 'connection_structures'=>
249
+ {
250
+ '172.16.16.76:12008'=>'22',
251
+ '172.16.16.76:12000'=>'447',
252
+ # ...
253
+ },
254
+ 'ep_max_txn_size'=>
246
255
  {
247
- "threads"=>
248
- {
249
- "172.16.16.76:12008"=>"4",
250
- "172.16.16.76:12000"=>"4",
251
- # ...
252
- },
253
- "connection_structures"=>
254
- {
255
- "172.16.16.76:12008"=>"22",
256
- "172.16.16.76:12000"=>"447",
257
- # ...
258
- },
259
- "ep_max_txn_size"=>
260
- {
261
- "172.16.16.76:12008"=>"1000",
262
- "172.16.16.76:12000"=>"1000",
263
- # ...
264
- },
256
+ '172.16.16.76:12008'=>'1000',
257
+ '172.16.16.76:12000'=>'1000',
265
258
  # ...
266
- }
259
+ },
260
+ # ...
261
+ }
262
+ ```
263
+
264
+ ### Async Operations
265
+
266
+ Most synchronous operations detailed above have an asynchronous counterpart. Async operations
267
+ optionally accept a block that will be used as a callback when the operations completes. The
268
+ block will be run within the context of a net.spy.memcached.internal.OperationCompletionListener, ie. a
269
+ separate thread, so make sure you adhere to all the
270
+ [typical guidelines for threadsafety](https://github.com/jruby/jruby/wiki/Concurrency-in-jruby#concurrency-basics).
271
+
272
+ ```ruby
273
+ c.set('fu', 'bar')
274
+ c.async_get('fu') do |result| # => yields a Result instance
275
+ result.value # => 'bar'
276
+ end
277
+ ```
267
278
 
268
279
  ## Contributing
269
280
 
@@ -274,5 +285,5 @@ the key and stats as key-value pairs.
274
285
  5. Create new Pull Request
275
286
 
276
287
 
277
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mje113/couchbase-jruby-client/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
288
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mje113/couchbase-jruby-client/trend.png)](https://bitdeli.com/free 'Bitdeli Badge')
278
289
 
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
2
 
4
3
  Dir['tasks/*.rake'].sort.each { |f| load f }
5
4
 
@@ -27,4 +27,5 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'minitest', '>= 5.1.0'
28
28
  s.add_development_dependency 'jrjackson', '>= 0.2.3'
29
29
  s.add_development_dependency 'pry'
30
+ s.add_development_dependency 'mocha'
30
31
  end
@@ -333,16 +333,12 @@ module Couchbase
333
333
  # @example Simple flush the bucket
334
334
  # c.flush #=> true
335
335
  #
336
- # @example Asynchronous flush
337
- # c.run do
338
- # c.flush do |ret|
339
- # ret.operation #=> :flush
340
- # ret.success? #=> true
341
- # ret.status #=> 200
342
- # end
343
- # end
344
336
  def flush
345
- @client.flush.get
337
+ async_flush.get
338
+ end
339
+
340
+ def async_flush
341
+ @client.flush
346
342
  end
347
343
 
348
344
  private
@@ -20,10 +20,11 @@
20
20
  module Couchbase::Operations
21
21
  module Fetch
22
22
 
23
- def fetch(key, set_options = {}, &block)
23
+ def fetch(key, set_options = {}, get_options = {}, &block)
24
24
  fail ArgumentError 'Must pass a block to #fetch' unless block_given?
25
25
 
26
- get(key, quiet: false)
26
+ get_options[:quiet] = false
27
+ get(key, get_options)
27
28
  rescue Couchbase::Error::NotFound
28
29
  yield(block).tap {|value| set(key, value, set_options) }
29
30
  end
@@ -25,9 +25,9 @@ module Couchbase::Operations
25
25
  module Store
26
26
 
27
27
  STORE_OP_METHODS = {
28
- set: -> client, key, value, ttl, transcoder { client.set(key, ttl, value, transcoder) },
29
- add: -> client, key, value, ttl, transcoder { client.add(key, ttl, value, transcoder) },
30
- replace: -> client, key, value, ttl, transcoder { client.replace(key, ttl, value, transcoder) },
28
+ set: -> client, key, value, ttl, transcoder { client.set(key, ttl.to_i, value, transcoder) },
29
+ add: -> client, key, value, ttl, transcoder { client.add(key, ttl.to_i, value, transcoder) },
30
+ replace: -> client, key, value, ttl, transcoder { client.replace(key, ttl.to_i, value, transcoder) },
31
31
  append: -> client, key, value, ttl, transcoder { client.append(key, value, transcoder) },
32
32
  prepend: -> client, key, value, ttl, transcoder { client.prepend(key, value, transcoder) }
33
33
  }.freeze
@@ -47,7 +47,7 @@ module Couchbase::Operations
47
47
  end
48
48
 
49
49
  def future_cas(future)
50
- future.get && future.getCas
50
+ future.get && future.cas
51
51
  rescue Java::JavaLang::UnsupportedOperationException
52
52
  # TODO: don't return fake cas
53
53
  1
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module Couchbase
19
- VERSION = '0.1.9'
19
+ VERSION = '0.2.0'
20
20
  end
data/lib/couchbase.rb CHANGED
@@ -16,7 +16,7 @@
16
16
  #
17
17
 
18
18
  unless RUBY_PLATFORM =~ /java/
19
- error "This gem is only compatible with a java-based ruby environment like JRuby."
19
+ fail "This gem is only compatible with a java-based ruby environment like JRuby."
20
20
  exit 255
21
21
  end
22
22
 
@@ -55,7 +55,8 @@ end
55
55
  # Couchbase jruby client
56
56
  module Couchbase
57
57
 
58
- @@buckets = ThreadSafe::Cache.new
58
+ @@buckets = ThreadSafe::Cache.new
59
+ @@connections = ThreadSafe::Array.new
59
60
 
60
61
  class << self
61
62
 
@@ -82,7 +83,9 @@ module Couchbase
82
83
  #
83
84
  # @return [Bucket] connection instance
84
85
  def connect(*options)
85
- Bucket.new(*(options.flatten))
86
+ bucket = Bucket.new(*(options.flatten))
87
+ @@connections << bucket
88
+ bucket
86
89
  end
87
90
  alias :new :connect
88
91
 
@@ -168,11 +171,14 @@ module Couchbase
168
171
  end
169
172
 
170
173
  def disconnect
171
- @@buckets.each_key do |name|
172
- bucket = @@buckets.delete(name)
173
- bucket.disconnect
174
+ @@buckets.each_pair do |bucket, connection|
175
+ connection.disconnect if connection.connected?
174
176
  end
175
- @@buckets = ThreadSafe::Cache.new
177
+ @@connections.each do |connection|
178
+ connection.disconnect if connection.connected?
179
+ end
180
+ @@buckets = ThreadSafe::Cache.new
181
+ @@connections = ThreadSafe::Array.new
176
182
  end
177
183
  end
178
184
  end
data/tasks/test.rake CHANGED
@@ -15,20 +15,22 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
- require 'rake/testtask'
19
- require 'rake/clean'
20
-
21
18
  rule 'test/CouchbaseMock.jar' do |task|
22
19
  jar_path = "0.6-SNAPSHOT/CouchbaseMock-0.6-20130903.160518-3.jar"
23
20
  sh %{wget -q -O test/CouchbaseMock.jar http://files.couchbase.com/maven2/org/couchbase/mock/CouchbaseMock/#{jar_path}}
24
21
  end
25
22
 
26
- CLOBBER << 'test/CouchbaseMock.jar'
23
+ task :test do
24
+ $LOAD_PATH.unshift('lib', 'test')
25
+
26
+ if ENV['TEST']
27
+ require ENV['TEST']
28
+ else
29
+ Dir.glob('./test/**/test_*.rb') { |f| require f }
30
+ end
27
31
 
28
- Rake::TestTask.new(:test) do |test|
29
- test.libs << 'test'
30
- test.pattern = 'test/**/test_*.rb'
31
- test.verbose = true
32
+ require 'test/setup.rb'
32
33
  end
33
34
 
34
35
  Rake::Task['test'].prerequisites.unshift('test/CouchbaseMock.jar')
36
+
data/test/setup.rb CHANGED
@@ -19,6 +19,8 @@ gem 'minitest'
19
19
  require 'coveralls'
20
20
  Coveralls.wear!
21
21
  require 'minitest'
22
+ gem 'mocha'
23
+ require 'mocha/setup'
22
24
  require 'couchbase'
23
25
  require 'open-uri'
24
26
  require 'ostruct'
@@ -63,11 +65,10 @@ class Minitest::Test
63
65
 
64
66
  end
65
67
 
66
- $mock = start_mock
67
-
68
- Dir.glob('test/test_*.rb').each { |test| require test }
69
- exit_code = Minitest.run(ARGV)
70
- Couchbase.disconnect
71
- $mock.stop
72
- java.lang.System.exit(exit_code ? 0 : 1)
73
-
68
+ at_exit {
69
+ $mock = start_mock
70
+ exit_code = Minitest.run(ARGV)
71
+ Couchbase.disconnect
72
+ $mock.stop
73
+ java.lang.System.exit(exit_code ? 0 : 1)
74
+ }
data/test/test_delete.rb CHANGED
@@ -21,7 +21,8 @@ class TestDelete < Minitest::Test
21
21
 
22
22
  def test_trivial_delete
23
23
  cb.set(uniq_id, "bar")
24
- assert cas = cb.delete(uniq_id)
24
+ cas = cb.delete(uniq_id)
25
+ assert cas
25
26
 
26
27
  assert_raises(Couchbase::Error::NotFound) do
27
28
  cb.delete(uniq_id)
@@ -49,11 +50,13 @@ class TestDelete < Minitest::Test
49
50
  refute cb.quiet?
50
51
  cb.quiet = true
51
52
  refute cb.delete(uniq_id(:missing))
53
+ ensure
54
+ cb.quiet = false
52
55
  end
53
56
 
54
57
  def test_delete_with_cas
55
58
  cas = cb.set(uniq_id, "bar")
56
- missing_cas = cas - 1
59
+ missing_cas = cas - 100
57
60
  assert_raises(Couchbase::Error::NotFound) do
58
61
  cb.delete(uniq_id, :cas => missing_cas)
59
62
  end
data/test/test_fetch.rb CHANGED
@@ -37,6 +37,27 @@ class TestFetch < Minitest::Test
37
37
  assert_equal 'abc', cb.get(uniq_id)
38
38
  end
39
39
 
40
+ def test_can_include_get_options
41
+ cb.set(uniq_id, 'abc')
42
+
43
+ get_options = { extended: true }
44
+ value, _, cas = cb.fetch(uniq_id, {}, get_options) do
45
+ 'unused'
46
+ end
47
+
48
+ assert_equal value, 'abc'
49
+ assert cas.is_a?(Fixnum)
50
+ end
51
+
52
+ def test_can_include_set_options
53
+ set_options = { ttl: 1 }
54
+
55
+ cb.expects(:set).with(uniq_id, 'abc', set_options)
56
+ cb.fetch(uniq_id, set_options) do
57
+ 'abc'
58
+ end
59
+ end
60
+
40
61
  def test_fetch_works_with_quiet_mode
41
62
  cb.quiet = true
42
63
  cb.fetch(uniq_id) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-jruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Mike Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -108,6 +108,20 @@ dependencies:
108
108
  version: '0'
109
109
  prerelease: false
110
110
  type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ prerelease: false
124
+ type: :development
111
125
  description: Couchbase JRuby driver
112
126
  email:
113
127
  - mike@urlgonomics.com
@@ -214,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
228
  version: '0'
215
229
  requirements: []
216
230
  rubyforge_project:
217
- rubygems_version: 2.1.9
231
+ rubygems_version: 2.2.2
218
232
  signing_key:
219
233
  specification_version: 4
220
234
  summary: The unofficial jruby client library for use with Couchbase Server.