couchbase-jruby-client 0.2.2-java → 1.0.4-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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +103 -0
  3. data/.ruby-version +1 -1
  4. data/Rakefile +13 -2
  5. data/couchbase-jruby-client.gemspec +7 -6
  6. data/lib/couchbase/bucket.rb +11 -338
  7. data/lib/couchbase/cluster.rb +10 -88
  8. data/lib/couchbase/configuration.rb +39 -0
  9. data/lib/couchbase/design_doc.rb +18 -73
  10. data/lib/couchbase/document.rb +34 -0
  11. data/lib/couchbase/error.rb +0 -35
  12. data/lib/couchbase/operations.rb +60 -40
  13. data/lib/couchbase/version.rb +1 -1
  14. data/lib/couchbase/view.rb +55 -345
  15. data/lib/couchbase.rb +37 -141
  16. data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
  17. data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
  18. data/lib/jars/rxjava-1.0.8.jar +0 -0
  19. data/lib/jars/rxjruby-0.0.1.jar +0 -0
  20. data/test/{test_cas.rb → helper.rb} +15 -10
  21. data/test/test_bucket.rb +14 -228
  22. data/test/test_cluster.rb +1 -29
  23. data/test/test_configuration.rb +51 -0
  24. data/test/test_couchbase.rb +28 -28
  25. data/test/test_design_doc.rb +29 -0
  26. data/test/test_document.rb +51 -0
  27. data/test/test_operations.rb +49 -0
  28. data/test/test_view.rb +62 -116
  29. metadata +43 -125
  30. data/lib/couchbase/async/callback.rb +0 -38
  31. data/lib/couchbase/async/queue.rb +0 -26
  32. data/lib/couchbase/async.rb +0 -32
  33. data/lib/couchbase/constants.rb +0 -29
  34. data/lib/couchbase/operations/arithmetic.rb +0 -290
  35. data/lib/couchbase/operations/delete.rb +0 -115
  36. data/lib/couchbase/operations/design_docs.rb +0 -99
  37. data/lib/couchbase/operations/fetch.rb +0 -33
  38. data/lib/couchbase/operations/get.rb +0 -303
  39. data/lib/couchbase/operations/stats.rb +0 -42
  40. data/lib/couchbase/operations/store.rb +0 -463
  41. data/lib/couchbase/operations/touch.rb +0 -140
  42. data/lib/couchbase/operations/unlock.rb +0 -209
  43. data/lib/couchbase/operations/utils.rb +0 -68
  44. data/lib/couchbase/query.rb +0 -76
  45. data/lib/couchbase/result.rb +0 -60
  46. data/lib/couchbase/transcoder.rb +0 -81
  47. data/lib/couchbase/utils.rb +0 -62
  48. data/lib/couchbase/view_row.rb +0 -227
  49. data/lib/jars/commons-codec-1.5.jar +0 -0
  50. data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
  51. data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
  52. data/lib/jars/couchbase-client-1.3.2.jar +0 -0
  53. data/lib/jars/httpcore-4.3.1.jar +0 -0
  54. data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
  55. data/lib/jars/jettison-1.1.jar +0 -0
  56. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  57. data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
  58. data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
  59. data/lib/jars/spymemcached-2.10.5.jar +0 -0
  60. data/tasks/benchmark.rake +0 -6
  61. data/tasks/test.rake +0 -36
  62. data/tasks/util.rake +0 -21
  63. data/test/mock.rb +0 -85
  64. data/test/profile/.gitignore +0 -1
  65. data/test/profile/.jrubyrc +0 -722
  66. data/test/profile/Gemfile +0 -7
  67. data/test/profile/benchmark.rb +0 -177
  68. data/test/profile/profile.rb +0 -59
  69. data/test/setup.rb +0 -74
  70. data/test/test_arithmetic.rb +0 -155
  71. data/test/test_async.rb +0 -24
  72. data/test/test_couchbase_rails_cache_store.rb +0 -341
  73. data/test/test_delete.rb +0 -139
  74. data/test/test_design_docs.rb +0 -67
  75. data/test/test_errors.rb +0 -74
  76. data/test/test_fetch.rb +0 -71
  77. data/test/test_format.rb +0 -142
  78. data/test/test_get.rb +0 -363
  79. data/test/test_query.rb +0 -23
  80. data/test/test_result.rb +0 -15
  81. data/test/test_stats.rb +0 -44
  82. data/test/test_store.rb +0 -203
  83. data/test/test_touch.rb +0 -90
  84. data/test/test_unlock.rb +0 -89
  85. data/test/test_utils.rb +0 -67
  86. data/test/test_version.rb +0 -28
  87. data/test/test_view_row.rb +0 -74
@@ -1,290 +0,0 @@
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
- module Couchbase::Operations
19
- module Arithmetic
20
-
21
- # Increment the value of an existing numeric key
22
- #
23
- # @since 1.0.0
24
- #
25
- # The increment methods allow you to increase a given stored integer
26
- # value. These are the incremental equivalent of the decrement operations
27
- # and work on the same basis; updating the value of a key if it can be
28
- # parsed to an integer. The update operation occurs on the server and is
29
- # provided at the protocol level. This simplifies what would otherwise be a
30
- # two-stage get and set operation.
31
- #
32
- # @note that server values stored and transmitted as unsigned numbers,
33
- # therefore if you try to store negative number and then increment or
34
- # decrement it will cause overflow. (see "Integer overflow" example
35
- # below)
36
- #
37
- # @overload incr(key, delta = 1, options = {})
38
- # @param key [String, Symbol] Key used to reference the value.
39
- # @param delta [Fixnum] Integer (up to 64 bits) value to increment
40
- # @param options [Hash] Options for operation.
41
- # @option options [true, false] :create (false) If set to +true+, it will
42
- # initialize the key with zero value and zero flags (use +:initial+
43
- # option to set another initial value). Note: it won't increment the
44
- # missing value.
45
- # @option options [Fixnum] :initial (0) Integer (up to 64 bits) value for
46
- # missing key initialization. This option imply +:create+ option is
47
- # +true+.
48
- # @option options [Fixnum] :ttl (self.default_ttl) Expiry time for key.
49
- # Values larger than 30*24*60*60 seconds (30 days) are interpreted as
50
- # absolute times (from the epoch). This option ignored for existent
51
- # keys.
52
- # @option options [true, false] :extended (false) If set to +true+, the
53
- # operation will return tuple +[value, cas]+, otherwise (by default) it
54
- # returns just value.
55
- #
56
- # @yieldparam ret [Result] the result of operation in asynchronous mode
57
- # (valid attributes: +error+, +operation+, +key+, +value+, +cas+).
58
- #
59
- # @return [Fixnum] the actual value of the key.
60
- #
61
- # @raise [Couchbase::Error::NotFound] if key is missing and +:create+
62
- # option isn't +true+.
63
- #
64
- # @raise [Couchbase::Error::DeltaBadval] if the key contains non-numeric
65
- # value
66
- #
67
- # @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
68
- #
69
- # @raise [ArgumentError] when passing the block in synchronous mode
70
- #
71
- # @example Increment key by one
72
- # c.incr("foo")
73
- #
74
- # @example Increment key by 50
75
- # c.incr("foo", 50)
76
- #
77
- # @example Increment key by one <b>OR</b> initialize with zero
78
- # c.incr("foo", :create => true) #=> will return old+1 or 0
79
- #
80
- # @example Increment key by one <b>OR</b> initialize with three
81
- # c.incr("foo", 50, :initial => 3) #=> will return old+50 or 3
82
- #
83
- # @example Increment key and get its CAS value
84
- # val, cas = c.incr("foo", :extended => true)
85
- #
86
- # @example Integer overflow
87
- # c.set("foo", -100)
88
- # c.get("foo") #=> -100
89
- # c.incr("foo") #=> 18446744073709551517
90
- #
91
- # @example Asynchronous invocation
92
- # c.run do
93
- # c.incr("foo") do |ret|
94
- # ret.operation #=> :increment
95
- # ret.success? #=> true
96
- # ret.key #=> "foo"
97
- # ret.value
98
- # ret.cas
99
- # end
100
- # end
101
- #
102
- def incr(*args)
103
- do_arithmetic(:incr, *args)
104
- end
105
- alias_method :increment, :incr
106
-
107
- # Decrement the value of an existing numeric key
108
- #
109
- # @since 1.0.0
110
- #
111
- # The decrement methods reduce the value of a given key if the
112
- # corresponding value can be parsed to an integer value. These operations
113
- # are provided at a protocol level to eliminate the need to get, update,
114
- # and reset a simple integer value in the database. It supports the use of
115
- # an explicit offset value that will be used to reduce the stored value in
116
- # the database.
117
- #
118
- # @note that server values stored and transmitted as unsigned numbers,
119
- # therefore if you try to decrement negative or zero key, you will always
120
- # get zero.
121
- #
122
- # @overload decr(key, delta = 1, options = {})
123
- # @param key [String, Symbol] Key used to reference the value.
124
- # @param delta [Fixnum] Integer (up to 64 bits) value to decrement
125
- # @param options [Hash] Options for operation.
126
- # @option options [true, false] :create (false) If set to +true+, it will
127
- # initialize the key with zero value and zero flags (use +:initial+
128
- # option to set another initial value). Note: it won't decrement the
129
- # missing value.
130
- # @option options [Fixnum] :initial (0) Integer (up to 64 bits) value for
131
- # missing key initialization. This option imply +:create+ option is
132
- # +true+.
133
- # @option options [Fixnum] :ttl (self.default_ttl) Expiry time for key.
134
- # Values larger than 30*24*60*60 seconds (30 days) are interpreted as
135
- # absolute times (from the epoch). This option ignored for existent
136
- # keys.
137
- # @option options [true, false] :extended (false) If set to +true+, the
138
- # operation will return tuple +[value, cas]+, otherwise (by default) it
139
- # returns just value.
140
- #
141
- # @yieldparam ret [Result] the result of operation in asynchronous mode
142
- # (valid attributes: +error+, +operation+, +key+, +value+, +cas+).
143
- #
144
- # @return [Fixnum] the actual value of the key.
145
- #
146
- # @raise [Couchbase::Error::NotFound] if key is missing and +:create+
147
- # option isn't +true+.
148
- #
149
- # @raise [Couchbase::Error::DeltaBadval] if the key contains non-numeric
150
- # value
151
- #
152
- # @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
153
- #
154
- # @raise [ArgumentError] when passing the block in synchronous mode
155
- #
156
- # @example Decrement key by one
157
- # c.decr("foo")
158
- #
159
- # @example Decrement key by 50
160
- # c.decr("foo", 50)
161
- #
162
- # @example Decrement key by one <b>OR</b> initialize with zero
163
- # c.decr("foo", :create => true) #=> will return old-1 or 0
164
- #
165
- # @example Decrement key by one <b>OR</b> initialize with three
166
- # c.decr("foo", 50, :initial => 3) #=> will return old-50 or 3
167
- #
168
- # @example Decrement key and get its CAS value
169
- # val, cas = c.decr("foo", :extended => true)
170
- #
171
- # @example Decrementing zero
172
- # c.set("foo", 0)
173
- # c.decrement("foo", 100500) #=> 0
174
- #
175
- # @example Decrementing negative value
176
- # c.set("foo", -100)
177
- # c.decrement("foo", 100500) #=> 0
178
- #
179
- # @example Asynchronous invocation
180
- # c.run do
181
- # c.decr("foo") do |ret|
182
- # ret.operation #=> :decrement
183
- # ret.success? #=> true
184
- # ret.key #=> "foo"
185
- # ret.value
186
- # ret.cas
187
- # end
188
- # end
189
- #
190
- def decr(*args)
191
- do_arithmetic(:decr, *args)
192
- end
193
- alias_method :decrement, :decr
194
-
195
- private
196
-
197
- def do_arithmetic(op, *args)
198
- key, delta, options = expand_arithmetic_args(args)
199
-
200
- case key
201
- when String, Symbol
202
- single_arithmetic(op, key, delta, options)
203
- when Array, Hash
204
- multi_arithmetic(op, key, delta)
205
- else
206
- raise # something
207
- end
208
- end
209
-
210
- def expand_arithmetic_args(args)
211
- options = if args.size > 1 && args.last.respond_to?(:to_h)
212
- args.pop
213
- else
214
- {}
215
- end
216
-
217
- delta = if args.size > 1 && args.last.respond_to?(:to_int)
218
- args.pop
219
- else
220
- options[:delta] || 1
221
- end
222
-
223
- key = args.size == 1 ? args.first : args
224
-
225
- [validate_key(key), delta, options]
226
- end
227
-
228
- def single_arithmetic(op, key, delta, options = {})
229
- result = case op
230
- when :incr
231
- client.incr(key, delta)
232
- when :decr
233
- client.decr(key, delta)
234
- end
235
-
236
- set_default_arithmetic_or_raise(key, result, options)
237
- end
238
-
239
- def set_default_arithmetic_or_raise(key, result, options)
240
- return result if result > 0
241
-
242
- if options[:initial] || options[:create] || set_default_arithmetic_init?
243
- value = if options[:initial]
244
- options[:initial]
245
- elsif options[:create]
246
- 0
247
- else
248
- default_arithmetic_init_int
249
- end
250
-
251
- set(key, value, options) && value
252
- else
253
- not_found_error(true)
254
- end
255
- end
256
-
257
- def set_default_arithmetic_init?
258
- default_arithmetic_init == true ||
259
- default_arithmetic_init.respond_to?(:to_int) &&
260
- default_arithmetic_init > 0
261
- end
262
-
263
- def default_arithmetic_init_int
264
- default_arithmetic_init == true ? 0 : default_arithmetic_init
265
- end
266
-
267
- def multi_arithmetic(op, keys, delta)
268
- {}.tap do |results|
269
- if keys.respond_to?(:each_pair)
270
- keys.each_pair do |k, v|
271
- results[k] = single_arithmetic(op, k, v)
272
- end
273
- else
274
- keys.each do |k|
275
- results[k] = single_arithmetic(op, k, delta)
276
- end
277
- end
278
- end
279
- end
280
-
281
- # def java_async_incr(key, delta)
282
- # client.asyncIncr(key, delta)
283
- # end
284
-
285
- # def java_async_decr(key, delta)
286
- # client.asyncDecr(key, delta)
287
- # end
288
-
289
- end
290
- end
@@ -1,115 +0,0 @@
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
- module Couchbase::Operations
19
- module Delete
20
-
21
- # Delete the specified key
22
- #
23
- # @since 1.0.0
24
- #
25
- # @overload delete(key, options = {})
26
- # @param key [String, Symbol] Key used to reference the value.
27
- # @param options [Hash] Options for operation.
28
- # @option options [true, false] :quiet (self.quiet) If set to +true+, the
29
- # operation won't raise error for missing key, it will return +nil+.
30
- # Otherwise it will raise error in synchronous mode. In asynchronous
31
- # mode this option ignored.
32
- # @option options [Fixnum] :cas The CAS value for an object. This value
33
- # created on the server and is guaranteed to be unique for each value of
34
- # a given key. This value is used to provide simple optimistic
35
- # concurrency control when multiple clients or threads try to
36
- # update/delete an item simultaneously.
37
- #
38
- # @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
39
- # @raise [ArgumentError] when passing the block in synchronous mode
40
- # @raise [Couchbase::Error::KeyExists] on CAS mismatch
41
- # @raise [Couchbase::Error::NotFound] if key is missing in verbose mode
42
- #
43
- # @return [true, false, Hash<String, Boolean>] the result of the
44
- # operation
45
- #
46
- # @example Delete the key in quiet mode (default)
47
- # c.set("foo", "bar")
48
- # c.delete("foo") #=> true
49
- # c.delete("foo") #=> false
50
- #
51
- # @example Delete the key verbosely
52
- # c.set("foo", "bar")
53
- # c.delete("foo", :quiet => false) #=> true
54
- # c.delete("foo", :quiet => true) #=> nil (default behaviour)
55
- # c.delete("foo", :quiet => false) #=> will raise Couchbase::Error::NotFound
56
- #
57
- # @example Delete the key with version check
58
- # ver = c.set("foo", "bar") #=> 5992859822302167040
59
- # c.delete("foo", :cas => 123456) #=> will raise Couchbase::Error::KeyExists
60
- # c.delete("foo", :cas => ver) #=> true
61
- #
62
- def delete(*args)
63
- key, cas, options = expand_delete_args(args)
64
-
65
- if key.respond_to?(:to_ary)
66
- delete_multi(key, options)
67
- else
68
- delete_single(key, cas, options)
69
- end
70
- end
71
-
72
- def async_delete(*args, &block)
73
- key, cas, options = expand_delete_args(args)
74
-
75
- future = client.delete(key)
76
- register_future(future, { op: :delete }, &block)
77
- end
78
-
79
- private
80
-
81
- def expand_delete_args(args)
82
- key, options = expand_get_args(args)
83
-
84
- if key.respond_to?(:to_str)
85
- [validate_key(key), options[:cas], options]
86
- else
87
- cas = if key.size > 1 &&
88
- key.last.respond_to?(:to_int)
89
- key.pop
90
- else
91
- nil
92
- end
93
-
94
- key = key.size == 1 ? key.first : key
95
-
96
- [validate_key(key), cas, options]
97
- end
98
- end
99
-
100
- def delete_single(key, cas, options)
101
- future = cas.nil? ? client.delete(key) : client.delete(key, cas)
102
- cas = future_cas(future)
103
- not_found_error(!cas, options)
104
- cas
105
- end
106
-
107
- def delete_multi(keys, options = {})
108
- {}.tap do |results|
109
- keys.each do |key|
110
- results[key] = delete_single(key, nil, options)
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,99 +0,0 @@
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
- module Couchbase::Operations
19
- module DesignDocs
20
-
21
- java_import com.couchbase.client.protocol.views.DesignDocument
22
- java_import com.couchbase.client.protocol.views.ViewDesign
23
-
24
- class DesignDocAccess
25
- def initialize(bucket)
26
- @bucket = bucket
27
- end
28
-
29
- def [](name)
30
- doc = @bucket.client.getDesignDocument(name)
31
- Couchbase::DesignDoc.new(@bucket, doc)
32
- rescue Java::ComCouchbaseClientProtocolViews::InvalidViewException
33
- nil
34
- end
35
- end
36
-
37
- # Fetch design docs stored in current bucket
38
- #
39
- # @since 1.2.0
40
- #
41
- # @return [Hash]
42
- def design_docs
43
- DesignDocAccess.new(self)
44
- end
45
-
46
- # Update or create design doc with supplied views
47
- #
48
- # @since 1.2.0
49
- #
50
- # @param [Hash, IO, String] data The source object containing JSON
51
- # encoded design document. It must have +_id+ key set, this key
52
- # should start with +_design/+.
53
- #
54
- # @return [true, false]
55
- def save_design_doc(data)
56
- attrs = case data
57
- when String
58
- MultiJson.load(data)
59
- when IO
60
- MultiJson.load(data.read)
61
- when Hash
62
- data
63
- else
64
- raise ArgumentError, "Document should be Hash, String or IO instance"
65
- end
66
-
67
- id = attrs.delete('_id').to_s.split('/')[1]
68
-
69
- design_doc = DesignDocument.new(id)
70
-
71
- attrs['views'].each_pair do |view, functions|
72
- view_design = if functions['reduce']
73
- ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string, functions['reduce'].to_java_string)
74
- else
75
- ViewDesign.new(view.to_s.to_java_string, functions['map'].to_java_string)
76
- end
77
- design_doc.getViews.add(view_design)
78
- end
79
-
80
- client.createDesignDoc(design_doc)
81
- end
82
-
83
- # Delete design doc with given id and revision.
84
- #
85
- # @since 1.2.0
86
- #
87
- # @param [String] id Design document id. It might have '_design/'
88
- # prefix.
89
- #
90
- # @param [String] rev Document revision. It uses latest revision if
91
- # +rev+ parameter is nil.
92
- #
93
- # @return [true, false]
94
- def delete_design_doc(id, rev = nil)
95
- client.deleteDesignDoc(id)
96
- end
97
-
98
- end
99
- end
@@ -1,33 +0,0 @@
1
- # Author:: Joe Winter <jwinter@jwinter.org>
2
- # Copyright:: 2013 jwinter.org
3
- # Author:: Mike Evans <mike@urlgonomics.com>
4
- # Copyright:: 2013 Urlgonomics LLC.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- module Couchbase::Operations
21
- module Fetch
22
-
23
- def fetch(key, set_options = {}, get_options = {}, &block)
24
- fail ArgumentError 'Must pass a block to #fetch' unless block_given?
25
-
26
- get_options[:quiet] = false
27
- get(key, get_options)
28
- rescue Couchbase::Error::NotFound
29
- yield(block).tap {|value| set(key, value, set_options) }
30
- end
31
-
32
- end
33
- end