couchbase-jruby-client 0.1.2 → 0.1.3

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/test/test_cas.rb CHANGED
@@ -19,34 +19,22 @@ require File.join(File.dirname(__FILE__), 'setup')
19
19
 
20
20
  class TestCas < MiniTest::Test
21
21
 
22
- def setup
23
- @mock = start_mock
24
- end
25
-
26
- def teardown
27
- stop_mock(@mock)
28
- end
29
-
30
22
  def test_compare_and_swap
31
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port,
32
- :default_format => :document)
33
- connection.set(uniq_id, {"bar" => 1})
34
- connection.cas(uniq_id) do |val|
23
+ cb.set(uniq_id, {"bar" => 1})
24
+ cb.cas(uniq_id) do |val|
35
25
  val["baz"] = 2
36
26
  val
37
27
  end
38
- val = connection.get(uniq_id)
28
+ val = cb.get(uniq_id)
39
29
  expected = {"bar" => 1, "baz" => 2}
40
30
  assert_equal expected, val
41
31
  end
42
32
 
43
33
  def test_compare_and_swap_async
44
34
  skip
45
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port,
46
- :default_format => :document)
47
- connection.set(uniq_id, {"bar" => 1})
35
+ cb.set(uniq_id, {"bar" => 1})
48
36
  calls = 0
49
- connection.run do |conn|
37
+ cb.run do |conn|
50
38
  conn.cas(uniq_id) do |ret|
51
39
  calls += 1
52
40
  case ret.operation
@@ -62,18 +50,16 @@ class TestCas < MiniTest::Test
62
50
  end
63
51
  end
64
52
  assert_equal 2, calls
65
- val = connection.get(uniq_id)
53
+ val = cb.get(uniq_id)
66
54
  expected = {"bar" => 1, "baz" => 2}
67
55
  assert_equal expected, val
68
56
  end
69
57
 
70
58
  def test_flags_replication
71
59
  skip
72
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port,
73
- :default_format => :document)
74
- connection.set(uniq_id, "bar", :flags => 0x100)
75
- connection.cas(uniq_id) { "baz" }
76
- _, flags, _ = connection.get(uniq_id, :extended => true)
60
+ cb.set(uniq_id, "bar", :flags => 0x100)
61
+ cb.cas(uniq_id) { "baz" }
62
+ _, flags, _ = cb.get(uniq_id, :extended => true)
77
63
  assert_equal 0x100, flags
78
64
  end
79
65
  end
@@ -16,18 +16,19 @@
16
16
  #
17
17
 
18
18
  require File.join(File.dirname(__FILE__), 'setup')
19
- require 'minitest/mock'
20
19
 
21
20
  class TestCouchbase < MiniTest::Test
22
21
 
23
22
  def test_that_it_create_instance_of_bucket
24
- with_mock do |mock|
25
- assert_instance_of Couchbase::Bucket, Couchbase.new("http://#{mock.host}:#{mock.port}")
23
+ with_configs do |configs|
24
+ connection = Couchbase.new("http://#{configs.host}:#{configs.port}")
25
+ assert_instance_of Couchbase::Bucket, connection
26
+ connection.disconnect
26
27
  end
27
28
  end
28
29
 
29
30
  def test_global_bucket_access
30
- with_mock do |mock|
31
+ with_configs do |configs|
31
32
  assert_instance_of Couchbase::Bucket, Couchbase.bucket
32
33
  assert_equal Couchbase.bucket, Couchbase.bucket
33
34
  end
data/test/test_delete.rb CHANGED
@@ -19,107 +19,105 @@ require File.join(File.dirname(__FILE__), 'setup')
19
19
 
20
20
  class TestStore < MiniTest::Test
21
21
 
22
- def setup
23
- @mock = start_mock
24
- end
25
-
26
- def teardown
27
- stop_mock(@mock)
28
- end
29
-
30
22
  def test_trivial_delete
31
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
32
- connection.set(uniq_id, "bar")
33
- assert connection.delete(uniq_id)
23
+ cb.set(uniq_id, "bar")
24
+ assert cb.delete(uniq_id)
34
25
  assert_raises(Couchbase::Error::NotFound) do
35
- connection.delete(uniq_id)
26
+ cb.delete(uniq_id)
36
27
  end
37
28
  end
38
29
 
39
30
  def test_delete_missing
40
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
41
31
  assert_raises(Couchbase::Error::NotFound) do
42
- connection.delete(uniq_id(:missing))
32
+ cb.delete(uniq_id(:missing))
43
33
  end
44
- refute connection.delete(uniq_id(:missing), :quiet => true)
45
- refute connection.quiet?
46
- connection.quiet = true
47
- refute connection.delete(uniq_id(:missing))
34
+ refute cb.delete(uniq_id(:missing), :quiet => true)
35
+ refute cb.quiet?
36
+ cb.quiet = true
37
+ refute cb.delete(uniq_id(:missing))
48
38
  end
