couchbase 0.9.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +8 -0
  2. data/.yardopts +5 -0
  3. data/HISTORY.markdown +14 -10
  4. data/README.markdown +293 -98
  5. data/Rakefile +19 -24
  6. data/couchbase.gemspec +25 -7
  7. data/ext/couchbase_ext/couchbase_ext.c +2332 -0
  8. data/ext/couchbase_ext/extconf.rb +102 -0
  9. data/lib/couchbase.rb +20 -30
  10. data/lib/couchbase/bucket.rb +43 -112
  11. data/lib/couchbase/version.rb +3 -2
  12. data/tasks/benchmark.rake +6 -0
  13. data/tasks/compile.rake +52 -0
  14. data/tasks/doc.rake +27 -0
  15. data/tasks/test.rake +94 -0
  16. data/tasks/util.rake +21 -0
  17. data/test/profile/.gitignore +1 -0
  18. data/test/profile/Gemfile +6 -0
  19. data/test/profile/benchmark.rb +195 -0
  20. data/test/setup.rb +107 -18
  21. data/test/test_arithmetic.rb +98 -0
  22. data/test/test_async.rb +211 -0
  23. data/test/test_bucket.rb +126 -23
  24. data/test/test_cas.rb +59 -0
  25. data/test/test_couchbase.rb +22 -3
  26. data/test/test_delete.rb +63 -0
  27. data/test/test_errors.rb +82 -0
  28. data/test/test_flush.rb +49 -0
  29. data/test/test_format.rb +98 -0
  30. data/test/test_get.rb +236 -0
  31. data/test/test_stats.rb +53 -0
  32. data/test/test_store.rb +186 -0
  33. data/test/test_touch.rb +57 -0
  34. data/test/test_version.rb +17 -0
  35. metadata +72 -58
  36. data/lib/couchbase/couchdb.rb +0 -107
  37. data/lib/couchbase/document.rb +0 -71
  38. data/lib/couchbase/http_status.rb +0 -118
  39. data/lib/couchbase/latch.rb +0 -71
  40. data/lib/couchbase/memcached.rb +0 -372
  41. data/lib/couchbase/node.rb +0 -49
  42. data/lib/couchbase/rest_client.rb +0 -124
  43. data/lib/couchbase/view.rb +0 -182
  44. data/test/support/buckets-config.json +0 -843
  45. data/test/support/sample_design_doc.json +0 -9
  46. data/test/test_couchdb.rb +0 -98
  47. data/test/test_document.rb +0 -11
  48. data/test/test_latch.rb +0 -88
  49. data/test/test_memcached.rb +0 -59
  50. data/test/test_rest_client.rb +0 -14
  51. data/test/test_view.rb +0 -98
