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 +4 -4
- data/README.md +153 -142
- data/Rakefile +0 -1
- data/couchbase-jruby-client.gemspec +1 -0
- data/lib/couchbase/bucket.rb +5 -9
- data/lib/couchbase/operations/fetch.rb +3 -2
- data/lib/couchbase/operations/store.rb +3 -3
- data/lib/couchbase/operations/utils.rb +1 -1
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase.rb +13 -7
- data/tasks/test.rake +10 -8
- data/test/setup.rb +9 -8
- data/test/test_delete.rb +5 -2
- data/test/test_fetch.rb +21 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bccd5819d83c3e1493076d252d676a36fe311f
|
4
|
+
data.tar.gz: ca2c16285b9d3fc2672d6af3467db5a14d19b8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
##
|
24
|
+
## Caveats
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
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
|
51
|
+
therefore this client is 'smart'.
|
48
52
|
|
49
|
-
|
53
|
+
```ruby
|
54
|
+
c = Couchbase.connect
|
55
|
+
```
|
50
56
|
|
51
57
|
This is equivalent to following forms:
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
73
|
+
list, because node list from cluster config is more accurate.
|
66
74
|
|
67
|
-
|
68
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
123
|
+
```ruby
|
124
|
+
c['foo']
|
125
|
+
c['foo', 'bar', 'baz']
|
126
|
+
c['foo', extended: true]
|
127
|
+
```
|
117
128
|
|
118
129
|
### Touch
|
119
130
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
142
|
-
|
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
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
202
|
-
|
207
|
+
```ruby
|
208
|
+
c['foo'] = 10
|
209
|
+
c['foo'] -= 20 #=> -10
|
210
|
+
```
|
203
211
|
|
204
212
|
### Delete
|
205
213
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
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
|
-
|
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
|
288
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mje113/couchbase-jruby-client/trend.png)](https://bitdeli.com/free 'Bitdeli Badge')
|
278
289
|
|
data/Rakefile
CHANGED
data/lib/couchbase/bucket.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/couchbase/version.rb
CHANGED
data/lib/couchbase.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
unless RUBY_PLATFORM =~ /java/
|
19
|
-
|
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
|
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.
|
172
|
-
|
173
|
-
bucket.disconnect
|
174
|
+
@@buckets.each_pair do |bucket, connection|
|
175
|
+
connection.disconnect if connection.connected?
|
174
176
|
end
|
175
|
-
@@
|
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
|
-
|
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
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
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 -
|
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.
|
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-
|
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.
|
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.
|