49
39
 
50
40
  def test_delete_with_cas
51
41
  skip
52
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
53
- cas = connection.set(uniq_id, "bar")
42
+ cas = cb.set(uniq_id, "bar")
54
43
  missing_cas = cas - 1
55
44
  assert_raises(Couchbase::Error::KeyExists) do
56
- connection.delete(uniq_id, :cas => missing_cas)
45
+ cb.delete(uniq_id, :cas => missing_cas)
57
46
  end
58
- assert connection.delete(uniq_id, :cas => cas)
47
+ assert cb.delete(uniq_id, :cas => cas)
59
48
  end
60
49
 
61
50
  def test_allow_fixnum_as_cas_parameter
62
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
63
- cas = connection.set(uniq_id, "bar")
64
- assert connection.delete(uniq_id, cas)
51
+ cas = cb.set(uniq_id, "bar")
52
+ assert cb.delete(uniq_id, cas)
65
53
  end
66
54
 
67
55
  def test_delete_with_prefix
68
56
  skip
69
57
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => "prefix:")
70
- connection.set(uniq_id(:foo), "bar")
71
- assert connection.delete(uniq_id(:foo))
58
+ cb.set(uniq_id(:foo), "bar")
59
+ assert cb.delete(uniq_id(:foo))
72
60
  assert_raises(Couchbase::Error::NotFound) do
73
- connection.get(uniq_id(:foo))
61
+ cb.get(uniq_id(:foo))
74
62
  end
75
63
  end
76
64
 
77
65
  def test_simple_multi_delete
78
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
79
- connection.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
80
- res = connection.delete(uniq_id(1), uniq_id(2))
66
+ cb.quiet = true
67
+ cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
68
+ res = cb.delete(uniq_id(1), uniq_id(2))
81
69
  assert res.is_a?(Hash)
82
70
  assert res[uniq_id(1)]
83
71
  assert res[uniq_id(2)]
72
+ ensure
73
+ cb.quiet = false
84
74
  end
85
75
 
86
76
  def test_simple_multi_delete_missing
87
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
88
- connection.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
89
- res = connection.delete(uniq_id(1), uniq_id(:missing), :quiet => true)
77
+ cb.quiet = true
78
+ cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
79
+ res = cb.delete(uniq_id(1), uniq_id(:missing), :quiet => true)
90
80
  assert res.is_a?(Hash)
91
81
  assert res[uniq_id(1)]
92
82
  refute res[uniq_id(:missing)]
83
+ ensure
84
+ cb.quiet = false
93
85
  end
94
86
 
95
87
  def test_multi_delete_with_cas_check
96
88
  skip
97
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
98
- cas = connection.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
99
- res = connection.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(2) => cas[uniq_id(2)])
89
+ cb.quiet = true
90
+ cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
91
+ res = cb.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(2) => cas[uniq_id(2)])
100
92
  assert res.is_a?(Hash)
101
93
  assert res[uniq_id(1)]
102
94
  assert res[uniq_id(2)]
95
+ ensure
96
+ cb.quiet = false
103
97
  end
104
98
 
105
99
  def test_multi_delete_missing_with_cas_check
106
100
  skip
107
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
108
- cas = connection.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
109
- res = connection.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(:missing) => cas[uniq_id(2)])
101
+ cb.quiet = true
102
+ cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
103
+ res = cb.delete(uniq_id(1) => cas[uniq_id(1)], uniq_id(:missing) => cas[uniq_id(2)])
110
104
  assert res.is_a?(Hash)
111
105
  assert res[uniq_id(1)]
112
106
  refute res[uniq_id(:missing)]
107
+ ensure
108
+ cb.quiet = false
113
109
  end
114
110
 
115
111
  def test_multi_delete_with_cas_check_mismatch
116
112
  skip
117
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
118
- cas = connection.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
113
+ cb.quiet = true
114
+ cas = cb.set(uniq_id(1) => "bar", uniq_id(2) => "foo")
119
115
 
120
116
  assert_raises(Couchbase::Error::KeyExists) do
121
- connection.delete(uniq_id(1) => cas[uniq_id(1)] + 1,
117
+ cb.delete(uniq_id(1) => cas[uniq_id(1)] + 1,
122
118
  uniq_id(2) => cas[uniq_id(2)])
123
119
  end
120
+ ensure
121
+ cb.quiet = false
124
122
  end
125
123
  end
@@ -19,38 +19,28 @@ require File.join(File.dirname(__FILE__), 'setup')
19
19
 
20
20
  class TestDesignDocs < MiniTest::Test
21
21
 
22
- def setup
23
- @mock = start_mock
24
- @cb = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
25
- end
26
-
27
- def teardown
28
- stop_mock(@mock)
29
- @cb.disconnect
30
- end
31
-
32
22
  def test_save_design_doc
33
- assert @cb.save_design_doc(design_doc)
23
+ assert cb.save_design_doc(design_doc)
34
24
  end
35
25
 
36
26
  def test_save_design_doc_with_bad_data
37
27
  assert_raises ArgumentError do
38
- @cb.save_design_doc(123)
28
+ cb.save_design_doc(123)
39
29
  end
40
30
  end
41
31
 
42
32
  def test_delete_design_doc
43
- @cb.save_design_doc(design_doc)
44
- assert @cb.delete_design_doc('blog')
33
+ cb.save_design_doc(design_doc)
34
+ assert cb.delete_design_doc('blog')
45
35
  end
46
36
 
47
37
  def test_design_doc_access
48
- @cb.save_design_doc(design_doc)
49
- assert @cb.design_docs['blog']
38
+ cb.save_design_doc(design_doc)
39
+ assert cb.design_docs['blog']
50
40
  end
51
41
 
52
42
  def test_design_doc_missing_access
53
- refute @cb.design_docs['missing']
43
+ refute cb.design_docs['missing']
54
44
  end
55
45
 
56
46
  def design_doc
@@ -69,4 +59,4 @@ class TestDesignDocs < MiniTest::Test
69
59
  }
70
60
  end
71
61
 
72
- end
62
+ end
data/test/test_errors.rb CHANGED
@@ -20,63 +20,54 @@ require 'digest/md5'
20
20
 
21
21
  class TestErrors < MiniTest::Test
22
22
 
23
- def setup
24
- @mock = start_mock
25
- end
26
-
27
- def teardown
28
- stop_mock(@mock)
29
- end
30
-
31
23
  def genkey(item)
32
24
  tuple = [item["author"], item["message"]]
33
25
  Digest::MD5.hexdigest(tuple.join('-'))
34
26
  end
35
27
 
36
28
  def test_graceful_add_with_collision
37
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
38
29
  msg1 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:09"}
39
30
  key1 = uniq_id(genkey(msg1))
40
31
  msg2 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:29:30"}
41
32
  key2 = uniq_id(genkey(msg2))
42
33
 
43
- connection.add(key1, msg1)
34
+ cb.add(key1, msg1)
44
35
  begin
45
- connection.add(key2, msg2)
36
+ cb.add(key2, msg2)
46
37
  rescue Couchbase::Error::KeyExists => ex
47
38
  # using info from exception
48
39
  # it could be done with cas operation, but we can save one request
49
40
  # here (in real world cas operation will be more consistent because it
50
41
  # fetch fresh version from the cluster)
51
42
  #
52
- # connection.cas(key2) do |msg|
43
+ # cb.cas(key2) do |msg|
53
44
  # msg.merge("time" => [msg["time"], msg2["time"]])
54
45
  # end
55
46
  msg2 = msg1.merge("time" => [msg1["time"], msg2["time"]])
56
- connection.set(key2, msg2, :cas => ex.cas)
47
+ cb.set(key2, msg2, :cas => ex.cas)
57
48
  end
58
49
 
59
50
  msg3 = {"author" => "foo", "message" => "hi all",
60
51
  "time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30"]}
61
52
  key3 = uniq_id(genkey(msg3))
62
- assert_equal msg3, connection.get(key3)
53
+ assert_equal msg3, cb.get(key3)
63
54
 
64
- connection.run do |conn|
55
+ cb.run do |conn|
65
56
  msg4 = {"author" => "foo", "message" => "hi all", "time" => "2012-01-12 11:45:34"}
66
57
  key4 = uniq_id(genkey(msg4))
67
58
 
68
- connection.add(key4, msg4) do |ret|
59
+ cb.add(key4, msg4) do |ret|
69
60
  assert_equal :add, ret.operation
70
61
  assert_equal key4, ret.key
71
62
  msg4 = msg3.merge("time" => msg3["time"] + [msg4["time"]])
72
- connection.set(ret.key, msg4, :cas => ret.cas)
63
+ cb.set(ret.key, msg4, :cas => ret.cas)
73
64
  end
74
65
  end
75
66
 
76
67
  msg5 = {"author" => "foo", "message" => "hi all",
77
68
  "time" => ["2012-01-12 11:29:09", "2012-01-12 11:29:30", "2012-01-12 11:45:34"]}
78
69
  key5 = uniq_id(genkey(msg5))
79
- assert_equal msg5, connection.get(key5)
70
+ assert_equal msg5, cb.get(key5)
80
71
  end
81
72
 
82
73
  end
data/test/test_format.rb CHANGED
@@ -25,20 +25,11 @@ class TestFormat < MiniTest::Test
25
25
  undef to_json rescue nil
26
26
  end
27
27
 
28
- def setup
29
- @mock = start_mock
30
- end
31
-
32
- def teardown
33
- stop_mock(@mock)
34
- end
35
-
36
28
  def test_default_document_format
37
29
  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)
30
+ assert_equal :document, cb.default_format
31
+ cb.set(uniq_id, orig_doc)
32
+ doc, flags, cas = cb.get(uniq_id, :extended => true)
42
33
  # assert_equal 0x00, flags & 0x11
43
34
  assert doc.is_a?(Hash)
44
35
  assert_equal 'Twoflower', doc['name']
@@ -51,9 +42,8 @@ class TestFormat < MiniTest::Test
51
42
  refute orig_doc.respond_to?(:to_s)
52
43
  refute orig_doc.respond_to?(:to_json)
53
44
 
54
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :document)
55
45
  assert_raises(Couchbase::Error::ValueFormat) do
56
- connection.set(uniq_id, orig_doc)
46
+ cb.set(uniq_id, orig_doc)
57
47
  end
58
48
 
59
49
  class << orig_doc
@@ -61,7 +51,7 @@ class TestFormat < MiniTest::Test
61
51
  MultiJson.dump(:name => name, :role => role)
62
52
  end
63
53
  end
64
- connection.set(uniq_id, orig_doc) # OK
54
+ cb.set(uniq_id, orig_doc) # OK
65
55
 
66
56
  class << orig_doc
67
57
  undef to_json
@@ -69,15 +59,14 @@ class TestFormat < MiniTest::Test
69
59
  MultiJson.dump(:name => name, :role => role)
70
60
  end
71
61
  end
72
- connection.set(uniq_id, orig_doc) # OK
62
+ cb.set(uniq_id, orig_doc) # OK
73
63
  end
74
64
  end
75
65
 
76
66
  def test_it_could_dump_arbitrary_class_using_marshal_format
77
67
  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)
68
+ cb.set(uniq_id, orig_doc, :format => :marshal)
69
+ doc, flags, cas = cb.get(uniq_id, :extended => true)
81
70
  # assert_equal Couchbase::Bucket::FMT_MARSHAL, flags & Couchbase::Bucket::FMT_MASK
82
71
  assert doc.is_a?(ArbitraryClass)
83
72
  assert_equal 'Twoflower', doc.name
@@ -85,32 +74,34 @@ class TestFormat < MiniTest::Test
85
74
  end
86
75
 
87
76
  def test_it_accepts_only_string_in_plain_mode
77
+ skip
88
78
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
89
- connection.set(uniq_id, "1")
79
+ cb.set(uniq_id, "1")
90
80
 
91
81
  assert_raises(Couchbase::Error::ValueFormat) do
92
- connection.set(uniq_id, 1)
82
+ cb.set(uniq_id, 1)
93
83
  end
94
84
 
95
85
  assert_raises(Couchbase::Error::ValueFormat) do
96
- connection.set(uniq_id, {:foo => "bar"})
86
+ cb.set(uniq_id, {:foo => "bar"})
97
87
  end
98
88
  end
99
89
 
100
90
  def test_bignum_conversion
91
+ skip
101
92
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :default_format => :plain)
102
93
  cas = 0xffff_ffff_ffff_ffff
103
94
  assert cas.is_a?(Bignum)
104
95
  assert_raises(Couchbase::Error::NotFound) do
105
- connection.delete(uniq_id => cas)
96
+ cb.delete(uniq_id => cas)
106
97
  end
107
98
  end
108
99
 
109
100
  def test_it_allows_to_turn_off_transcoder
110
101
  skip
111
102
  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)
103
+ cb.set(uniq_id, "value", :flags => 0xffff_ffff)
104
+ doc, flags, _ = cb.get(uniq_id, :extended => true)
114
105
  assert_equal "value", doc
115
106
  assert_equal 0xffff_ffff, flags
116
107
  end
@@ -147,14 +138,13 @@ class TestFormat < MiniTest::Test
147
138
 
148
139
  def test_it_can_use_custom_transcoder
149
140
  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)
141
+ cb.transcoder = ZlibTranscoder.new(Couchbase::Transcoder::Document)
142
+ cb.set(uniq_id, {"foo" => "bar"})
143
+ doc, flags, _ = cb.get(uniq_id, :extended => true)
154
144
  assert_equal({"foo" => "bar"}, doc)
155
145
  assert_equal(ZlibTranscoder::FMT_ZLIB|Couchbase::Bucket::FMT_DOCUMENT, flags)
156
- connection.transcoder = nil
157
- doc = connection.get(uniq_id)
146
+ cb.transcoder = nil
147
+ doc = cb.get(uniq_id)
158
148
  assert_equal "x\x01\xABVJ\xCB\xCFW\xB2RJJ,R\xAA\x05\0\x1Dz\x044", doc
159
149
  end
160
150