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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +103 -0
  3. data/.ruby-version +1 -1
  4. data/Rakefile +13 -2
  5. data/couchbase-jruby-client.gemspec +7 -6
  6. data/lib/couchbase/bucket.rb +11 -338
  7. data/lib/couchbase/cluster.rb +10 -88
  8. data/lib/couchbase/configuration.rb +39 -0
  9. data/lib/couchbase/design_doc.rb +18 -73
  10. data/lib/couchbase/document.rb +34 -0
  11. data/lib/couchbase/error.rb +0 -35
  12. data/lib/couchbase/operations.rb +60 -40
  13. data/lib/couchbase/version.rb +1 -1
  14. data/lib/couchbase/view.rb +55 -345
  15. data/lib/couchbase.rb +37 -141
  16. data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
  17. data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
  18. data/lib/jars/rxjava-1.0.8.jar +0 -0
  19. data/lib/jars/rxjruby-0.0.1.jar +0 -0
  20. data/test/{test_cas.rb → helper.rb} +15 -10
  21. data/test/test_bucket.rb +14 -228
  22. data/test/test_cluster.rb +1 -29
  23. data/test/test_configuration.rb +51 -0
  24. data/test/test_couchbase.rb +28 -28
  25. data/test/test_design_doc.rb +29 -0
  26. data/test/test_document.rb +51 -0
  27. data/test/test_operations.rb +49 -0
  28. data/test/test_view.rb +62 -116
  29. metadata +43 -125
  30. data/lib/couchbase/async/callback.rb +0 -38
  31. data/lib/couchbase/async/queue.rb +0 -26
  32. data/lib/couchbase/async.rb +0 -32
  33. data/lib/couchbase/constants.rb +0 -29
  34. data/lib/couchbase/operations/arithmetic.rb +0 -290
  35. data/lib/couchbase/operations/delete.rb +0 -115
  36. data/lib/couchbase/operations/design_docs.rb +0 -99
  37. data/lib/couchbase/operations/fetch.rb +0 -33
  38. data/lib/couchbase/operations/get.rb +0 -303
  39. data/lib/couchbase/operations/stats.rb +0 -42
  40. data/lib/couchbase/operations/store.rb +0 -463
  41. data/lib/couchbase/operations/touch.rb +0 -140
  42. data/lib/couchbase/operations/unlock.rb +0 -209
  43. data/lib/couchbase/operations/utils.rb +0 -68
  44. data/lib/couchbase/query.rb +0 -76
  45. data/lib/couchbase/result.rb +0 -60
  46. data/lib/couchbase/transcoder.rb +0 -81
  47. data/lib/couchbase/utils.rb +0 -62
  48. data/lib/couchbase/view_row.rb +0 -227
  49. data/lib/jars/commons-codec-1.5.jar +0 -0
  50. data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
  51. data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
  52. data/lib/jars/couchbase-client-1.3.2.jar +0 -0
  53. data/lib/jars/httpcore-4.3.1.jar +0 -0
  54. data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
  55. data/lib/jars/jettison-1.1.jar +0 -0
  56. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  57. data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
  58. data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
  59. data/lib/jars/spymemcached-2.10.5.jar +0 -0
  60. data/tasks/benchmark.rake +0 -6
  61. data/tasks/test.rake +0 -36
  62. data/tasks/util.rake +0 -21
  63. data/test/mock.rb +0 -85
  64. data/test/profile/.gitignore +0 -1
  65. data/test/profile/.jrubyrc +0 -722
  66. data/test/profile/Gemfile +0 -7
  67. data/test/profile/benchmark.rb +0 -177
  68. data/test/profile/profile.rb +0 -59
  69. data/test/setup.rb +0 -74
  70. data/test/test_arithmetic.rb +0 -155
  71. data/test/test_async.rb +0 -24
  72. data/test/test_couchbase_rails_cache_store.rb +0 -341
  73. data/test/test_delete.rb +0 -139
  74. data/test/test_design_docs.rb +0 -67
  75. data/test/test_errors.rb +0 -74
  76. data/test/test_fetch.rb +0 -71
  77. data/test/test_format.rb +0 -142
  78. data/test/test_get.rb +0 -363
  79. data/test/test_query.rb +0 -23
  80. data/test/test_result.rb +0 -15
  81. data/test/test_stats.rb +0 -44
  82. data/test/test_store.rb +0 -203
  83. data/test/test_touch.rb +0 -90
  84. data/test/test_unlock.rb +0 -89
  85. data/test/test_utils.rb +0 -67
  86. data/test/test_version.rb +0 -28
  87. data/test/test_view_row.rb +0 -74