@@ -0,0 +1,53 @@
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::Unit::TestCase
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(:port => @mock.port)
32
+ stats = connection.stats
33
+ assert stats.is_a?(Hash)
34
+ assert_equal 4, stats.size
35
+ node, info = stats.first
36
+ assert node.is_a?(String)
37
+ assert info.is_a?(Hash)
38
+ assert info["pid"]
39
+ end
40
+
41
+ def test_stats_with_argument
42
+ connection = Couchbase.new(:port => @mock.port)
43
+ stats = connection.stats("pid")
44
+ assert stats.is_a?(Hash)
45
+ assert_equal 4, stats.size
46
+ node, info = stats.first
47
+ assert node.is_a?(String)
48
+ assert info.is_a?(Hash)
49
+ assert_equal 1, info.size
50
+ assert info["pid"]
51
+ end
52
+
53
+ end
@@ -0,0 +1,186 @@
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::Unit::TestCase
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(:port => @mock.port)
32
+ cas = connection.set(test_id, "bar")
33
+ assert(cas > 0)
34
+ end
35
+
36
+ def test_set_with_cas
37
+ connection = Couchbase.new(:port => @mock.port)
38
+
39
+ cas1 = connection.set(test_id, "bar1")
40
+ assert cas1 > 0
41
+
42
+ assert_raises(Couchbase::Error::KeyExists) do
43
+ connection.set(test_id, "bar2", :cas => cas1+1)
44
+ end
45
+
46
+ cas2 = connection.set(test_id, "bar2", :cas => cas1)
47
+ assert cas2 > 0
48
+ refute_equal cas2, cas1
49
+
50
+ cas3 = connection.set(test_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(:port => @mock.port)
58
+
59
+ cas1 = connection.add(test_id, "bar")
60
+ assert cas1 > 0
61
+
62
+ assert_raises(Couchbase::Error::KeyExists) do
63
+ connection.add(test_id, "bar")
64
+ end
65
+
66
+ assert_raises(Couchbase::Error::KeyExists) do
67
+ connection.add(test_id, "bar", :cas => cas1)
68
+ end
69
+ end
70
+
71
+ def test_replace
72
+ connection = Couchbase.new(:port => @mock.port)
73
+
74
+ assert_raises(Couchbase::Error::NotFound) do
75
+ connection.replace(test_id, "bar")
76
+ end
77
+
78
+ cas1 = connection.set(test_id, "bar")
79
+ assert cas1 > 0
80
+
81
+ connection.replace(test_id, "bar")
82
+ end
83
+
84
+ def test_acceptable_keys
85
+ connection = Couchbase.new(:port => @mock.port)
86
+
87
+ cas = connection.set(test_id.to_sym, "bar")
88
+ assert cas > 0
89
+
90
+ cas = connection.set(test_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(:port => @mock.port)
112
+ ret = nil
113
+ connection.run do |conn|
114
+ conn.set(test_id("1"), "foo1") {|res| ret = res}
115
+ conn.set(test_id("2"), "foo2") # ignore result
116
+ assert_equal 2, conn.seqno
117
+ end
118
+ assert ret.is_a?(Couchbase::Result)
119
+ assert ret.success?
120
+ assert_equal test_id("1"), ret.key
121
+ assert_equal :set, ret.operation
122
+ assert ret.cas.is_a?(Numeric)
123
+ end
124
+
125
+ def test_it_raises_error_when_appending_or_prepending_to_missing_key
126
+ connection = Couchbase.new(:port => @mock.port)
127
+
128
+ assert_raises(Couchbase::Error::NotStored) do
129
+ connection.append(test_id(:missing), "foo")
130
+ end
131
+
132
+ assert_raises(Couchbase::Error::NotStored) do
133
+ connection.prepend(test_id(:missing), "foo")
134
+ end
135
+ end
136
+
137
+ def test_append
138
+ connection = Couchbase.new(:port => @mock.port, :default_format => :plain)
139
+
140
+ cas1 = connection.set(test_id, "foo")
141
+ assert cas1 > 0
142
+ cas2 = connection.append(test_id, "bar")
143
+ assert cas2 > 0
144
+ refute_equal cas2, cas1
145
+
146
+ val = connection.get(test_id)
147
+ assert_equal "foobar", val
148
+ end
149
+
150
+ def test_prepend
151
+ connection = Couchbase.new(:port => @mock.port, :default_format => :plain)
152
+
153
+ cas1 = connection.set(test_id, "foo")
154
+ assert cas1 > 0
155
+ cas2 = connection.prepend(test_id, "bar")
156
+ assert cas2 > 0
157
+ refute_equal cas2, cas1
158
+
159
+ val = connection.get(test_id)
160
+ assert_equal "barfoo", val
161
+ end
162
+
163
+ ArbitraryData = Struct.new(:baz)
164
+
165
+ def test_set_using_brackets
166
+ connection = Couchbase.new(:port => @mock.port)
167
+
168
+ connection[test_id(1)] = "foo"
169
+ val = connection.get(test_id(1))
170
+ assert_equal "foo", val
171
+
172
+ if RUBY_VERSION =~ /^1\.9/
173
+ eval <<-EOC
174
+ connection[test_id(2), :flags => 0x1100] = "bar"
175
+ val, flags = connection.get(test_id(2), :extended => true)
176
+ assert_equal "bar", val
177
+ assert_equal 0x1100, flags
178
+
179
+ connection[test_id(3), :format => :marshal] = ArbitraryData.new("thing")
180
+ val = connection.get(test_id(3))
181
+ assert val.is_a?(ArbitraryData)
182
+ assert_equal "thing", val.baz
183
+ EOC
184
+ end
185
+ end
186
+ end
@@ -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 TestTouch < MiniTest::Unit::TestCase
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(:port => @mock.port)
32
+ connection.set(test_id, "bar", :ttl => 1)
33
+ connection.touch(test_id, :ttl => 2)
34
+ sleep(1)
35
+ assert connection.get(test_id)
36
+ sleep(1)
37
+ refute connection.get(test_id)
38
+ end
39
+
40
+ def test_it_uses_default_ttl_for_touch
41
+ connection = Couchbase.new(:port => @mock.port, :default_ttl => 1)
42
+ connection.set(test_id, "bar", :ttl => 10)
43
+ connection.touch(test_id, :ttl => 1)
44
+ sleep(2)
45
+ refute connection.get(test_id)
46
+ end
47
+
48
+ def test_it_accepts_ttl_for_get_command
49
+ connection = Couchbase.new(:port => @mock.port)
50
+ connection.set(test_id, "bar", :ttl => 10)
51
+ val = connection.get(test_id, :ttl => 1)
52
+ assert_equal "bar", val
53
+ sleep(2)
54
+ refute connection.get(test_id)
55
+ end
56
+
57
+ end
@@ -1,3 +1,20 @@
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
+
1
18
  require File.join(File.dirname(__FILE__), 'setup')
2
19
 
3
20
  class TestVersion < MiniTest::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,55 +9,55 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000Z
12
+ date: 2012-01-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: memcached
16
- requirement: &13656460 !ruby/object:Gem::Requirement
15
+ name: yajl-ruby
16
+ requirement: &19677780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '1.3'
21
+ version: 1.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13656460
24
+ version_requirements: *19677780
25
25
  - !ruby/object:Gem::Dependency
26
- name: yajl-ruby
27
- requirement: &13706380 !ruby/object:Gem::Requirement
26
+ name: rake
27
+ requirement: &19677000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.2
33
- type: :runtime
32
+ version: 0.8.7
33
+ type: :development
34
34
  prerelease: false
35
- version_requirements: *13706380
35
+ version_requirements: *19677000
36
36
  - !ruby/object:Gem::Dependency
37
- name: curb
38
- requirement: &13705920 !ruby/object:Gem::Requirement
37
+ name: minitest
38
+ requirement: &19676300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.7.15
44
- type: :runtime
43
+ version: '0'
44
+ type: :development
45
45
  prerelease: false
46
- version_requirements: *13705920
46
+ version_requirements: *19676300
47
47
  - !ruby/object:Gem::Dependency
48
- name: yaji
49
- requirement: &13705460 !ruby/object:Gem::Requirement
48
+ name: rake-compiler
49
+ requirement: &19672900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ~>
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.9
55
- type: :runtime
54
+ version: 0.7.5
55
+ type: :development
56
56
  prerelease: false
57
- version_requirements: *13705460
57
+ version_requirements: *19672900
58
58
  - !ruby/object:Gem::Dependency
59
- name: rake
60
- requirement: &13705080 !ruby/object:Gem::Requirement
59
+ name: rdiscount
60
+ requirement: &19672400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *13705080
68
+ version_requirements: *19672400
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest
71
- requirement: &13704620 !ruby/object:Gem::Requirement
70
+ name: yard
71
+ requirement: &19671780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *13704620
79
+ version_requirements: *19671780
80
80
  - !ruby/object:Gem::Dependency
81
- name: mocha
82
- requirement: &13704200 !ruby/object:Gem::Requirement
81
+ name: ruby-debug19
82
+ requirement: &19671120 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,43 +87,50 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *13704200
90
+ version_requirements: *19671120
91
91
  description: The official client library for use with Couchbase Server.
92
- email: info@couchbase.com
92
+ email: support@couchbase.com
93
93
  executables: []
94
- extensions: []
94
+ extensions:
95
+ - ext/couchbase_ext/extconf.rb
95
96
  extra_rdoc_files: []
96
97
  files:
97
98
  - .gitignore
99
+ - .yardopts
98
100
  - Gemfile
99
101
  - HISTORY.markdown
100
102
  - LICENSE
101
103
  - README.markdown
102
104
  - Rakefile
103
105
  - couchbase.gemspec
106
+ - ext/couchbase_ext/couchbase_ext.c
107
+ - ext/couchbase_ext/extconf.rb
104
108
  - lib/couchbase.rb
105
109
  - lib/couchbase/bucket.rb
106
- - lib/couchbase/couchdb.rb
107
- - lib/couchbase/document.rb
108
- - lib/couchbase/http_status.rb
109
- - lib/couchbase/latch.rb
110
- - lib/couchbase/memcached.rb
111
- - lib/couchbase/node.rb
112
- - lib/couchbase/rest_client.rb
113
110
  - lib/couchbase/version.rb
114
- - lib/couchbase/view.rb
111
+ - tasks/benchmark.rake
112
+ - tasks/compile.rake
113
+ - tasks/doc.rake
114
+ - tasks/test.rake
115
+ - tasks/util.rake
116
+ - test/profile/.gitignore
117
+ - test/profile/Gemfile
118
+ - test/profile/benchmark.rb
115
119
  - test/setup.rb
116
- - test/support/buckets-config.json
117
- - test/support/sample_design_doc.json
120
+ - test/test_arithmetic.rb
121
+ - test/test_async.rb
118
122
  - test/test_bucket.rb
123
+ - test/test_cas.rb
119
124
  - test/test_couchbase.rb
120
- - test/test_couchdb.rb
121
- - test/test_document.rb
122
- - test/test_latch.rb
123
- - test/test_memcached.rb
124
- - test/test_rest_client.rb
125
+ - test/test_delete.rb
126
+ - test/test_errors.rb
127
+ - test/test_flush.rb
128
+ - test/test_format.rb
129
+ - test/test_get.rb
130
+ - test/test_stats.rb
131
+ - test/test_store.rb
132
+ - test/test_touch.rb
125
133
  - test/test_version.rb
126
- - test/test_view.rb
127
134
  homepage: http://couchbase.org
128
135
  licenses:
129
136
  - ASL-2
@@ -150,15 +157,22 @@ signing_key:
150
157
  specification_version: 3
151
158
  summary: Couchbase ruby driver
152
159
  test_files:
160
+ - test/profile/.gitignore
161
+ - test/profile/Gemfile
162
+ - test/profile/benchmark.rb
153
163
  - test/setup.rb
154
- - test/support/buckets-config.json
155
- - test/support/sample_design_doc.json
164
+ - test/test_arithmetic.rb
165
+ - test/test_async.rb
156
166
  - test/test_bucket.rb
167
+ - test/test_cas.rb
157
168
  - test/test_couchbase.rb
158
- - test/test_couchdb.rb
159
- - test/test_document.rb
160
- - test/test_latch.rb
161
- - test/test_memcached.rb
162
- - test/test_rest_client.rb
169
+ - test/test_delete.rb
170
+ - test/test_errors.rb
171
+ - test/test_flush.rb
172
+ - test/test_format.rb
173
+ - test/test_get.rb
174
+ - test/test_stats.rb
175
+ - test/test_store.rb
176
+ - test/test_touch.rb
163
177
  - test/test_version.rb
164
- - test/test_view.rb
178
+ has_rdoc: