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.
- checksums.yaml +4 -4
- data/.rubocop.yml +103 -0
- data/.ruby-version +1 -1
- data/Rakefile +13 -2
- data/couchbase-jruby-client.gemspec +7 -6
- data/lib/couchbase/bucket.rb +11 -338
- data/lib/couchbase/cluster.rb +10 -88
- data/lib/couchbase/configuration.rb +39 -0
- data/lib/couchbase/design_doc.rb +18 -73
- data/lib/couchbase/document.rb +34 -0
- data/lib/couchbase/error.rb +0 -35
- data/lib/couchbase/operations.rb +60 -40
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +55 -345
- data/lib/couchbase.rb +37 -141
- data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
- data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
- data/lib/jars/rxjava-1.0.8.jar +0 -0
- data/lib/jars/rxjruby-0.0.1.jar +0 -0
- data/test/{test_cas.rb → helper.rb} +15 -10
- data/test/test_bucket.rb +14 -228
- data/test/test_cluster.rb +1 -29
- data/test/test_configuration.rb +51 -0
- data/test/test_couchbase.rb +28 -28
- data/test/test_design_doc.rb +29 -0
- data/test/test_document.rb +51 -0
- data/test/test_operations.rb +49 -0
- data/test/test_view.rb +62 -116
- metadata +43 -125
- data/lib/couchbase/async/callback.rb +0 -38
- data/lib/couchbase/async/queue.rb +0 -26
- data/lib/couchbase/async.rb +0 -32
- data/lib/couchbase/constants.rb +0 -29
- data/lib/couchbase/operations/arithmetic.rb +0 -290
- data/lib/couchbase/operations/delete.rb +0 -115
- data/lib/couchbase/operations/design_docs.rb +0 -99
- data/lib/couchbase/operations/fetch.rb +0 -33
- data/lib/couchbase/operations/get.rb +0 -303
- data/lib/couchbase/operations/stats.rb +0 -42
- data/lib/couchbase/operations/store.rb +0 -463
- data/lib/couchbase/operations/touch.rb +0 -140
- data/lib/couchbase/operations/unlock.rb +0 -209
- data/lib/couchbase/operations/utils.rb +0 -68
- data/lib/couchbase/query.rb +0 -76
- data/lib/couchbase/result.rb +0 -60
- data/lib/couchbase/transcoder.rb +0 -81
- data/lib/couchbase/utils.rb +0 -62
- data/lib/couchbase/view_row.rb +0 -227
- data/lib/jars/commons-codec-1.5.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2.jar +0 -0
- data/lib/jars/httpcore-4.3.1.jar +0 -0
- data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
- data/lib/jars/jettison-1.1.jar +0 -0
- data/lib/jars/netty-3.5.5.Final.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
- data/lib/jars/spymemcached-2.10.5.jar +0 -0
- data/tasks/benchmark.rake +0 -6
- data/tasks/test.rake +0 -36
- data/tasks/util.rake +0 -21
- data/test/mock.rb +0 -85
- data/test/profile/.gitignore +0 -1
- data/test/profile/.jrubyrc +0 -722
- data/test/profile/Gemfile +0 -7
- data/test/profile/benchmark.rb +0 -177
- data/test/profile/profile.rb +0 -59
- data/test/setup.rb +0 -74
- data/test/test_arithmetic.rb +0 -155
- data/test/test_async.rb +0 -24
- data/test/test_couchbase_rails_cache_store.rb +0 -341
- data/test/test_delete.rb +0 -139
- data/test/test_design_docs.rb +0 -67
- data/test/test_errors.rb +0 -74
- data/test/test_fetch.rb +0 -71
- data/test/test_format.rb +0 -142
- data/test/test_get.rb +0 -363
- data/test/test_query.rb +0 -23
- data/test/test_result.rb +0 -15
- data/test/test_stats.rb +0 -44
- data/test/test_store.rb +0 -203
- data/test/test_touch.rb +0 -90
- data/test/test_unlock.rb +0 -89
- data/test/test_utils.rb +0 -67
- data/test/test_version.rb +0 -28
- data/test/test_view_row.rb +0 -74
@@ -1,341 +0,0 @@
|
|
1
|
-
# Author:: Couchbase <info@couchbase.com>
|
2
|
-
# Copyright:: 2011, 2012 Couchbase, Inc.
|
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
|
-
# require 'active_support/cache/couchbase_store'
|
20
|
-
# require 'active_support/notifications'
|
21
|
-
# require 'ostruct'
|
22
|
-
|
23
|
-
# class TestCouchbaseRailsCacheStore < Minitest::Test
|
24
|
-
|
25
|
-
# def setup
|
26
|
-
# @mock = start_mock
|
27
|
-
# @foo = OpenStruct.new :payload => "foo"
|
28
|
-
# @foobar = OpenStruct.new :payload => "foobar"
|
29
|
-
# end
|
30
|
-
|
31
|
-
# def teardown
|
32
|
-
# stop_mock(@mock)
|
33
|
-
# end
|
34
|
-
|
35
|
-
# def store
|
36
|
-
# @store ||= ActiveSupport::Cache::CouchbaseStore.new(:hostname => @mock.host,
|
37
|
-
# :port => @mock.port)
|
38
|
-
# end
|
39
|
-
|
40
|
-
# def pool_store
|
41
|
-
# @pool_store ||= ActiveSupport::Cache::CouchbaseStore.new(:hostname => @mock.host,
|
42
|
-
# :port => @mock.port,
|
43
|
-
# :connection_pool => 5)
|
44
|
-
# end
|
45
|
-
|
46
|
-
# def test_it_supported_methods
|
47
|
-
# supported_methods = store.public_methods(false).map(&:to_sym)
|
48
|
-
# assert supported_methods.include?(:fetch)
|
49
|
-
# assert supported_methods.include?(:write)
|
50
|
-
# assert supported_methods.include?(:read)
|
51
|
-
# assert supported_methods.include?(:read_multi)
|
52
|
-
# assert supported_methods.include?(:increment)
|
53
|
-
# assert supported_methods.include?(:decrement)
|
54
|
-
# assert supported_methods.include?(:exists?)
|
55
|
-
# assert supported_methods.include?(:delete)
|
56
|
-
# assert supported_methods.include?(:stats)
|
57
|
-
# refute supported_methods.include?(:clear)
|
58
|
-
# assert_raises(NotImplementedError) do
|
59
|
-
# store.clear
|
60
|
-
# end
|
61
|
-
# refute supported_methods.include?(:cleanup)
|
62
|
-
# assert_raises(NotImplementedError) do
|
63
|
-
# store.cleanup
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
|
67
|
-
# def test_it_writes_and_reads_the_data
|
68
|
-
# store.write uniq_id, @foobar
|
69
|
-
# assert_equal @foobar, store.read(uniq_id)
|
70
|
-
# end
|
71
|
-
|
72
|
-
# def test_it_writes_the_data_with_expiration_time
|
73
|
-
# store.write(uniq_id, @foobar, :expires_in => 1.second)
|
74
|
-
# assert_equal @foobar, store.read(uniq_id)
|
75
|
-
# sleep 2
|
76
|
-
# refute store.read(uniq_id)
|
77
|
-
# end
|
78
|
-
|
79
|
-
# def test_it_doest_write_data_if_unless_exist_option_is_true
|
80
|
-
# store.write uniq_id, @foo
|
81
|
-
# [:unless_exist, :unless_exists].each do |unless_exists|
|
82
|
-
# store.write uniq_id, @foobar, unless_exists => true
|
83
|
-
# assert_equal @foo, store.read(uniq_id)
|
84
|
-
# end
|
85
|
-
# end
|
86
|
-
|
87
|
-
# def test_it_reads_raw_data
|
88
|
-
# store.write uniq_id, @foo
|
89
|
-
# expected = case RUBY_VERSION
|
90
|
-
# when /^2\.0/
|
91
|
-
# "\x04\bU:\x0FOpenStruct{\x06:\fpayloadI\"\bfoo\x06:\x06ET"
|
92
|
-
# when /^1\.9/
|
93
|
-
# "\x04\bU:\x0FOpenStruct{\x06:\fpayloadI\"\bfoo\x06:\x06EF"
|
94
|
-
# else
|
95
|
-
# "\004\bU:\017OpenStruct{\006:\fpayload\"\bfoo"
|
96
|
-
# end
|
97
|
-
# assert_equal expected, store.read(uniq_id, :raw => true)
|
98
|
-
# end
|
99
|
-
|
100
|
-
# def test_it_writes_raw_data
|
101
|
-
# store.write uniq_id, @foobar, :raw => true
|
102
|
-
# assert_equal '#<OpenStruct payload="foobar">', store.read(uniq_id, :raw => true)
|
103
|
-
# end
|
104
|
-
|
105
|
-
# def test_it_deletes_data
|
106
|
-
# store.write uniq_id, @foo
|
107
|
-
# store.delete uniq_id
|
108
|
-
# refute store.read(uniq_id)
|
109
|
-
# end
|
110
|
-
|
111
|
-
# def test_it_verifies_existence_of_an_object_in_the_store
|
112
|
-
# store.write uniq_id, @foo
|
113
|
-
# assert store.exist?(uniq_id)
|
114
|
-
# refute store.exist?(uniq_id(:missing))
|
115
|
-
# end
|
116
|
-
|
117
|
-
# def test_it_initializes_key_on_first_increment_with_zero
|
118
|
-
# store.increment(uniq_id)
|
119
|
-
# assert_equal 0, store.read(uniq_id)
|
120
|
-
# assert_equal "0", store.read(uniq_id, :raw => true)
|
121
|
-
# end
|
122
|
-
|
123
|
-
# def test_it_initializes_key_on_first_decrement_with_zero
|
124
|
-
# store.decrement(uniq_id)
|
125
|
-
# assert_equal 0, store.read(uniq_id)
|
126
|
-
# assert_equal "0", store.read(uniq_id, :raw => true)
|
127
|
-
# end
|
128
|
-
|
129
|
-
# def test_it_initializes_key_with_given_value_on_increment
|
130
|
-
# store.increment(uniq_id, 1, :initial => 5)
|
131
|
-
# assert_equal 5, store.read(uniq_id)
|
132
|
-
# assert_equal "5", store.read(uniq_id, :raw => true)
|
133
|
-
# end
|
134
|
-
|
135
|
-
# def test_it_initializes_key_with_given_value_on_decrement
|
136
|
-
# store.decrement(uniq_id, 1, :initial => 5)
|
137
|
-
# assert_equal 5, store.read(uniq_id)
|
138
|
-
# assert_equal "5", store.read(uniq_id, :raw => true)
|
139
|
-
# end
|
140
|
-
|
141
|
-
# def test_it_increments_a_key
|
142
|
-
# 3.times { store.increment uniq_id }
|
143
|
-
# assert_equal 2, store.read(uniq_id)
|
144
|
-
# assert_equal "2", store.read(uniq_id, :raw => true)
|
145
|
-
# end
|
146
|
-
|
147
|
-
# def test_it_decrements_a_key
|
148
|
-
# 4.times { store.increment uniq_id }
|
149
|
-
# 2.times { store.decrement uniq_id }
|
150
|
-
# assert_equal 1, store.read(uniq_id)
|
151
|
-
# assert_equal "1", store.read(uniq_id, :raw => true)
|
152
|
-
# end
|
153
|
-
|
154
|
-
# def test_it_increments_a_raw_key
|
155
|
-
# assert store.write(uniq_id, 1, :raw => true)
|
156
|
-
# store.increment(uniq_id, 2)
|
157
|
-
# assert_equal 3, store.read(uniq_id, :raw => true).to_i
|
158
|
-
# end
|
159
|
-
|
160
|
-
# def test_it_decrements_a_raw_key
|
161
|
-
# assert store.write(uniq_id, 3, :raw => true)
|
162
|
-
# store.decrement(uniq_id, 2)
|
163
|
-
# assert_equal 1, store.read(uniq_id, :raw => true).to_i
|
164
|
-
# end
|
165
|
-
|
166
|
-
# def test_it_increments_a_key_by_given_value
|
167
|
-
# store.write(uniq_id, 0, :raw => true)
|
168
|
-
# store.increment uniq_id, 3
|
169
|
-
# assert_equal 3, store.read(uniq_id, :raw => true).to_i
|
170
|
-
# end
|
171
|
-
|
172
|
-
# def test_it_decrements_a_key_by_given_value
|
173
|
-
# store.write(uniq_id, 0, :raw => true)
|
174
|
-
# 3.times { store.increment uniq_id }
|
175
|
-
# store.decrement uniq_id, 2
|
176
|
-
# assert_equal 1, store.read(uniq_id, :raw => true).to_i
|
177
|
-
# end
|
178
|
-
|
179
|
-
# def test_it_provides_store_stats
|
180
|
-
# refute store.stats.empty?
|
181
|
-
# end
|
182
|
-
|
183
|
-
# def test_it_fetches_data
|
184
|
-
# assert store.write(uniq_id, @foo)
|
185
|
-
# assert_equal @foo, store.fetch(uniq_id)
|
186
|
-
# refute store.fetch("rub-a-dub")
|
187
|
-
# store.fetch("rub-a-dub") { "Flora de Cana" }
|
188
|
-
# assert_equal "Flora de Cana", store.fetch("rub-a-dub")
|
189
|
-
# store.fetch(uniq_id, :force => true) # force cache miss
|
190
|
-
# store.fetch(uniq_id, :force => true, :expires_in => 1.second) { @foobar }
|
191
|
-
# assert_equal @foobar, store.fetch(uniq_id)
|
192
|
-
# sleep 2
|
193
|
-
# refute store.fetch(uniq_id)
|
194
|
-
# end
|
195
|
-
|
196
|
-
# def test_it_reads_multiple_keys
|
197
|
-
# assert store.write(uniq_id(1), @foo)
|
198
|
-
# assert store.write(uniq_id(2), "foo")
|
199
|
-
# result = store.read_multi uniq_id(1), uniq_id(2)
|
200
|
-
# assert_equal @foo, result[uniq_id(1)]
|
201
|
-
# assert_equal "foo", result[uniq_id(2)]
|
202
|
-
# end
|
203
|
-
|
204
|
-
# def test_it_reads_multiple_keys_and_returns_only_the_matched_ones
|
205
|
-
# assert store.write(uniq_id, @foo)
|
206
|
-
# result = store.read_multi uniq_id, uniq_id(:missing)
|
207
|
-
# assert result[uniq_id]
|
208
|
-
# refute result[uniq_id(:missing)]
|
209
|
-
# end
|
210
|
-
|
211
|
-
# def test_it_notifies_on_fetch
|
212
|
-
# collect_notifications do
|
213
|
-
# store.fetch(uniq_id) { "foo" }
|
214
|
-
# end
|
215
|
-
|
216
|
-
# read, generate, write = @events
|
217
|
-
|
218
|
-
# assert_equal 'cache_read.active_support', read.name
|
219
|
-
# assert_equal({:key => uniq_id, :super_operation => :fetch}, read.payload)
|
220
|
-
|
221
|
-
# assert_equal 'cache_generate.active_support', generate.name
|
222
|
-
# assert_equal({:key => uniq_id}, generate.payload)
|
223
|
-
|
224
|
-
# assert_equal 'cache_write.active_support', write.name
|
225
|
-
# assert_equal({:key => uniq_id}, write.payload)
|
226
|
-
# end
|
227
|
-
|
228
|
-
# def test_it_notifies_on_read
|
229
|
-
# collect_notifications do
|
230
|
-
# store.read uniq_id
|
231
|
-
# end
|
232
|
-
|
233
|
-
# read = @events.first
|
234
|
-
# assert_equal 'cache_read.active_support', read.name
|
235
|
-
# assert_equal({:key => uniq_id, :hit => false}, read.payload)
|
236
|
-
# end
|
237
|
-
|
238
|
-
# def test_it_notifies_on_write
|
239
|
-
# collect_notifications do
|
240
|
-
# store.write uniq_id, "foo"
|
241
|
-
# end
|
242
|
-
|
243
|
-
# write = @events.first
|
244
|
-
# assert_equal 'cache_write.active_support', write.name
|
245
|
-
# assert_equal({:key => uniq_id}, write.payload)
|
246
|
-
# end
|
247
|
-
|
248
|
-
# def test_it_notifies_on_delete
|
249
|
-
# collect_notifications do
|
250
|
-
# store.delete uniq_id
|
251
|
-
# end
|
252
|
-
|
253
|
-
# delete = @events.first
|
254
|
-
# assert_equal 'cache_delete.active_support', delete.name
|
255
|
-
# assert_equal({:key => uniq_id}, delete.payload)
|
256
|
-
# end
|
257
|
-
|
258
|
-
# def test_it_notifies_on_exist?
|
259
|
-
# collect_notifications do
|
260
|
-
# store.exist? uniq_id
|
261
|
-
# end
|
262
|
-
|
263
|
-
# exist = @events.first
|
264
|
-
# assert_equal 'cache_exists?.active_support', exist.name
|
265
|
-
# assert_equal({:key => uniq_id}, exist.payload)
|
266
|
-
# end
|
267
|
-
|
268
|
-
# def test_it_notifies_on_increment
|
269
|
-
# collect_notifications do
|
270
|
-
# store.increment uniq_id
|
271
|
-
# end
|
272
|
-
|
273
|
-
# increment = @events.first
|
274
|
-
# assert_equal 'cache_increment.active_support', increment.name
|
275
|
-
# assert_equal({:key => uniq_id, :amount => 1, :create => true}, increment.payload)
|
276
|
-
# end
|
277
|
-
|
278
|
-
# def test_it_notifies_on_decrement
|
279
|
-
# collect_notifications do
|
280
|
-
# store.decrement uniq_id
|
281
|
-
# end
|
282
|
-
|
283
|
-
# decrement = @events.first
|
284
|
-
# assert_equal 'cache_decrement.active_support', decrement.name
|
285
|
-
# assert_equal({:key => uniq_id, :amount => 1, :create => true}, decrement.payload)
|
286
|
-
# end
|
287
|
-
|
288
|
-
# # Inspiration: https://github.com/mperham/dalli/blob/master/test/test_dalli.rb#L416
|
289
|
-
# def test_it_is_threadsafe
|
290
|
-
# workers = []
|
291
|
-
|
292
|
-
# # Have a bunch of threads perform a bunch of operations at the same time.
|
293
|
-
# # Verify the result of each operation to ensure the request and response
|
294
|
-
# # are not intermingled between threads.
|
295
|
-
# 10.times do
|
296
|
-
# workers << Thread.new do
|
297
|
-
# 100.times do
|
298
|
-
# store.write('a', 9)
|
299
|
-
# store.write('b', 11)
|
300
|
-
# assert_equal 9, store.read('a')
|
301
|
-
# assert_equal({ 'a' => 9, 'b' => 11 }, store.read_multi('a', 'b'))
|
302
|
-
# assert_equal 11, store.read('b')
|
303
|
-
# assert_equal %w(a b), store.read_multi('a', 'b', 'c').keys.sort
|
304
|
-
# end
|
305
|
-
# end
|
306
|
-
# end
|
307
|
-
|
308
|
-
# workers.each { |w| w.join }
|
309
|
-
# end
|
310
|
-
|
311
|
-
# def test_it_can_use_connection_pool_for_thread_safety
|
312
|
-
# workers = []
|
313
|
-
|
314
|
-
# 10.times do
|
315
|
-
# workers << Thread.new do
|
316
|
-
# 100.times do
|
317
|
-
# pool_store.write('a', 9)
|
318
|
-
# pool_store.write('b', 11)
|
319
|
-
# assert_equal 9, pool_store.read('a')
|
320
|
-
# assert_equal({ 'a' => 9, 'b' => 11 }, pool_store.read_multi('a', 'b'))
|
321
|
-
# assert_equal 11, pool_store.read('b')
|
322
|
-
# assert_equal %w(a b), pool_store.read_multi('a', 'b', 'c').keys.sort
|
323
|
-
# end
|
324
|
-
# end
|
325
|
-
# end
|
326
|
-
|
327
|
-
# workers.each { |w| w.join }
|
328
|
-
# end
|
329
|
-
|
330
|
-
# private
|
331
|
-
|
332
|
-
# def collect_notifications
|
333
|
-
# @events = [ ]
|
334
|
-
# ActiveSupport::Cache::CouchbaseStore.instrument = true
|
335
|
-
# ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
|
336
|
-
# @events << ActiveSupport::Notifications::Event.new(*args)
|
337
|
-
# end
|
338
|
-
# yield
|
339
|
-
# ActiveSupport::Cache::CouchbaseStore.instrument = false
|
340
|
-
# end
|
341
|
-
# end
|
data/test/test_delete.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
# Author:: Couchbase <info@couchbase.com>
|
2
|
-
# Copyright:: 2011, 2012 Couchbase, Inc.
|
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 TestDelete < Minitest::Test
|
21
|
-
|
22
|
-
def test_trivial_delete
|
23
|
-
cb.set(uniq_id, "bar")
|
24
|
-
cas = cb.delete(uniq_id)
|
25
|
-
assert cas
|
26
|
-
|
27
|
-
assert_raises(Couchbase::Error::NotFound) do
|
28
|
-
cb.delete(uniq_id)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_trivial_async_delete
|
33
|
-
cb.set(uniq_id, 'fu')
|
34
|
-
ret = nil
|
35
|
-
future = cb.async_delete(uniq_id) { |res| ret = res }
|
36
|
-
future.get
|
37
|
-
sleep 0.1
|
38
|
-
|
39
|
-
assert ret.is_a?(Couchbase::Result)
|
40
|
-
assert ret.success?
|
41
|
-
assert_equal :delete, ret.operation
|
42
|
-
assert ret.cas.is_a?(Numeric)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_delete_missing
|
46
|
-
assert_raises(Couchbase::Error::NotFound) do
|
47
|
-
cb.delete(uniq_id(:missing))
|
48
|
-
end
|
49
|
-
refute cb.delete(uniq_id(:missing), :quiet => true)
|
50
|
-
refute cb.quiet?
|
51
|
-
cb.quiet = true
|
52
|
-
refute cb.delete(uniq_id(:missing))
|
53
|
-
ensure
|
54
|
-
cb.quiet = false
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_delete_with_cas
|
58
|
-
cas = cb.set(uniq_id, "bar")
|
59
|
-
missing_cas = cas - 100
|
60
|
-
assert_raises(Couchbase::Error::NotFound) do
|
61
|
-
cb.delete(uniq_id, :cas => missing_cas)
|
62
|
-
end
|
63
|
-
assert cb.delete(uniq_id, :cas => cas)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_allow_fixnum_as_cas_parameter
|
67
|
-
cas = cb.set(uniq_id, "bar")
|
68
|
-
assert cb.delete(uniq_id, cas)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_delete_with_prefix
|
72
|
-
skip
|
73
|
-
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => "prefix:")
|
74
|
-
cb.set(uniq_id(:foo), "bar")
|
75
|
-
assert cb.delete(uniq_id(:foo))
|
76
|
-
assert_raises(Couchbase::Error::NotFound) do
|
77
|
-
cb.get(uniq_id(:foo))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_simple_multi_delete
|
82
|
-
cb.quiet = true
|
83
|
-
cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
|
84
|
-
res = cb.delete(uniq_id(1), uniq_id(2))
|
85
|
-
assert res.is_a?(Hash)
|
86
|
-
assert res[uniq_id(1)]
|
87
|
-
assert res[uniq_id(2)]
|
88
|
-
ensure
|
89
|
-
cb.quiet = false
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_simple_multi_delete_missing
|
93
|
-
cb.quiet = true
|
94
|
-
cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
|
95
|
-
res = cb.delete(uniq_id(1), uniq_id(:missing), :quiet => true)
|
96
|
-
assert res.is_a?(Hash)
|
97
|
-
assert res[uniq_id(1)]
|
98
|
-
refute res[uniq_id(:missing)]
|
99
|
-
ensure
|
100
|
-
cb.quiet = false
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_multi_delete_with_cas_check
|
104
|
-
skip
|
105
|
-
cb.quiet = true
|
106
|
-
cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
|
107
|
-
res = cb.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(2) => cas[uniq_id(2)])
|
108
|
-
assert res.is_a?(Hash)
|
109
|
-
assert res[uniq_id(1)]
|
110
|
-
assert res[uniq_id(2)]
|
111
|
-
ensure
|
112
|
-
cb.quiet = false
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_multi_delete_missing_with_cas_check
|
116
|
-
skip
|
117
|
-
cb.quiet = true
|
118
|
-
cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
|
119
|
-
res = cb.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(:missing) => cas[uniq_id(2)])
|
120
|
-
assert res.is_a?(Hash)
|
121
|
-
assert res[uniq_id(1)]
|
122
|
-
refute res[uniq_id(:missing)]
|
123
|
-
ensure
|
124
|
-
cb.quiet = false
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_multi_delete_with_cas_check_mismatch
|
128
|
-
skip
|
129
|
-
cb.quiet = true
|
130
|
-
cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
|
131
|
-
|
132
|
-
assert_raises(Couchbase::Error::KeyExists) do
|
133
|
-
cb.delete(uniq_id(1) => cas[uniq_id(1)] + 1,
|
134
|
-
uniq_id(2) => cas[uniq_id(2)])
|
135
|
-
end
|
136
|
-
ensure
|
137
|
-
cb.quiet = false
|
138
|
-
end
|
139
|
-
end
|
data/test/test_design_docs.rb
DELETED
@@ -1,67 +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
|
-
require File.join(File.dirname(__FILE__), 'setup')
|
19
|
-
|
20
|
-
class TestDesignDocs < Minitest::Test
|
21
|
-
|
22
|
-
def test_save_design_doc
|
23
|
-
skip unless $mock.real?
|
24
|
-
assert cb.save_design_doc(design_doc)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_save_design_doc_with_bad_data
|
28
|
-
skip unless $mock.real?
|
29
|
-
assert_raises ArgumentError do
|
30
|
-
cb.save_design_doc(123)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_delete_design_doc
|
35
|
-
skip unless $mock.real?
|
36
|
-
cb.save_design_doc(design_doc)
|
37
|
-
assert cb.delete_design_doc('blog')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_design_doc_access
|
41
|
-
skip unless $mock.real?
|
42
|
-
cb.save_design_doc(design_doc)
|
43
|
-
assert cb.design_docs['blog']
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_design_doc_missing_access
|
47
|
-
skip unless $mock.real?
|
48
|
-
refute cb.design_docs['missing']
|
49
|
-
end
|
50
|
-
|
51
|
-
def design_doc
|
52
|
-
{
|
53
|
-
'_id' => '_design/blog',
|
54
|
-
'language' => 'javascript',
|
55
|
-
'views' => {
|
56
|
-
'recent_posts' => {
|
57
|
-
'map' => <<-JS
|
58
|
-
function (doc, meta) {
|
59
|
-
emit(doc.name);
|
60
|
-
}
|
61
|
-
JS
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/test/test_errors.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Author:: Couchbase <info@couchbase.com>
|
2
|
-
# Copyright:: 2011, 2012 Couchbase, Inc.
|
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
|
-
require 'digest/md5'
|
20
|
-
|
21
|
-
class TestErrors < Minitest::Test
|
22
|
-
|
23
|
-
def genkey(item)
|
24
|
-
tuple = [item["author"], item["message"]]
|
25
|
-
Digest::MD5.hexdigest(tuple.join('-'))
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_graceful_add_with_collision
|
29
|
-
skip
|
30
|
-
msg1 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:09"}
|
31
|
-
key1 = uniq_id(genkey(msg1))
|
32
|
-
msg2 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:30"}
|
33
|
-
key2 = uniq_id(genkey(msg2))
|
34
|
-
|
35
|
-
cb.add(key1, msg1)
|
36
|
-
begin
|
37
|
-
cb.add(key2, msg2)
|
38
|
-
rescue Couchbase::Error::KeyExists => ex
|
39
|
-
# using info from exception
|
40
|
-
# it could be done with cas operation, but we can save one request
|
41
|
-
# here (in real world cas operation will be more consistent because it
|
42
|
-
# fetch fresh version from the cluster)
|
43
|
-
#
|
44
|
-
# cb.cas(key2) do |msg|
|
45
|
-
# msg.merge("time" => [msg["time"], msg2["time"]])
|
46
|
-
# end
|
47
|
-
msg2 = msg1.merge("time" => [msg1["time"], msg2["time"]])
|
48
|
-
cb.set(key2, msg2, :cas => ex.cas)
|
49
|
-
end
|
50
|
-
|
51
|
-
msg3 = {"author" => "foo", "message" => "hi all",
|
52
|
-
"time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30"]}
|
53
|
-
key3 = uniq_id(genkey(msg3))
|
54
|
-
assert_equal msg3, cb.get(key3)
|
55
|
-
|
56
|
-
cb.run do |conn|
|
57
|
-
msg4 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:45:34"}
|
58
|
-
key4 = uniq_id(genkey(msg4))
|
59
|
-
|
60
|
-
cb.add(key4, msg4) do |ret|
|
61
|
-
assert_equal :add, ret.operation
|
62
|
-
assert_equal key4, ret.key
|
63
|
-
msg4 = msg3.merge("time" => msg3["time"] + [msg4["time"]])
|
64
|
-
cb.set(ret.key, msg4, :cas => ret.cas)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
msg5 = {"author" => "foo", "message" => "hi all",
|
69
|
-
"time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30", "2012-01-12 11:45:34"]}
|
70
|
-
key5 = uniq_id(genkey(msg5))
|
71
|
-
assert_equal msg5, cb.get(key5)
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
data/test/test_fetch.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# Author:: Joe Winter <jwinter@jwinter.org>
|
2
|
-
# Copyright:: 2013 jwinter.org
|
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 TestFetch < Minitest::Test
|
21
|
-
|
22
|
-
def test_trivial_fetch
|
23
|
-
cb.fetch(uniq_id) do
|
24
|
-
123
|
25
|
-
end
|
26
|
-
val = cb.get(uniq_id)
|
27
|
-
assert_equal 123, val
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_returns_existing_key_if_exists
|
31
|
-
cb.set(uniq_id, 'abc')
|
32
|
-
|
33
|
-
cb.fetch(uniq_id) do
|
34
|
-
'xyz'
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal 'abc', cb.get(uniq_id)
|
38
|
-
end
|
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
|
-
|
61
|
-
def test_fetch_works_with_quiet_mode
|
62
|
-
cb.quiet = true
|
63
|
-
cb.fetch(uniq_id) do
|
64
|
-
'xyz'
|
65
|
-
end
|
66
|
-
assert_equal 'xyz', cb.get(uniq_id)
|
67
|
-
ensure
|
68
|
-
cb.quiet = false
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|