couchbase-jruby-client 0.2.2-java → 1.0.4-java
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/test/test_bucket.rb
CHANGED
@@ -1,239 +1,25 @@
|
|
1
|
-
|
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')
|
1
|
+
require 'helper'
|
19
2
|
|
20
3
|
class TestBucket < Minitest::Test
|
21
4
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
Couchbase.new("http://#{configs.host}:#{configs.port}"),
|
26
|
-
Couchbase.new(:port => configs.port),
|
27
|
-
Couchbase.new("http://#{configs.host}:8091", :port => configs.port)
|
28
|
-
]
|
29
|
-
connections.each do |connection|
|
30
|
-
assert_equal configs.port, connection.port
|
31
|
-
assert_equal "#{configs.host}:#{configs.port}", connection.authority
|
32
|
-
assert_equal "http://#{configs.host}:#{configs.port}/pools/default/buckets/default/", connection.url
|
33
|
-
end
|
34
|
-
connections.each(&:disconnect)
|
35
|
-
end
|
36
|
-
|
37
|
-
with_configs(:host => '127.0.0.1') do |configs|
|
38
|
-
connections = [
|
39
|
-
Couchbase.new("http://#{configs.host}:#{configs.port}"),
|
40
|
-
Couchbase.new(:hostname => configs.host, :port => configs.port),
|
41
|
-
Couchbase.new('http://example.com:8091', :hostname => configs.host, :port => configs.port)
|
42
|
-
]
|
43
|
-
connections.each do |connection|
|
44
|
-
assert_equal configs.host, connection.hostname
|
45
|
-
assert_equal "#{configs.host}:#{configs.port}", connection.authority
|
46
|
-
assert_equal "http://#{configs.host}:#{configs.port}/pools/default/buckets/default/", connection.url
|
47
|
-
end
|
48
|
-
connections.each(&:disconnect)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_it_raises_network_error_if_server_not_found
|
53
|
-
skip 'Exception not being trapped correctly'
|
54
|
-
refute(`netstat -tnl` =~ /12345/)
|
55
|
-
assert_raises Couchbase::Error::Connect do
|
56
|
-
Couchbase.new(:port => 12345)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_it_raises_argument_error_for_illegal_url
|
61
|
-
illegal = [
|
62
|
-
"ftp://localhost:8091/",
|
63
|
-
"http:/localhost:8091/",
|
64
|
-
""
|
65
|
-
]
|
66
|
-
illegal.each do |url|
|
67
|
-
assert_raises ArgumentError do
|
68
|
-
Couchbase.new(url)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_it_able_to_connect_to_protected_buckets
|
74
|
-
skip
|
75
|
-
with_configs(:buckets_spec => 'protected:secret') do |configs|
|
76
|
-
connection = Couchbase.new(:hostname => configs.host,
|
77
|
-
:port => configs.port,
|
78
|
-
:bucket => 'protected',
|
79
|
-
:username => 'protected',
|
80
|
-
:password => 'secret')
|
81
|
-
assert_equal "protected", connection.bucket
|
82
|
-
assert_equal "protected", connection.username
|
83
|
-
assert_equal "secret", connection.password
|
84
|
-
connection.disconnect
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_it_allows_to_specify_credentials_in_url
|
89
|
-
skip
|
90
|
-
with_configs(:buckets_spec => 'protected:secret') do |configs|
|
91
|
-
connection = Couchbase.new("http://protected:secret@#{configs.host}:#{configs.port}/pools/default/buckets/protected/")
|
92
|
-
assert_equal "protected", connection.bucket
|
93
|
-
assert_equal "protected", connection.username
|
94
|
-
assert_equal "secret", connection.password
|
95
|
-
connection.disconnect
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_it_raises_error_with_wrong_credentials
|
100
|
-
skip unless $mock.real?
|
101
|
-
with_configs do |configs|
|
102
|
-
assert_raises Couchbase::Error::Auth do
|
103
|
-
Couchbase.new(:hostname => configs.host,
|
104
|
-
:port => configs.port,
|
105
|
-
:bucket => 'default',
|
106
|
-
:username => 'wrong.username',
|
107
|
-
:password => 'wrong_password')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_it_unable_to_connect_to_protected_buckets_with_wrong_credentials
|
113
|
-
skip
|
114
|
-
with_configs(:buckets_spec => 'protected:secret') do |configs|
|
115
|
-
assert_raises Couchbase::Error::Auth do
|
116
|
-
Couchbase.new(:hostname => configs.host,
|
117
|
-
:port => configs.port,
|
118
|
-
:bucket => 'protected',
|
119
|
-
:username => 'wrong',
|
120
|
-
:password => 'secret')
|
121
|
-
end
|
122
|
-
assert_raises Couchbase::Error::Auth do
|
123
|
-
Couchbase.new(:hostname => configs.host,
|
124
|
-
:port => configs.port,
|
125
|
-
:bucket => 'protected',
|
126
|
-
:username => 'protected',
|
127
|
-
:password => 'wrong')
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_it_allows_change_quiet_flag
|
133
|
-
with_configs do |configs|
|
134
|
-
connection = Couchbase.new(:hostname => configs.host,
|
135
|
-
:port => configs.port)
|
136
|
-
|
137
|
-
refute connection.quiet?
|
138
|
-
|
139
|
-
connection.disconnect
|
140
|
-
connection = Couchbase.new(:hostname => configs.host,
|
141
|
-
:port => configs.port,
|
142
|
-
:quiet => true)
|
143
|
-
assert connection.quiet?
|
144
|
-
|
145
|
-
connection.quiet = nil
|
146
|
-
assert_equal false, connection.quiet?
|
147
|
-
|
148
|
-
connection.quiet = :foo
|
149
|
-
assert_equal true, connection.quiet?
|
150
|
-
connection.disconnect
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_it_is_connected
|
155
|
-
with_configs do |configs|
|
156
|
-
connection = Couchbase.new(:hostname => configs.host,
|
157
|
-
:port => configs.port)
|
158
|
-
assert connection.connected?
|
159
|
-
connection.disconnect
|
160
|
-
end
|
5
|
+
def test_async_access
|
6
|
+
assert_instance_of com.couchbase.client.java.CouchbaseAsyncBucket,
|
7
|
+
Couchbase.bucket.async
|
161
8
|
end
|
162
9
|
|
163
|
-
def
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
refute connection.connected?
|
169
|
-
end
|
10
|
+
def test_legacy_set_and_get
|
11
|
+
obj = { 'a' => 1, 'b' => 'b', 'c' => true, 'd' => [1, 2, 3] }
|
12
|
+
assert Couchbase.bucket.set('a', obj)
|
13
|
+
doc = Couchbase.bucket.get('a')
|
14
|
+
assert_equal obj, doc.to_h
|
170
15
|
end
|
171
16
|
|
172
|
-
def
|
173
|
-
|
174
|
-
|
175
|
-
:port => configs.port)
|
176
|
-
connection.disconnect
|
177
|
-
assert_raises Couchbase::Error::Connect do
|
178
|
-
connection.disconnect
|
179
|
-
end
|
180
|
-
end
|
17
|
+
def test_get_and_set_string
|
18
|
+
assert Couchbase.bucket.set('a', 'a')
|
19
|
+
assert_equal 'a', Couchbase.bucket.get('a').to_s
|
181
20
|
end
|
182
21
|
|
183
|
-
def
|
184
|
-
|
185
|
-
connection = Couchbase.new(:hostname => configs.host,
|
186
|
-
:port => configs.port)
|
187
|
-
connection.disconnect
|
188
|
-
refute connection.connected?
|
189
|
-
connection.reconnect
|
190
|
-
assert connection.connected?
|
191
|
-
assert connection.set(uniq_id, "foo")
|
192
|
-
connection.disconnect
|
193
|
-
end
|
22
|
+
def test_flush_bucket
|
23
|
+
assert Couchbase.bucket.flush
|
194
24
|
end
|
195
|
-
|
196
|
-
def test_it_allows_to_change_configuration_during_reconnect
|
197
|
-
skip
|
198
|
-
with_configs do |configs|
|
199
|
-
connection = Couchbase.new(:quiet => true)
|
200
|
-
assert connection.quiet?
|
201
|
-
connection.disconnect
|
202
|
-
|
203
|
-
connection.reconnect(:quiet => false)
|
204
|
-
refute connection.quiet?
|
205
|
-
connection.disconnect
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_it_uses_bucket_name_as_username_if_username_is_empty
|
210
|
-
skip
|
211
|
-
with_configs(:buckets_spec => 'protected:secret') do |configs|
|
212
|
-
connection = Couchbase.new(:hostname => configs.host,
|
213
|
-
:port => configs.port,
|
214
|
-
:bucket => 'protected',
|
215
|
-
:password => 'secret')
|
216
|
-
assert connection.connected?
|
217
|
-
connection.disconnect
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_it_converts_options_keys_to_symbols
|
222
|
-
bucket = Couchbase::Bucket.new('quiet' => true, 'default_ttl' => 10)
|
223
|
-
assert bucket.quiet?
|
224
|
-
assert_equal 10, bucket.default_ttl
|
225
|
-
bucket.disconnect
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_can_flush_bucket
|
229
|
-
skip unless $mock.real?
|
230
|
-
assert cb.flush
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_replaces_nil_password_with_string
|
234
|
-
connection = Couchbase.new(password: nil)
|
235
|
-
assert_equal '', connection.password
|
236
|
-
connection.disconnect
|
237
|
-
end
|
238
|
-
|
239
25
|
end
|
data/test/test_cluster.rb
CHANGED
@@ -1,33 +1,5 @@
|
|
1
|
-
|
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
|
-
require File.join(File.dirname(__FILE__), 'setup')
|
1
|
+
require 'helper'
|
18
2
|
|
19
3
|
class TestCluster < Minitest::Test
|
20
4
|
|
21
|
-
def setup
|
22
|
-
@cluster = Couchbase::Cluster.new(username: 'admin', password: 'password')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_that_it_can_connect_to_cluster_manager
|
26
|
-
assert @cluster
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_can_list_buckets
|
30
|
-
assert @cluster.list_buckets.include?('default')
|
31
|
-
end
|
32
|
-
|
33
5
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestConfiguration < Minitest::Test
|
4
|
+
|
5
|
+
SINGLE_CONFIG = {
|
6
|
+
host: '127.0.0.1',
|
7
|
+
bucket: 'fu',
|
8
|
+
password: 'abc123'
|
9
|
+
}
|
10
|
+
|
11
|
+
MULTIPLE_HOSTS = {
|
12
|
+
hosts: %w(host1 host2),
|
13
|
+
bucket: 'bar',
|
14
|
+
password: 'abc123'
|
15
|
+
}
|
16
|
+
|
17
|
+
MULTIPLE_BUCKETS = {
|
18
|
+
host: '127.0.0.1',
|
19
|
+
buckets: [
|
20
|
+
{ 'name' => 'fu', 'password' => 'abc123' },
|
21
|
+
{ 'name' => 'bar', 'password' => 'abc123' }
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
def test_default
|
26
|
+
config = Couchbase::Configuration.new
|
27
|
+
assert_equal ['localhost'], config.hosts
|
28
|
+
assert_equal 'default', config.buckets.first.name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_single_config
|
32
|
+
config = Couchbase::Configuration.new(SINGLE_CONFIG)
|
33
|
+
assert_equal ['127.0.0.1'], config.hosts
|
34
|
+
assert_equal 'fu', config.buckets.first.name
|
35
|
+
assert_equal 'abc123', config.buckets.first.password
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_multiple_hosts
|
39
|
+
config = Couchbase::Configuration.new(MULTIPLE_HOSTS)
|
40
|
+
assert_equal %w(host1 host2), config.hosts
|
41
|
+
assert_equal 'bar', config.buckets[0].name
|
42
|
+
assert_equal 'abc123', config.buckets[0].password
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_multiple_buckets
|
46
|
+
config = Couchbase::Configuration.new(MULTIPLE_BUCKETS)
|
47
|
+
assert_equal ['127.0.0.1'], config.hosts
|
48
|
+
assert_equal 'fu', config.buckets[0].name
|
49
|
+
assert_equal 'bar', config.buckets[1].name
|
50
|
+
end
|
51
|
+
end
|
data/test/test_couchbase.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
|
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')
|
1
|
+
require 'helper'
|
19
2
|
|
20
3
|
class TestCouchbase < Minitest::Test
|
21
4
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
5
|
+
def test_couchbase_module
|
6
|
+
assert Couchbase.is_a? Module
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_couchbase_init
|
10
|
+
assert_instance_of Module, Couchbase
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_cluster_access
|
14
|
+
assert_instance_of Couchbase::Cluster, Couchbase.cluster
|
28
15
|
end
|
29
16
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
17
|
+
def test_bucket_access
|
18
|
+
assert_instance_of Couchbase::Bucket, Couchbase.bucket
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_connection_status
|
22
|
+
Couchbase.bucket
|
23
|
+
assert Couchbase.connected?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_configuration_error
|
27
|
+
Couchbase.bucket
|
28
|
+
assert_raises Couchbase::ConfigurationError do
|
29
|
+
Couchbase.connection_options = {}
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
33
|
+
def test_multiple_bukets
|
34
|
+
assert_instance_of Couchbase::Bucket, Couchbase.buckets[:default]
|
35
|
+
assert_instance_of Couchbase::Bucket, Couchbase.bucket(:default)
|
36
|
+
end
|
37
37
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDesignDoc < Minitest::Test
|
4
|
+
|
5
|
+
def test_create_design_doc
|
6
|
+
dd = {
|
7
|
+
by_foo: {
|
8
|
+
map: <<-JS
|
9
|
+
function(doc, meta) {
|
10
|
+
emit(doc.id, null)
|
11
|
+
}
|
12
|
+
JS
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
design_doc = Couchbase::DesignDoc.new('bar', dd)
|
17
|
+
assert_instance_of com.couchbase.client.java.view.DesignDocument,
|
18
|
+
design_doc.create
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_incorrect_doc_format
|
22
|
+
dd = {
|
23
|
+
by_fu: ''
|
24
|
+
}
|
25
|
+
assert_raises Couchbase::DesignDocFormatError do
|
26
|
+
Couchbase::DesignDoc.new('bar', dd)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDocument < Minitest::Test
|
4
|
+
include Couchbase
|
5
|
+
|
6
|
+
java_import com.couchbase.client.java.document.RawJsonDocument
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@json_string = '{"a":1,"b":2,"c":3}'
|
10
|
+
@json_hash = MultiJson.load(@json_string)
|
11
|
+
@document = Document.new(RawJsonDocument.create('doc', 100, @json_string))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_java_doc_conversion
|
15
|
+
assert_equal 'doc', @document.id
|
16
|
+
assert_equal 0, @document.cas
|
17
|
+
assert_equal 100, @document.ttl
|
18
|
+
assert_equal @json_string, @document.content
|
19
|
+
assert_equal @json_string, @document.to_s
|
20
|
+
assert_equal @json_string, "#{@document}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_hash_conversion
|
24
|
+
assert_equal @json_hash, @document.to_h
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_array_conversion
|
28
|
+
assert_equal @json_hash, @document.to_a
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_implicit_hash_conversion
|
32
|
+
assert_equal 1, @document['a']
|
33
|
+
assert_equal 2, @document['b']
|
34
|
+
assert_equal 3, @document['c']
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_each
|
38
|
+
@document.each do |pair|
|
39
|
+
assert_instance_of Array, pair
|
40
|
+
assert_instance_of String, pair[0]
|
41
|
+
assert_instance_of Fixnum, pair[1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_each_pair
|
46
|
+
@document.each_pair do |k, v|
|
47
|
+
assert_instance_of String, k
|
48
|
+
assert_instance_of Fixnum, v
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestOperations < Minitest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@bucket = Couchbase.bucket
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_set_and_get
|
10
|
+
assert @bucket.set(uniq_id, a: 1)
|
11
|
+
assert_equal({ 'a' => 1 }, @bucket.get(uniq_id).to_h)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_set_and_remove
|
15
|
+
assert @bucket.set(uniq_id, a: 1)
|
16
|
+
assert @bucket.remove(uniq_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add_and_get
|
20
|
+
assert @bucket.add(uniq_id, a: 1)
|
21
|
+
assert_equal({ 'a' => 1 }, @bucket.get(uniq_id).to_h)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_set_and_get_plain
|
25
|
+
assert @bucket.set(uniq_id, a: 1)
|
26
|
+
assert_equal '{"a":1}', @bucket.get(uniq_id).to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_set_with_string_and_get_plain
|
30
|
+
assert @bucket.set(uniq_id, '{"a":1}')
|
31
|
+
assert_equal '{"a":1}', @bucket.get(uniq_id).to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_set_with_string_and_get
|
35
|
+
assert @bucket.set(uniq_id, '{"a":1}')
|
36
|
+
assert_equal({ 'a' => 1 }, @bucket.get(uniq_id).to_h)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_set_with_ttl
|
40
|
+
assert @bucket.set(uniq_id, { a: 1 }, ttl: 1)
|
41
|
+
refute_nil @bucket.get(uniq_id)
|
42
|
+
sleep 2
|
43
|
+
assert_nil @bucket.get(uniq_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_set_with_persist_to
|
47
|
+
assert @bucket.set(uniq_id, { a: 1 }, persist_to: :master)
|
48
|
+
end
|
49
|
+
end
|