jmoses-couchbase 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +15 -0
  2. data/.travis.yml +22 -0
  3. data/.yardopts +5 -0
  4. data/CONTRIBUTING.markdown +75 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +201 -0
  7. data/Makefile +3 -0
  8. data/README.markdown +665 -0
  9. data/RELEASE_NOTES.markdown +819 -0
  10. data/Rakefile +20 -0
  11. data/couchbase.gemspec +49 -0
  12. data/examples/chat-em/Gemfile +7 -0
  13. data/examples/chat-em/README.markdown +45 -0
  14. data/examples/chat-em/server.rb +82 -0
  15. data/examples/chat-goliath-grape/Gemfile +5 -0
  16. data/examples/chat-goliath-grape/README.markdown +50 -0
  17. data/examples/chat-goliath-grape/app.rb +67 -0
  18. data/examples/chat-goliath-grape/config/app.rb +20 -0
  19. data/examples/transcoders/Gemfile +3 -0
  20. data/examples/transcoders/README.markdown +59 -0
  21. data/examples/transcoders/cb-zcat +40 -0
  22. data/examples/transcoders/cb-zcp +45 -0
  23. data/examples/transcoders/gzip_transcoder.rb +49 -0
  24. data/examples/transcoders/options.rb +54 -0
  25. data/ext/couchbase_ext/.gitignore +4 -0
  26. data/ext/couchbase_ext/arguments.c +956 -0
  27. data/ext/couchbase_ext/arithmetic.c +316 -0
  28. data/ext/couchbase_ext/bucket.c +1373 -0
  29. data/ext/couchbase_ext/context.c +65 -0
  30. data/ext/couchbase_ext/couchbase_ext.c +1364 -0
  31. data/ext/couchbase_ext/couchbase_ext.h +644 -0
  32. data/ext/couchbase_ext/delete.c +163 -0
  33. data/ext/couchbase_ext/eventmachine_plugin.c +452 -0
  34. data/ext/couchbase_ext/extconf.rb +169 -0
  35. data/ext/couchbase_ext/get.c +316 -0
  36. data/ext/couchbase_ext/gethrtime.c +129 -0
  37. data/ext/couchbase_ext/http.c +432 -0
  38. data/ext/couchbase_ext/multithread_plugin.c +1090 -0
  39. data/ext/couchbase_ext/observe.c +171 -0
  40. data/ext/couchbase_ext/plugin_common.c +171 -0
  41. data/ext/couchbase_ext/result.c +129 -0
  42. data/ext/couchbase_ext/stats.c +163 -0
  43. data/ext/couchbase_ext/store.c +542 -0
  44. data/ext/couchbase_ext/timer.c +192 -0
  45. data/ext/couchbase_ext/touch.c +186 -0
  46. data/ext/couchbase_ext/unlock.c +176 -0
  47. data/ext/couchbase_ext/utils.c +551 -0
  48. data/ext/couchbase_ext/version.c +142 -0
  49. data/lib/action_dispatch/middleware/session/couchbase_store.rb +38 -0
  50. data/lib/active_support/cache/couchbase_store.rb +430 -0
  51. data/lib/couchbase.rb +155 -0
  52. data/lib/couchbase/bucket.rb +457 -0
  53. data/lib/couchbase/cluster.rb +119 -0
  54. data/lib/couchbase/connection_pool.rb +58 -0
  55. data/lib/couchbase/constants.rb +12 -0
  56. data/lib/couchbase/result.rb +26 -0
  57. data/lib/couchbase/transcoder.rb +120 -0
  58. data/lib/couchbase/utils.rb +62 -0
  59. data/lib/couchbase/version.rb +21 -0
  60. data/lib/couchbase/view.rb +506 -0
  61. data/lib/couchbase/view_row.rb +272 -0
  62. data/lib/ext/multi_json_fix.rb +56 -0
  63. data/lib/rack/session/couchbase.rb +108 -0
  64. data/tasks/benchmark.rake +6 -0
  65. data/tasks/compile.rake +160 -0
  66. data/tasks/test.rake +100 -0
  67. data/tasks/util.rake +21 -0
  68. data/test/profile/.gitignore +1 -0
  69. data/test/profile/Gemfile +6 -0
  70. data/test/profile/benchmark.rb +195 -0
  71. data/test/setup.rb +178 -0
  72. data/test/test_arithmetic.rb +185 -0
  73. data/test/test_async.rb +316 -0
  74. data/test/test_bucket.rb +276 -0
  75. data/test/test_cas.rb +235 -0
  76. data/test/test_couchbase.rb +77 -0
  77. data/test/test_couchbase_connection_pool.rb +77 -0
  78. data/test/test_couchbase_rails_cache_store.rb +361 -0
  79. data/test/test_delete.rb +120 -0
  80. data/test/test_errors.rb +82 -0
  81. data/test/test_eventmachine.rb +70 -0
  82. data/test/test_format.rb +164 -0
  83. data/test/test_get.rb +407 -0
  84. data/test/test_stats.rb +57 -0
  85. data/test/test_store.rb +216 -0
  86. data/test/test_timer.rb +42 -0
  87. data/test/test_touch.rb +97 -0
  88. data/test/test_unlock.rb +119 -0
  89. data/test/test_utils.rb +58 -0
  90. data/test/test_version.rb +52 -0
  91. metadata +353 -0
@@ -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
@@ -0,0 +1,216 @@
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 TestStore < 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_set
31
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
+ cas = connection.set(uniq_id, "bar")
33
+ assert(cas > 0)
34
+ end
35
+
36
+ def test_set_with_cas
37
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
38
+
39
+ cas1 = connection.set(uniq_id, "bar1")
40
+ assert cas1 > 0
41
+
42
+ assert_raises(Couchbase::Error::KeyExists) do
43
+ connection.set(uniq_id, "bar2", :cas => cas1+1)
44
+ end
45
+
46
+ cas2 = connection.set(uniq_id, "bar2", :cas => cas1)
47
+ assert cas2 > 0
48
+ refute_equal cas2, cas1
49
+
50
+ cas3 = connection.set(uniq_id, "bar3")
51
+ assert cas3 > 0
52
+ refute_equal cas3, cas2
53
+ refute_equal cas3, cas1
54
+ end
55
+
56
+ def test_add
57
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
58
+
59
+ cas1 = connection.add(uniq_id, "bar")
60
+ assert cas1 > 0
61
+
62
+ assert_raises(Couchbase::Error::KeyExists) do
63
+ connection.add(uniq_id, "bar")
64
+ end
65
+
66
+ assert_raises(Couchbase::Error::KeyExists) do
67
+ connection.add(uniq_id, "bar", :cas => cas1)
68
+ end
69
+ end
70
+
71
+ def test_replace
72
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
73
+
74
+ assert_raises(Couchbase::Error::NotFound) do
75
+ connection.replace(uniq_id, "bar")
76
+ end
77
+
78
+ cas1 = connection.set(uniq_id, "bar")
79
+ assert cas1 > 0
80
+
81
+ connection.replace(uniq_id, "bar")
82
+ end
83
+
84
+ def test_acceptable_keys
85
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
86
+
87
+ cas = connection.set(uniq_id.to_sym, "bar")
88
+ assert cas > 0
89
+
90
+ cas = connection.set(uniq_id.to_s, "bar")
91
+ assert cas > 0
92
+
93
+ assert_raises(TypeError) do
94
+ connection.set(nil, "bar")
95
+ end
96
+
97
+ obj = {:foo => "bar", :baz => 1}
98
+ assert_raises(TypeError) do
99
+ connection.set(obj, "bar")
100
+ end
101
+
102
+ class << obj
103
+ alias :to_str :to_s
104
+ end
105
+
106
+ connection.set(obj, "bar")
107
+ assert cas > 0
108
+ end
109
+
110
+ def test_asynchronous_set
111
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
112
+ ret = nil
113
+ connection.run do |conn|
114
+ conn.set(uniq_id("1"), "foo1") {|res| ret = res}
115
+ conn.set(uniq_id("2"), "foo2") # ignore result
116
+ end
117
+ assert ret.is_a?(Couchbase::Result)
118
+ assert ret.success?
119
+ assert_equal uniq_id("1"), ret.key
120
+ assert_equal :set, ret.operation
121
+ assert ret.cas.is_a?(Numeric)
122
+ end
123
+
124
+ def test_it_raises_error_when_appending_or_prepending_to_missing_key
125
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
126
+
127
+ assert_raises(Couchbase::Error::NotStored) do
128
+ connection.append(uniq_id(:missing), "foo")
129
+ end
130
+
131
+ assert_raises(Couchbase::Error::NotStored) do
132
+ connection.prepend(uniq_id(:missing), "foo")
133
+ end
134
+ end
135
+
136
+ def test_append
137
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
138
+
139
+ cas1 = connection.set(uniq_id, "foo")
140
+ assert cas1 > 0
141
+ cas2 = connection.append(uniq_id, "bar")
142
+ assert cas2 > 0
143
+ refute_equal cas2, cas1
144
+
145
+ val = connection.get(uniq_id)
146
+ assert_equal "foobar", val
147
+ end
148
+
149
+ def test_prepend
150
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
151
+
152
+ cas1 = connection.set(uniq_id, "foo")
153
+ assert cas1 > 0
154
+ cas2 = connection.prepend(uniq_id, "bar")
155
+ assert cas2 > 0
156
+ refute_equal cas2, cas1
157
+
158
+ val = connection.get(uniq_id)
159
+ assert_equal "barfoo", val
160
+ end
161
+
162
+ def test_set_with_prefix
163
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => "prefix:")
164
+ connection.set(uniq_id(:foo), "bar")
165
+ assert_equal "bar", connection.get(uniq_id(:foo))
166
+ expected = {uniq_id(:foo) => "bar"}
167
+ assert_equal expected, connection.get(uniq_id(:foo), :assemble_hash => true)
168
+
169
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => nil)
170
+ expected = {"prefix:#{uniq_id(:foo)}" => "bar"}
171
+ assert_equal expected, connection.get("prefix:#{uniq_id(:foo)}", :assemble_hash => true)
172
+ end
173
+
174
+ ArbitraryData = Struct.new(:baz)
175
+
176
+ def test_set_using_brackets
177
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
178
+
179
+ connection[uniq_id(1)] = "foo"
180
+ val = connection.get(uniq_id(1))
181
+ assert_equal "foo", val
182
+
183
+ if RUBY_VERSION =~ /^1\.9/
184
+ eval <<-EOC
185
+ connection[uniq_id(2), :flags => 0x1100] = "bar"
186
+ val, flags = connection.get(uniq_id(2), :extended => true)
187
+ assert_equal "bar", val
188
+ assert_equal 0x1100, flags
189
+
190
+ connection[uniq_id(3), :format => :marshal] = ArbitraryData.new("thing")
191
+ val = connection.get(uniq_id(3))
192
+ assert val.is_a?(ArbitraryData)
193
+ assert_equal "thing", val.baz
194
+ EOC
195
+ end
196
+ end
197
+
198
+ def test_multi_store
199
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
200
+ connection.add(uniq_id(:a) => "bbb", uniq_id(:z) => "yyy")
201
+ assert_equal ["bbb", "yyy"], connection.get(uniq_id(:a), uniq_id(:z))
202
+
203
+ connection.prepend(uniq_id(:a) => "aaa", uniq_id(:z) => "xxx")
204
+ assert_equal ["aaabbb", "xxxyyy"], connection.get(uniq_id(:a), uniq_id(:z))
205
+
206
+ connection.append(uniq_id(:a) => "ccc", uniq_id(:z) => "zzz")
207
+ assert_equal ["aaabbbccc", "xxxyyyzzz"], connection.get(uniq_id(:a), uniq_id(:z))
208
+
209
+ connection.replace(uniq_id(:a) => "foo", uniq_id(:z) => "bar")
210
+ assert_equal ["foo", "bar"], connection.get(uniq_id(:a), uniq_id(:z))
211
+
212
+ res = connection.set(uniq_id(:a) => "bar", uniq_id(:z) => "foo")
213
+ assert_equal ["bar", "foo"], connection.get(uniq_id(:a), uniq_id(:z))
214
+ assert res.is_a?(Hash)
215
+ end
216
+ end
@@ -0,0 +1,42 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 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 TestTimer < 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_initialization
31
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
+ num = 0
33
+ connection.run do
34
+ assert Couchbase::Timer.new(connection, 100) { num += 1}
35
+ assert connection.create_timer(100) { num += 1}
36
+
37
+ assert Couchbase::Timer.new(connection, 100, :periodic => true) {|t| num += 1; t.cancel}
38
+ assert connection.create_periodic_timer(100) {|t| num += 1; t.cancel}
39
+ end
40
+ assert_equal 4, num
41
+ end
42
+ end
@@ -0,0 +1,97 @@
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 TestTouch < 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_touch
31
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
+ connection.set(uniq_id, "bar", :ttl => 1)
33
+ connection.touch(uniq_id, :ttl => 2)
34
+ sleep(1)
35
+ assert connection.get(uniq_id)
36
+ sleep(2)
37
+ assert_raises(Couchbase::Error::NotFound) do
38
+ connection.get(uniq_id)
39
+ end
40
+ end
41
+
42
+ def test_multi_touch
43
+ connection = Couchbase.new(:port => @mock.port)
44
+ connection.set(uniq_id(1), "bar")
45
+ connection.set(uniq_id(2), "baz")
46
+ ret = connection.touch(uniq_id(1) => 1, uniq_id(2) => 1)
47
+ assert ret[uniq_id(1)]
48
+ assert ret[uniq_id(2)]
49
+ sleep(2)
50
+ assert_raises(Couchbase::Error::NotFound) do
51
+ connection.get(uniq_id(1))
52
+ end
53
+ assert_raises(Couchbase::Error::NotFound) do
54
+ connection.get(uniq_id(2))
55
+ end
56
+ end
57
+
58
+ def test_it_uses_default_ttl_for_touch
59
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_ttl => 1)
60
+ connection.set(uniq_id, "bar", :ttl => 10)
61
+ connection.touch(uniq_id)
62
+ sleep(2)
63
+ assert_raises(Couchbase::Error::NotFound) do
64
+ connection.get(uniq_id)
65
+ end
66
+ end
67
+
68
+ def test_it_accepts_ttl_for_get_command
69
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
70
+ connection.set(uniq_id, "bar", :ttl => 10)
71
+ val = connection.get(uniq_id, :ttl => 1)
72
+ assert_equal "bar", val
73
+ sleep(2)
74
+ assert_raises(Couchbase::Error::NotFound) do
75
+ connection.get(uniq_id)
76
+ end
77
+ end
78
+
79
+ def test_missing_in_quiet_mode
80
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
81
+ cas1 = connection.set(uniq_id(1), "foo1")
82
+ cas2 = connection.set(uniq_id(2), "foo2")
83
+
84
+ assert_raises(Couchbase::Error::NotFound) do
85
+ connection.touch(uniq_id(:missing), :quiet => false)
86
+ end
87
+
88
+ val = connection.touch(uniq_id(:missing))
89
+ refute(val)
90
+
91
+ ret = connection.touch(uniq_id(1), uniq_id(:missing), uniq_id(2))
92
+ assert_equal true, ret[uniq_id(1)]
93
+ assert_equal false, ret[uniq_id(:missing)]
94
+ assert_equal true, ret[uniq_id(2)]
95
+ end
96
+
97
+ end
@@ -0,0 +1,119 @@
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 TestTouch < 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_unlock
31
+ if @mock.real?
32
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
33
+ connection.set(uniq_id, "foo")
34
+ _, _, cas = connection.get(uniq_id, :lock => true, :extended => true)
35
+ assert_raises Couchbase::Error::KeyExists do
36
+ connection.set(uniq_id, "bar")
37
+ end
38
+ assert connection.unlock(uniq_id, :cas => cas)
39
+ connection.set(uniq_id, "bar")
40
+ else
41
+ skip("GETL and UNL aren't implemented in CouchbaseMock.jar yet")
42
+ end
43
+ end
44
+
45
+ def test_alternative_syntax_for_single_key
46
+ if @mock.real?
47
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
48
+ connection.set(uniq_id, "foo")
49
+ _, _, cas = connection.get(uniq_id, :lock => true, :extended => true)
50
+ assert_raises Couchbase::Error::KeyExists do
51
+ connection.set(uniq_id, "bar")
52
+ end
53
+ assert connection.unlock(uniq_id, cas)
54
+ connection.set(uniq_id, "bar")
55
+ else
56
+ skip("GETL and UNL aren't implemented in CouchbaseMock.jar yet")
57
+ end
58
+ end
59
+
60
+ def test_multiple_unlock
61
+ if @mock.real?
62
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
63
+ connection.set(uniq_id(1), "foo")
64
+ connection.set(uniq_id(2), "foo")
65
+ info = connection.get(uniq_id(1), uniq_id(2), :lock => true, :extended => true)
66
+ assert_raises Couchbase::Error::KeyExists do
67
+ connection.set(uniq_id(1), "bar")
68
+ end
69
+ assert_raises Couchbase::Error::KeyExists do
70
+ connection.set(uniq_id(2), "bar")
71
+ end
72
+ ret = connection.unlock(uniq_id(1) => info[uniq_id(1)][2],
73
+ uniq_id(2) => info[uniq_id(2)][2])
74
+ assert ret[uniq_id(1)]
75
+ assert ret[uniq_id(2)]
76
+ connection.set(uniq_id(1), "bar")
77
+ connection.set(uniq_id(2), "bar")
78
+ else
79
+ skip("GETL and UNL aren't implemented in CouchbaseMock.jar yet")
80
+ end
81
+ end
82
+
83
+ def test_quiet_mode
84
+ if @mock.real?
85
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
86
+ connection.set(uniq_id, "foo")
87
+ _, _, cas = connection.get(uniq_id, :lock => true, :extended => true)
88
+ assert_raises Couchbase::Error::NotFound do
89
+ connection.unlock(uniq_id(:missing), :cas => 0xdeadbeef)
90
+ end
91
+ keys = {
92
+ uniq_id => cas,
93
+ uniq_id(:missing) => 0xdeadbeef
94
+ }
95
+ ret = connection.unlock(keys, :quiet => true)
96
+ assert ret[uniq_id]
97
+ refute ret[uniq_id(:missing)]
98
+ else
99
+ skip("GETL and UNL aren't implemented in CouchbaseMock.jar yet")
100
+ end
101
+ end
102
+
103
+ def test_tmp_failure
104
+ if @mock.real?
105
+ connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
106
+ cas1 = connection.set(uniq_id(1), "foo")
107
+ cas2 = connection.set(uniq_id(2), "foo")
108
+ connection.get(uniq_id(1), :lock => true) # get with lock will update CAS
109
+ assert_raises Couchbase::Error::TemporaryFail do
110
+ connection.unlock(uniq_id(1), cas1)
111
+ end
112
+ assert_raises Couchbase::Error::TemporaryFail do
113
+ connection.unlock(uniq_id(2), cas2)
114
+ end
115
+ else
116
+ skip("GETL and UNL aren't implemented in CouchbaseMock.jar yet")
117
+ end
118
+ end
119
+ end