@@ -1,227 +0,0 @@
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
- module Couchbase
19
-
20
- java_import com.couchbase.client.protocol.views.ViewRowNoDocs
21
- java_import com.couchbase.client.protocol.views.ViewRowWithDocs
22
- java_import com.couchbase.client.protocol.views.ViewRowReduced
23
- java_import com.couchbase.client.protocol.views.SpatialViewRowNoDocs
24
- java_import com.couchbase.client.protocol.views.SpatialViewRowWithDocs
25
-
26
- class Java::ComCouchbaseClientProtocolViews::ViewRowNoDocs
27
- def doc
28
- {
29
- id: getId,
30
- key: getKey,
31
- value: getValue
32
- }
33
- end
34
- end
35
-
36
- class Java::ComCouchbaseClientProtocolViews::ViewRowWithDocs
37
- def doc
38
- {
39
- 'meta' => {
40
- 'id' => self['id']
41
- },
42
- 'value' => document
43
- }
44
- end
45
- end
46
-
47
- module Java::ComCouchbaseClientProtocolViews::ViewRow
48
- def [](key)
49
- if respond_to?(key)
50
- send(key)
51
- else
52
- fail NoMethodError, "ViewRow##{key} isn't defined."
53
- end
54
- end
55
- end
56
-
57
-
58
- # This class encapsulates structured JSON document
59
- #
60
- # @since 1.2.0
61
- #
62
- # It behaves like Hash for document included into row, and has access methods to row data as well.
63
- #
64
- # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-datastore.html
65
- class ViewRow
66
-
67
- include Constants
68
-
69
- # Undefine as much methods as we can to free names for views
70
- instance_methods.each do |m|
71
- undef_method(m) if m.to_s !~ /(?:^__|^nil\?$|^send$|^object_id$|^class$|)/
72
- end
73
-
74
- # The hash built from JSON document.
75
- #
76
- # @since 1.2.0
77
- #
78
- # This is complete response from the Couchbase
79
- #
80
- # @return [Hash]
81
- attr_accessor :data
82
-
83
- # The key which was emitted by map function
84
- #
85
- # @since 1.2.0
86
- #
87
- # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
88
- #
89
- # Usually it is String (the object +_id+) but it could be also any
90
- # compount JSON value.
91
- #
92
- # @return [Object]
93
- attr_accessor :key
94
-
95
- # The value which was emitted by map function
96
- #
97
- # @since 1.2.0
98
- #
99
- # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
100
- #
101
- # @return [Object]
102
- attr_accessor :value
103
-
104
- # The document hash.
105
- #
106
- # @since 1.2.0
107
- #
108
- # It usually available when view executed with +:include_doc+ argument.
109
- #
110
- # @return [Hash]
111
- attr_accessor :doc
112
-
113
- # The identificator of the document
114
- #
115
- # @since 1.2.0
116
- #
117
- # @return [String]
118
- attr_accessor :id
119
-
120
- # The meta data linked to the document
121
- #
122
- # @since 1.2.0
123
- #
124
- # @return [Hash]
125
- attr_accessor :meta
126
-
127
- # Initialize the document instance
128
- #
129
- # @since 1.2.0
130
- #
131
- # It takes reference to the bucket, data hash.
132
- #
133
- # @param [Couchbase::Bucket] bucket the reference to connection
134
- # @param [Hash] data the data hash, which was built from JSON document
135
- # representation
136
- def initialize(bucket, data)
137
- @bucket = bucket
138
- @data = data
139
- @key = data.key
140
- @last = false
141
- @id = data.id unless data.is_a?(ViewRowReduced)
142
-
143
- case data
144
- when ViewRowWithDocs, SpatialViewRowWithDocs
145
- @doc = data.document
146
- when ViewRowReduced
147
- @value = MultiJson.load(data.value)
148
- when SpatialViewRowNoDocs, SpatialViewRowWithDocs
149
- @geometry = data.geometry
150
- @bbox = data.bbox
151
- end
152
- end
153
-
154
- # Wraps data hash into ViewRow instance
155
- #
156
- # @since 1.2.0
157
- #
158
- # @see ViewRow#initialize
159
- #
160
- # @param [Couchbase::Bucket] bucket the reference to connection
161
- # @param [Hash] data the data hash, which was built from JSON document
162
- # representation
163
- #
164
- # @return [ViewRow]
165
- def self.wrap(bucket, data)
166
- self.new(bucket, data)
167
- end
168
-
169
- # Get attribute of the document
170
- #
171
- # @since 1.2.0
172
- #
173
- # Fetches attribute from underlying document hash
174
- #
175
- # @param [String] key the attribute name
176
- #
177
- # @return [Object] property value or nil
178
- def [](key)
179
- @doc[key]
180
- end
181
-
182
- # Check attribute existence
183
- #
184
- # @since 1.2.0
185
- #
186
- # @param [String] key the attribute name
187
- #
188
- # @return [true, false] +true+ if the given attribute is present in in
189
- # the document.
190
- def has_key?(key)
191
- @doc.has_key?(key)
192
- end
193
-
194
- # Set document attribute
195
- #
196
- # @since 1.2.0
197
- #
198
- # Set or update the attribute in the document hash
199
- #
200
- # @param [String] key the attribute name
201
- # @param [Object] value the attribute value
202
- #
203
- # @return [Object] the value
204
- def []=(key, value)
205
- @doc[key] = value
206
- end
207
-
208
- # Signals if this row is last in a stream
209
- #
210
- # @since 1.2.1
211
- #
212
- # @return [true, false] +true+ if this row is last in a stream
213
- def last?
214
- @last
215
- end
216
-
217
- def inspect
218
- desc = "#<#{self.class.name}:#{self.object_id}"
219
- [:@id, :@key, :@value, :@doc, :@meta].each do |iv|
220
- desc << " #{iv}=#{instance_variable_get(iv).inspect}"
221
- end
222
- desc << ">"
223
- desc
224
- end
225
- end
226
-
227
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/tasks/benchmark.rake DELETED
@@ -1,6 +0,0 @@
1
- desc 'Run benchmarks and compare them to memcached and dalli gems'
2
- task :benchmark => [:clean, :compile] do
3
- cd File.expand_path(File.join(__FILE__, '..', '..', 'test', 'profile')) do
4
- sh "bundle install && bundle exec ruby benchmark.rb | tee benchmark-#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}.log"
5
- end
6
- end
data/tasks/test.rake DELETED
@@ -1,36 +0,0 @@
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
- rule 'test/CouchbaseMock.jar' do |task|
19
- jar_path = "0.6-SNAPSHOT/CouchbaseMock-0.6-20130903.160518-3.jar"
20
- sh %{wget -q -O test/CouchbaseMock.jar http://files.couchbase.com/maven2/org/couchbase/mock/CouchbaseMock/#{jar_path}}
21
- end
22
-
23
- task :test do
24
- $LOAD_PATH.unshift('lib', 'test')
25
-
26
- if ENV['TEST']
27
- require ENV['TEST']
28
- else
29
- Dir.glob('./test/**/test_*.rb') { |f| require f }
30
- end
31
-
32
- require 'test/setup.rb'
33
- end
34
-
35
- Rake::Task['test'].prerequisites.unshift('test/CouchbaseMock.jar')
36
-
data/tasks/util.rake DELETED
@@ -1,21 +0,0 @@
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
- desc 'Start an irb session and load the library.'
19
- task :console do
20
- exec "irb -I lib -rcouchbase"
21
- end
data/test/mock.rb DELETED
@@ -1,85 +0,0 @@
1
- class CouchbaseServer
2
- attr_accessor :host, :port, :num_nodes, :buckets_spec
3
-
4
- def real?
5
- true
6
- end
7
-
8
- def initialize(params = {})
9
- @host, @port = ENV['COUCHBASE_SERVER'].split(':')
10
- @port = @port.to_i
11
-
12
- if @host.nil? || @host.empty? || @port == 0
13
- raise ArgumentError, 'Check COUCHBASE_SERVER variable. It should be hostname:port'
14
- end
15
-
16
- @config = MultiJson.load(open("http://#{@host}:#{@port}/pools/default"))
17
- @num_nodes = @config['nodes'].size
18
- @buckets_spec = params[:buckets_spec] || 'default:' # "default:,protected:secret,cache::memcache"
19
- end
20
-
21
- def start
22
- # flush all buckets
23
- @buckets_spec.split(',') do |bucket|
24
- name, password, _ = bucket.split(':')
25
- connection = Couchbase.new(:hostname => @host,
26
- :port => @port,
27
- :username => name,
28
- :bucket => name,
29
- :password => password)
30
- connection.flush
31
- end
32
- end
33
- def stop; end
34
- end
35
-
36
- require "#{File.dirname(__FILE__)}/CouchbaseMock.jar"
37
-
38
- class CouchbaseMock
39
- attr_accessor :host, :port, :num_nodes, :buckets_spec, :num_vbuckets
40
-
41
- def real?
42
- false
43
- end
44
-
45
- def initialize(params = {})
46
- @host = 'localhost'
47
- @port = 8091
48
- @num_nodes = 1
49
- @num_vbuckets = 4096
50
- @buckets_spec = 'default:' # "default:,protected:secret,cache::memcache"
51
- params.each do |key, value|
52
- send("#{key}=", value)
53
- end
54
- yield self if block_given?
55
- if @num_vbuckets < 1 || (@num_vbuckets & (@num_vbuckets - 1) != 0)
56
- raise ArgumentError, 'Number of vbuckets should be a power of two and greater than zero'
57
- end
58
- @mock = Java::OrgCouchbaseMock::CouchbaseMock.new(@host, @port, @num_nodes, @num_vbuckets, @buckets_spec)
59
- end
60
-
61
- def start
62
- @mock.start
63
- @mock.waitForStartup
64
- end
65
-
66
- def stop
67
- @mock.stop
68
- end
69
- end
70
-
71
- def start_mock(params = {})
72
- mock = nil
73
- if ENV['COUCHBASE_SERVER']
74
- mock = CouchbaseServer.new(params)
75
- if (params[:port] && mock.port != params[:port]) ||
76
- (params[:host] && mock.host != params[:host]) ||
77
- mock.buckets_spec != 'default:'
78
- skip("Unable to configure real cluster. Requested config is: #{params.inspect}")
79
- end
80
- else
81
- mock = CouchbaseMock.new(params)
82
- end
83
- mock.start
84
- mock
85
- end
@@ -1 +0,0 @@
1
- benchmark*.log