couchbase 1.0.0 → 1.1.0
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.
- data/.gitignore +2 -0
- data/.travis.yml +11 -0
- data/HISTORY.markdown +17 -0
- data/README.markdown +99 -59
- data/couchbase.gemspec +1 -0
- data/ext/couchbase_ext/couchbase_ext.c +1557 -425
- data/ext/couchbase_ext/extconf.rb +60 -49
- data/lib/couchbase.rb +41 -7
- data/lib/couchbase/bucket.rb +5 -3
- data/lib/couchbase/version.rb +1 -1
- data/tasks/compile.rake +72 -0
- data/tasks/test.rake +2 -2
- data/test/setup.rb +52 -2
- data/test/test_arithmetic.rb +37 -26
- data/test/test_async.rb +68 -44
- data/test/test_bucket.rb +130 -45
- data/test/test_cas.rb +8 -8
- data/test/test_couchbase.rb +1 -1
- data/test/test_delete.rb +15 -15
- data/test/test_errors.rb +6 -6
- data/test/test_flush.rb +3 -3
- data/test/test_format.rb +14 -14
- data/test/test_get.rb +144 -69
- data/test/test_stats.rb +18 -14
- data/test/test_store.rb +40 -40
- data/test/test_touch.rb +26 -14
- data/test/test_version.rb +30 -2
- metadata +34 -17
data/test/test_cas.rb
CHANGED
@@ -28,30 +28,30 @@ class TestCas < MiniTest::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_compare_and_swap
|
31
|
-
connection = Couchbase.new(:port => @mock.port,
|
31
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port,
|
32
32
|
:default_format => :document)
|
33
|
-
connection.set(
|
34
|
-
connection.cas(
|
33
|
+
connection.set(uniq_id, {"bar" => 1})
|
34
|
+
connection.cas(uniq_id) do |val|
|
35
35
|
val["baz"] = 2
|
36
36
|
val
|
37
37
|
end
|
38
|
-
val = connection.get(
|
38
|
+
val = connection.get(uniq_id)
|
39
39
|
expected = {"bar" => 1, "baz" => 2}
|
40
40
|
assert_equal expected, val
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_compare_and_swap_async
|
44
|
-
connection = Couchbase.new(:port => @mock.port,
|
44
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port,
|
45
45
|
:default_format => :document)
|
46
|
-
connection.set(
|
46
|
+
connection.set(uniq_id, {"bar" => 1})
|
47
47
|
connection.run do |conn|
|
48
|
-
conn.cas(
|
48
|
+
conn.cas(uniq_id) do |ret|
|
49
49
|
new_val = ret.value
|
50
50
|
new_val["baz"] = 2
|
51
51
|
new_val
|
52
52
|
end
|
53
53
|
end
|
54
|
-
val = connection.get(
|
54
|
+
val = connection.get(uniq_id)
|
55
55
|
expected = {"bar" => 1, "baz" => 2}
|
56
56
|
assert_equal expected, val
|
57
57
|
end
|
data/test/test_couchbase.rb
CHANGED
@@ -21,7 +21,7 @@ class TestCouchbase < MiniTest::Unit::TestCase
|
|
21
21
|
|
22
22
|
def test_that_it_create_instance_of_bucket
|
23
23
|
with_mock do |mock|
|
24
|
-
assert_instance_of Couchbase::Bucket, Couchbase.new("http
|
24
|
+
assert_instance_of Couchbase::Bucket, Couchbase.new("http://#{mock.host}:#{mock.port}/pools/default")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/test/test_delete.rb
CHANGED
@@ -28,36 +28,36 @@ class TestStore < MiniTest::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_trivial_delete
|
31
|
-
connection = Couchbase.new(:port => @mock.port)
|
32
|
-
connection.set(
|
33
|
-
assert connection.delete(
|
34
|
-
refute connection.delete(
|
31
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
32
|
+
connection.set(uniq_id, "bar")
|
33
|
+
assert connection.delete(uniq_id)
|
34
|
+
refute connection.delete(uniq_id)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_delete_missing
|
38
|
-
connection = Couchbase.new(:port => @mock.port)
|
39
|
-
refute connection.delete(
|
38
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
39
|
+
refute connection.delete(uniq_id(:missing))
|
40
40
|
connection.quiet = false
|
41
41
|
assert_raises(Couchbase::Error::NotFound) do
|
42
|
-
connection.delete(
|
42
|
+
connection.delete(uniq_id(:missing))
|
43
43
|
end
|
44
|
-
refute connection.delete(
|
44
|
+
refute connection.delete(uniq_id(:missing), :quiet => true)
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_delete_with_cas
|
48
|
-
connection = Couchbase.new(:port => @mock.port)
|
49
|
-
cas = connection.set(
|
48
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
49
|
+
cas = connection.set(uniq_id, "bar")
|
50
50
|
missing_cas = cas - 1
|
51
51
|
assert_raises(Couchbase::Error::KeyExists) do
|
52
|
-
connection.delete(
|
52
|
+
connection.delete(uniq_id, :cas => missing_cas)
|
53
53
|
end
|
54
|
-
assert connection.delete(
|
54
|
+
assert connection.delete(uniq_id, :cas => cas)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_allow_fixnum_as_cas_parameter
|
58
|
-
connection = Couchbase.new(:port => @mock.port)
|
59
|
-
cas = connection.set(
|
60
|
-
assert connection.delete(
|
58
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
59
|
+
cas = connection.set(uniq_id, "bar")
|
60
|
+
assert connection.delete(uniq_id, cas)
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
data/test/test_errors.rb
CHANGED
@@ -34,11 +34,11 @@ class TestErrors < MiniTest::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_graceful_add_with_collision
|
37
|
-
connection = Couchbase.new(:port => @mock.port)
|
37
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
38
38
|
msg1 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:09"}
|
39
|
-
key1 =
|
39
|
+
key1 = uniq_id(genkey(msg1))
|
40
40
|
msg2 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:30"}
|
41
|
-
key2 =
|
41
|
+
key2 = uniq_id(genkey(msg2))
|
42
42
|
|
43
43
|
connection.add(key1, msg1)
|
44
44
|
begin
|
@@ -58,12 +58,12 @@ class TestErrors < MiniTest::Unit::TestCase
|
|
58
58
|
|
59
59
|
msg3 = {"author" => "foo", "message" => "hi all",
|
60
60
|
"time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30"]}
|
61
|
-
key3 =
|
61
|
+
key3 = uniq_id(genkey(msg3))
|
62
62
|
assert_equal msg3, connection.get(key3)
|
63
63
|
|
64
64
|
connection.run do |conn|
|
65
65
|
msg4 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:45:34"}
|
66
|
-
key4 =
|
66
|
+
key4 = uniq_id(genkey(msg4))
|
67
67
|
|
68
68
|
connection.add(key4, msg4) do |ret|
|
69
69
|
assert_equal :add, ret.operation
|
@@ -75,7 +75,7 @@ class TestErrors < MiniTest::Unit::TestCase
|
|
75
75
|
|
76
76
|
msg5 = {"author" => "foo", "message" => "hi all",
|
77
77
|
"time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30", "2012-01-12 11:45:34"]}
|
78
|
-
key5 =
|
78
|
+
key5 = uniq_id(genkey(msg5))
|
79
79
|
assert_equal msg5, connection.get(key5)
|
80
80
|
end
|
81
81
|
|
data/test/test_flush.rb
CHANGED
@@ -28,18 +28,18 @@ class TestFlush < MiniTest::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_trivial_flush
|
31
|
-
connection = Couchbase.new(:port => @mock.port)
|
31
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
32
32
|
assert connection.flush
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_flush_with_block
|
36
|
-
connection = Couchbase.new(:port => @mock.port)
|
36
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
37
37
|
flushed = {}
|
38
38
|
on_node_flush = lambda{|res| flushed[res.node] = res.success?}
|
39
39
|
connection.run do |conn|
|
40
40
|
conn.flush(&on_node_flush)
|
41
41
|
end
|
42
|
-
assert_equal
|
42
|
+
assert_equal @mock.num_nodes, flushed.size
|
43
43
|
flushed.each do |node, res|
|
44
44
|
assert node.is_a?(String)
|
45
45
|
assert res
|
data/test/test_format.rb
CHANGED
@@ -35,10 +35,10 @@ class TestFormat < MiniTest::Unit::TestCase
|
|
35
35
|
|
36
36
|
def test_default_document_format
|
37
37
|
orig_doc = {'name' => 'Twoflower', 'role' => 'The tourist'}
|
38
|
-
connection = Couchbase.new(:port => @mock.port)
|
38
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
39
39
|
assert_equal :document, connection.default_format
|
40
|
-
connection.set(
|
41
|
-
doc, flags, cas = connection.get(
|
40
|
+
connection.set(uniq_id, orig_doc)
|
41
|
+
doc, flags, cas = connection.get(uniq_id, :extended => true)
|
42
42
|
assert_equal 0x00, flags & 0x11
|
43
43
|
assert doc.is_a?(Hash)
|
44
44
|
assert_equal 'Twoflower', doc['name']
|
@@ -50,9 +50,9 @@ class TestFormat < MiniTest::Unit::TestCase
|
|
50
50
|
refute orig_doc.respond_to?(:to_s)
|
51
51
|
refute orig_doc.respond_to?(:to_json)
|
52
52
|
|
53
|
-
connection = Couchbase.new(:port => @mock.port, :default_format => :document)
|
53
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :document)
|
54
54
|
assert_raises(Couchbase::Error::ValueFormat) do
|
55
|
-
connection.set(
|
55
|
+
connection.set(uniq_id, orig_doc)
|
56
56
|
end
|
57
57
|
|
58
58
|
class << orig_doc
|
@@ -60,7 +60,7 @@ class TestFormat < MiniTest::Unit::TestCase
|
|
60
60
|
JSON.dump(:name => name, :role => role)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
connection.set(
|
63
|
+
connection.set(uniq_id, orig_doc) # OK
|
64
64
|
|
65
65
|
class << orig_doc
|
66
66
|
undef to_json
|
@@ -68,14 +68,14 @@ class TestFormat < MiniTest::Unit::TestCase
|
|
68
68
|
JSON.dump(:name => name, :role => role)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
connection.set(
|
71
|
+
connection.set(uniq_id, orig_doc) # OK
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_it_could_dump_arbitrary_class_using_marshal_format
|
75
75
|
orig_doc = ArbitraryClass.new("Twoflower", "The tourist")
|
76
|
-
connection = Couchbase.new(:port => @mock.port)
|
77
|
-
connection.set(
|
78
|
-
doc, flags, cas = connection.get(
|
76
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
77
|
+
connection.set(uniq_id, orig_doc, :format => :marshal)
|
78
|
+
doc, flags, cas = connection.get(uniq_id, :extended => true)
|
79
79
|
assert_equal 0x01, flags & 0x11
|
80
80
|
assert doc.is_a?(ArbitraryClass)
|
81
81
|
assert_equal 'Twoflower', doc.name
|
@@ -83,15 +83,15 @@ class TestFormat < MiniTest::Unit::TestCase
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_it_accepts_only_string_in_plain_mode
|
86
|
-
connection = Couchbase.new(:port => @mock.port, :default_format => :plain)
|
87
|
-
connection.set(
|
86
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
|
87
|
+
connection.set(uniq_id, "1")
|
88
88
|
|
89
89
|
assert_raises(Couchbase::Error::ValueFormat) do
|
90
|
-
connection.set(
|
90
|
+
connection.set(uniq_id, 1)
|
91
91
|
end
|
92
92
|
|
93
93
|
assert_raises(Couchbase::Error::ValueFormat) do
|
94
|
-
connection.set(
|
94
|
+
connection.set(uniq_id, {:foo => "bar"})
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
data/test/test_get.rb
CHANGED
@@ -28,112 +28,147 @@ class TestGet < MiniTest::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_trivial_get
|
31
|
-
connection = Couchbase.new(:port => @mock.port)
|
32
|
-
connection.set(
|
33
|
-
val = connection.get(
|
31
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
32
|
+
connection.set(uniq_id, "bar")
|
33
|
+
val = connection.get(uniq_id)
|
34
34
|
assert_equal "bar", val
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_extended_get
|
38
|
-
connection = Couchbase.new(:port => @mock.port)
|
38
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
39
39
|
|
40
|
-
orig_cas = connection.set(
|
41
|
-
val, flags, cas = connection.get(
|
40
|
+
orig_cas = connection.set(uniq_id, "bar")
|
41
|
+
val, flags, cas = connection.get(uniq_id, :extended => true)
|
42
42
|
assert_equal "bar", val
|
43
43
|
assert_equal 0x0, flags
|
44
44
|
assert_equal orig_cas, cas
|
45
45
|
|
46
|
-
orig_cas = connection.set(
|
47
|
-
val, flags, cas = connection.get(
|
46
|
+
orig_cas = connection.set(uniq_id, "bar", :flags => 0x1000)
|
47
|
+
val, flags, cas = connection.get(uniq_id, :extended => true)
|
48
48
|
assert_equal "bar", val
|
49
49
|
assert_equal 0x1000, flags
|
50
50
|
assert_equal orig_cas, cas
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_multi_get
|
54
|
-
connection = Couchbase.new(:port => @mock.port)
|
54
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
55
55
|
|
56
|
-
connection.set(
|
57
|
-
connection.set(
|
56
|
+
connection.set(uniq_id(1), "foo1")
|
57
|
+
connection.set(uniq_id(2), "foo2")
|
58
58
|
|
59
|
-
val1, val2 = connection.get(
|
59
|
+
val1, val2 = connection.get(uniq_id(1), uniq_id(2))
|
60
60
|
assert_equal "foo1", val1
|
61
61
|
assert_equal "foo2", val2
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_multi_get_extended
|
65
|
-
connection = Couchbase.new(:port => @mock.port)
|
65
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
66
66
|
|
67
|
-
cas1 = connection.set(
|
68
|
-
cas2 = connection.set(
|
67
|
+
cas1 = connection.set(uniq_id(1), "foo1")
|
68
|
+
cas2 = connection.set(uniq_id(2), "foo2")
|
69
69
|
|
70
|
-
results = connection.get(
|
71
|
-
assert_equal ["foo1", 0x0, cas1], results[
|
72
|
-
assert_equal ["foo2", 0x0, cas2], results[
|
70
|
+
results = connection.get(uniq_id(1), uniq_id(2), :extended => true)
|
71
|
+
assert_equal ["foo1", 0x0, cas1], results[uniq_id(1)]
|
72
|
+
assert_equal ["foo2", 0x0, cas2], results[uniq_id(2)]
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_multi_get_and_touch
|
76
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
77
|
+
connection.set(uniq_id(1), "foo1")
|
78
|
+
connection.set(uniq_id(2), "foo2")
|
79
|
+
|
80
|
+
results = connection.get(uniq_id(1) => 1, uniq_id(2) => 1)
|
81
|
+
assert results.is_a?(Hash)
|
82
|
+
assert_equal "foo1", results[uniq_id(1)]
|
83
|
+
assert_equal "foo2", results[uniq_id(2)]
|
84
|
+
sleep(2)
|
85
|
+
assert connection.get(uniq_id(1), uniq_id(2)).compact.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_multi_get_and_touch_extended
|
89
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
90
|
+
|
91
|
+
cas1 = connection.set(uniq_id(1), "foo1")
|
92
|
+
cas2 = connection.set(uniq_id(2), "foo2")
|
93
|
+
|
94
|
+
results = connection.get({uniq_id(1) => 1, uniq_id(2) => 1}, :extended => true)
|
95
|
+
assert_equal ["foo1", 0x0, cas1], results[uniq_id(1)]
|
96
|
+
assert_equal ["foo2", 0x0, cas2], results[uniq_id(2)]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_multi_get_and_touch_with_single_key
|
100
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
101
|
+
connection.set(uniq_id, "foo1")
|
102
|
+
|
103
|
+
results = connection.get(uniq_id => 1)
|
104
|
+
assert results.is_a?(Hash)
|
105
|
+
assert_equal "foo1", results[uniq_id]
|
106
|
+
sleep(2)
|
107
|
+
refute = connection.get(uniq_id)
|
73
108
|
end
|
74
109
|
|
75
110
|
def test_missing_in_quiet_mode
|
76
|
-
connection = Couchbase.new(:port => @mock.port)
|
77
|
-
cas1 = connection.set(
|
78
|
-
cas2 = connection.set(
|
111
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
112
|
+
cas1 = connection.set(uniq_id(1), "foo1")
|
113
|
+
cas2 = connection.set(uniq_id(2), "foo2")
|
79
114
|
|
80
|
-
val = connection.get(
|
115
|
+
val = connection.get(uniq_id(:missing))
|
81
116
|
refute(val)
|
82
|
-
val = connection.get(
|
117
|
+
val = connection.get(uniq_id(:missing), :extended => true)
|
83
118
|
refute(val)
|
84
119
|
|
85
|
-
val1, missing, val2 = connection.get(
|
120
|
+
val1, missing, val2 = connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
|
86
121
|
assert_equal "foo1", val1
|
87
122
|
refute missing
|
88
123
|
assert_equal "foo2", val2
|
89
124
|
|
90
|
-
results = connection.get(
|
91
|
-
assert_equal ["foo1", 0x0, cas1], results[
|
92
|
-
refute results[
|
93
|
-
assert_equal ["foo2", 0x0, cas2], results[
|
125
|
+
results = connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
|
126
|
+
assert_equal ["foo1", 0x0, cas1], results[uniq_id(1)]
|
127
|
+
refute results[uniq_id(:missing)]
|
128
|
+
assert_equal ["foo2", 0x0, cas2], results[uniq_id(2)]
|
94
129
|
end
|
95
130
|
|
96
131
|
def test_it_allows_temporary_quiet_flag
|
97
|
-
connection = Couchbase.new(:port => @mock.port, :quiet => false)
|
132
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => false)
|
98
133
|
assert_raises(Couchbase::Error::NotFound) do
|
99
|
-
connection.get(
|
134
|
+
connection.get(uniq_id(:missing))
|
100
135
|
end
|
101
|
-
refute connection.get(
|
136
|
+
refute connection.get(uniq_id(:missing), :quiet => true)
|
102
137
|
end
|
103
138
|
|
104
139
|
def test_missing_in_verbose_mode
|
105
|
-
connection = Couchbase.new(:port => @mock.port, :quiet => false)
|
106
|
-
connection.set(
|
107
|
-
connection.set(
|
140
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => false)
|
141
|
+
connection.set(uniq_id(1), "foo1")
|
142
|
+
connection.set(uniq_id(2), "foo2")
|
108
143
|
|
109
144
|
assert_raises(Couchbase::Error::NotFound) do
|
110
|
-
connection.get(
|
145
|
+
connection.get(uniq_id(:missing))
|
111
146
|
end
|
112
147
|
|
113
148
|
assert_raises(Couchbase::Error::NotFound) do
|
114
|
-
connection.get(
|
149
|
+
connection.get(uniq_id(:missing), :extended => true)
|
115
150
|
end
|
116
151
|
|
117
152
|
assert_raises(Couchbase::Error::NotFound) do
|
118
|
-
connection.get(
|
153
|
+
connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2))
|
119
154
|
end
|
120
155
|
|
121
156
|
assert_raises(Couchbase::Error::NotFound) do
|
122
|
-
connection.get(
|
157
|
+
connection.get(uniq_id(1), uniq_id(:missing), uniq_id(2), :extended => true)
|
123
158
|
end
|
124
159
|
end
|
125
160
|
|
126
161
|
def test_asynchronous_get
|
127
|
-
connection = Couchbase.new(:port => @mock.port)
|
128
|
-
cas = connection.set(
|
162
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
163
|
+
cas = connection.set(uniq_id, "foo", :flags => 0x6660)
|
129
164
|
res = []
|
130
165
|
|
131
166
|
suite = lambda do |conn|
|
132
167
|
res.clear
|
133
|
-
conn.get(
|
134
|
-
conn.get(
|
168
|
+
conn.get(uniq_id) # ignore result
|
169
|
+
conn.get(uniq_id) {|ret| res << ret}
|
135
170
|
handler = lambda {|ret| res << ret}
|
136
|
-
conn.get(
|
171
|
+
conn.get(uniq_id, &handler)
|
137
172
|
assert_equal 3, conn.seqno
|
138
173
|
end
|
139
174
|
|
@@ -141,7 +176,7 @@ class TestGet < MiniTest::Unit::TestCase
|
|
141
176
|
res.each do |r|
|
142
177
|
assert r.is_a?(Couchbase::Result)
|
143
178
|
assert r.success?
|
144
|
-
assert_equal
|
179
|
+
assert_equal uniq_id, r.key
|
145
180
|
assert_equal "foo", r.value
|
146
181
|
assert_equal 0x6660, r.flags
|
147
182
|
assert_equal cas, r.cas
|
@@ -156,25 +191,25 @@ class TestGet < MiniTest::Unit::TestCase
|
|
156
191
|
end
|
157
192
|
|
158
193
|
def test_asynchronous_multi_get
|
159
|
-
connection = Couchbase.new(:port => @mock.port)
|
160
|
-
connection.set(
|
161
|
-
connection.set(
|
194
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
195
|
+
connection.set(uniq_id(1), "foo")
|
196
|
+
connection.set(uniq_id(2), "bar")
|
162
197
|
|
163
198
|
res = {}
|
164
199
|
connection.run do |conn|
|
165
|
-
conn.get(
|
200
|
+
conn.get(uniq_id(1), uniq_id(2)) {|ret| res[ret.key] = ret.value}
|
166
201
|
assert_equal 2, conn.seqno
|
167
202
|
end
|
168
203
|
|
169
|
-
assert res[
|
170
|
-
assert_equal "foo", res[
|
171
|
-
assert res[
|
172
|
-
assert_equal "bar", res[
|
204
|
+
assert res[uniq_id(1)]
|
205
|
+
assert_equal "foo", res[uniq_id(1)]
|
206
|
+
assert res[uniq_id(2)]
|
207
|
+
assert_equal "bar", res[uniq_id(2)]
|
173
208
|
end
|
174
209
|
|
175
210
|
def test_asynchronous_get_missing
|
176
|
-
connection = Couchbase.new(:port => @mock.port)
|
177
|
-
connection.set(
|
211
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
212
|
+
connection.set(uniq_id, "foo")
|
178
213
|
res = {}
|
179
214
|
missing = []
|
180
215
|
|
@@ -194,43 +229,83 @@ class TestGet < MiniTest::Unit::TestCase
|
|
194
229
|
suite = lambda do |conn|
|
195
230
|
res.clear
|
196
231
|
missing.clear
|
197
|
-
conn.get(
|
198
|
-
conn.get(
|
232
|
+
conn.get(uniq_id(:missing1), &get_handler)
|
233
|
+
conn.get(uniq_id, uniq_id(:missing2), &get_handler)
|
199
234
|
assert 3, conn.seqno
|
200
235
|
end
|
201
236
|
|
202
237
|
connection.run(&suite)
|
203
|
-
assert_equal "foo", res[
|
204
|
-
assert res.has_key?(
|
205
|
-
refute res[
|
206
|
-
assert res.has_key?(
|
207
|
-
refute res[
|
238
|
+
assert_equal "foo", res[uniq_id]
|
239
|
+
assert res.has_key?(uniq_id(:missing1)) # handler was called with nil
|
240
|
+
refute res[uniq_id(:missing1)]
|
241
|
+
assert res.has_key?(uniq_id(:missing2))
|
242
|
+
refute res[uniq_id(:missing2)]
|
208
243
|
assert_empty missing
|
209
244
|
|
210
245
|
connection.quiet = false
|
211
246
|
|
212
247
|
connection.run(&suite)
|
213
|
-
refute res.has_key?(
|
214
|
-
refute res.has_key?(
|
215
|
-
assert_equal [
|
216
|
-
assert_equal "foo", res[
|
248
|
+
refute res.has_key?(uniq_id(:missing1))
|
249
|
+
refute res.has_key?(uniq_id(:missing2))
|
250
|
+
assert_equal [uniq_id(:missing1), uniq_id(:missing2)], missing.sort
|
251
|
+
assert_equal "foo", res[uniq_id]
|
217
252
|
end
|
218
253
|
|
219
254
|
def test_get_using_brackets
|
220
|
-
connection = Couchbase.new(:port => @mock.port)
|
255
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
221
256
|
|
222
|
-
orig_cas = connection.set(
|
257
|
+
orig_cas = connection.set(uniq_id, "foo", :flags => 0x1100)
|
223
258
|
|
224
|
-
val = connection[
|
259
|
+
val = connection[uniq_id]
|
225
260
|
assert_equal "foo", val
|
226
261
|
|
227
262
|
if RUBY_VERSION =~ /^1\.9/
|
228
263
|
eval <<-EOC
|
229
|
-
val, flags, cas = connection[
|
264
|
+
val, flags, cas = connection[uniq_id, :extended => true]
|
230
265
|
assert_equal "foo", val
|
231
266
|
assert_equal 0x1100, flags
|
232
267
|
assert_equal orig_cas, cas
|
233
268
|
EOC
|
234
269
|
end
|
235
270
|
end
|
271
|
+
|
272
|
+
def test_it_allows_to_store_nil
|
273
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
274
|
+
|
275
|
+
orig_cas = connection.set(uniq_id, nil)
|
276
|
+
assert orig_cas.is_a?(Numeric)
|
277
|
+
|
278
|
+
refute connection.get(uniq_id)
|
279
|
+
# doesn't raise NotFound exception
|
280
|
+
refute connection.get(uniq_id, :quiet => false)
|
281
|
+
# returns CAS
|
282
|
+
value, flags, cas = connection.get(uniq_id, :extended => true)
|
283
|
+
refute value
|
284
|
+
assert_equal 0x00, flags
|
285
|
+
assert_equal orig_cas, cas
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_zero_length_string_is_not_nil
|
289
|
+
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
|
290
|
+
|
291
|
+
connection.set(uniq_id, "", :format => :document)
|
292
|
+
assert_equal "", connection.get(uniq_id)
|
293
|
+
|
294
|
+
connection.set(uniq_id, "", :format => :plain)
|
295
|
+
assert_equal "", connection.get(uniq_id)
|
296
|
+
|
297
|
+
connection.set(uniq_id, "", :format => :marshal)
|
298
|
+
assert_equal "", connection.get(uniq_id)
|
299
|
+
|
300
|
+
connection.set(uniq_id, nil, :format => :document)
|
301
|
+
assert_equal nil, connection.get(uniq_id, :quiet => false)
|
302
|
+
|
303
|
+
assert_raises Couchbase::Error::ValueFormat do
|
304
|
+
connection.set(uniq_id, nil, :format => :plain)
|
305
|
+
end
|
306
|
+
|
307
|
+
connection.set(uniq_id, nil, :format => :marshal)
|
308
|
+
assert_equal nil, connection.get(uniq_id, :quiet => false)
|
309
|
+
end
|
310
|
+
|
236
311
|
end
|