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