libcouchbase-mapo 1.4.1

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.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +38 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +445 -0
  9. data/Rakefile +76 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +19 -0
  12. data/lib/libcouchbase.rb +40 -0
  13. data/lib/libcouchbase/bucket.rb +825 -0
  14. data/lib/libcouchbase/callbacks.rb +69 -0
  15. data/lib/libcouchbase/connection.rb +886 -0
  16. data/lib/libcouchbase/design_docs.rb +92 -0
  17. data/lib/libcouchbase/error.rb +68 -0
  18. data/lib/libcouchbase/ext/libcouchbase.rb +1175 -0
  19. data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
  20. data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
  21. data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
  22. data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
  23. data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
  24. data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
  25. data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
  26. data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
  27. data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
  28. data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
  29. data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
  30. data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
  31. data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +61 -0
  32. data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
  33. data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
  34. data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
  35. data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
  36. data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
  37. data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
  38. data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
  39. data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
  40. data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
  41. data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
  42. data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
  43. data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
  44. data/lib/libcouchbase/ext/libcouchbase/enums.rb +1007 -0
  45. data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
  46. data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
  47. data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
  48. data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
  49. data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
  50. data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
  51. data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
  52. data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
  53. data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
  54. data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
  55. data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
  56. data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
  57. data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
  58. data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
  59. data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
  60. data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
  61. data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
  62. data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
  63. data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
  64. data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
  65. data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
  66. data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
  67. data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
  68. data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
  69. data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
  70. data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
  71. data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +31 -0
  72. data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
  73. data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
  74. data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
  75. data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
  76. data/lib/libcouchbase/ext/libcouchbase_libuv.rb +22 -0
  77. data/lib/libcouchbase/ext/tasks.rb +39 -0
  78. data/lib/libcouchbase/n1ql.rb +78 -0
  79. data/lib/libcouchbase/query_full_text.rb +147 -0
  80. data/lib/libcouchbase/query_n1ql.rb +123 -0
  81. data/lib/libcouchbase/query_view.rb +135 -0
  82. data/lib/libcouchbase/results_fiber.rb +281 -0
  83. data/lib/libcouchbase/results_native.rb +220 -0
  84. data/lib/libcouchbase/subdoc_request.rb +139 -0
  85. data/lib/libcouchbase/version.rb +5 -0
  86. data/libcouchbase.gemspec +68 -0
  87. data/spec/bucket_spec.rb +290 -0
  88. data/spec/connection_spec.rb +257 -0
  89. data/spec/design_docs_spec.rb +31 -0
  90. data/spec/error_spec.rb +26 -0
  91. data/spec/fts_spec.rb +135 -0
  92. data/spec/n1ql_spec.rb +206 -0
  93. data/spec/results_libuv_spec.rb +244 -0
  94. data/spec/results_native_spec.rb +259 -0
  95. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
  96. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
  97. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
  98. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
  99. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
  100. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
  101. data/spec/subdoc_spec.rb +192 -0
  102. data/spec/view_spec.rb +201 -0
  103. data/windows_build.md +36 -0
  104. metadata +265 -0
@@ -0,0 +1,257 @@
1
+ # frozen_string_literal: true, encoding: ASCII-8BIT
2
+
3
+ require 'libcouchbase'
4
+
5
+
6
+ describe Libcouchbase::Connection do
7
+ before :each do
8
+ @log = []
9
+ expect(@log).to eq([])
10
+ @reactor = ::Libuv::Reactor.default
11
+ end
12
+
13
+ after :each do
14
+ @reactor = nil
15
+ @log = nil
16
+ end
17
+
18
+ it "should connect and disconnect from the default bucket" do
19
+ @reactor.run { |reactor|
20
+ connection = Libcouchbase::Connection.new
21
+ connection.connect.then {
22
+ @log << true
23
+ }.finally { connection.destroy }
24
+ }
25
+
26
+ expect(@log).to eq([true])
27
+ end
28
+
29
+ it "should store a key on the default bucket" do
30
+ @reactor.run { |reactor|
31
+ connection = Libcouchbase::Connection.new
32
+ connection.connect.then do
33
+ connection.store('sometestkey', {"json" => "data"}).then(proc {|resp|
34
+ @log << resp.callback
35
+ }, proc { |error|
36
+ @log << error
37
+ }).finally { connection.destroy }
38
+ end
39
+ }
40
+
41
+ expect(@log).to eq([:callback_store])
42
+ end
43
+
44
+ it "should durably store a key on the default bucket" do
45
+ @reactor.run { |reactor|
46
+ connection = Libcouchbase::Connection.new
47
+ connection.connect.then do
48
+ connection.store('sometestkey', {"json" => "data2"}, persist_to: -1, replicate_to: -1).then(proc {|resp|
49
+ @log << resp.callback
50
+ }, proc { |error|
51
+ @log << error
52
+ }).finally { connection.destroy }
53
+ end
54
+ }
55
+
56
+ expect(@log).to eq([:callback_storedur])
57
+ end
58
+
59
+ it "should fetch a key from the default bucket" do
60
+ @reactor.run { |reactor|
61
+ connection = Libcouchbase::Connection.new
62
+ connection.connect.then do
63
+ connection.get('sometestkey').then(proc {|resp|
64
+ @log << resp.value
65
+ }, proc { |error|
66
+ @log << error
67
+ }).finally { connection.destroy }
68
+ end
69
+ }
70
+
71
+ expect(@log).to eq([{json: "data2"}])
72
+ end
73
+
74
+ it "should unlock a key on the default bucket" do
75
+
76
+ @reactor.run { |reactor|
77
+ connection = Libcouchbase::Connection.new
78
+ connection.connect.then do
79
+ connection.get('sometestkey', lock: 2).then(proc {|resp|
80
+ @log << resp.callback
81
+ connection.unlock('sometestkey', cas: resp.cas).then(proc {|resp|
82
+ @log << resp.callback
83
+ }, proc { |error|
84
+ @log << error
85
+ })
86
+ }, proc { |error|
87
+ @log << error
88
+ }).finally { connection.destroy }
89
+ end
90
+ }
91
+
92
+ expect(@log).to eq([:callback_get, :callback_unlock])
93
+ end
94
+
95
+ it "should remove a key on the default bucket" do
96
+ @reactor.run { |reactor|
97
+ connection = Libcouchbase::Connection.new
98
+ connection.connect.then do
99
+ connection.remove('sometestkey').then(proc {|resp|
100
+ @log << :success
101
+ }, proc { |error|
102
+ @log << error
103
+ }).finally { connection.destroy }
104
+ end
105
+ }
106
+
107
+ expect(@log).to eq([:success])
108
+ end
109
+
110
+ it "should allow settings to be configured" do
111
+ @reactor.run { |reactor|
112
+ connection = Libcouchbase::Connection.new
113
+ connection.connect.then do
114
+ expect(connection.configure(:operation_timeout, 1500000).value).to be(connection)
115
+ expect { connection.configure(:bob, 1500000).value }.to raise_error(Libcouchbase::Error)
116
+ @log << :success
117
+ connection.destroy
118
+ end
119
+ }
120
+
121
+ expect(@log).to eq([:success])
122
+ end
123
+
124
+ it "should return the server list" do
125
+ @reactor.run { |reactor|
126
+ begin
127
+ connection = Libcouchbase::Connection.new
128
+ connection.connect.value
129
+ @log = connection.get_server_list.value
130
+ ensure
131
+ connection.destroy
132
+ end
133
+ }
134
+
135
+ expect(@log).to eq(['127.0.0.1:11210'])
136
+ end
137
+
138
+ it "should support counter operations" do
139
+ @reactor.run { |reactor|
140
+ connection = Libcouchbase::Connection.new
141
+ connection.connect.then do
142
+ connection.counter('testcount', initial: 10, expire_in: 2)
143
+ .then(proc { |resp|
144
+ @log << resp.value
145
+ connection.get('testcount').then do |resp|
146
+ @log << resp.value
147
+ end
148
+ }, proc { |error|
149
+ @log << error
150
+ }).finally { connection.destroy }
151
+ end
152
+ }
153
+
154
+ expect(@log).to eq([10, 10])
155
+ end
156
+
157
+ it "should support touch operations" do
158
+ @reactor.run { |reactor|
159
+ connection = Libcouchbase::Connection.new
160
+ connection.connect.then do
161
+ connection.store('testtouch', 34).then(proc {|resp|
162
+ @log << resp.value
163
+ connection.touch('testtouch', expire_in: 1).then(proc {
164
+ @log << 'set'
165
+ sleep 2
166
+ connection.get('testtouch').catch do |err|
167
+ @log << err.is_a?(Libcouchbase::Error::KeyNotFound)
168
+ end
169
+ })
170
+ }, proc { |error|
171
+ @log << error
172
+ }).finally { connection.destroy }
173
+ end
174
+ }
175
+
176
+ expect(@log).to eq([34, 'set', true])
177
+ end
178
+
179
+ it "should fail to flush unless the connection specifies it is enabled" do
180
+ @reactor.run { |reactor|
181
+ connection = Libcouchbase::Connection.new
182
+ connection.connect.then do
183
+ begin
184
+ connection.flush.then(proc {
185
+ @log << :error
186
+ }, proc {
187
+ @log << :error
188
+ }).finally { connection.destroy }
189
+ rescue => e
190
+ @log << :success
191
+ connection.destroy
192
+ end
193
+ end
194
+ }
195
+
196
+ expect(@log).to eq([:success])
197
+ end
198
+
199
+ it "should flush when enabled explicitly", flush: true do
200
+ @reactor.run { |reactor|
201
+ connection = Libcouchbase::Connection.new(bucket: :test, username: 'tester', password: 'password123')
202
+ connection.connect(flush_enabled: true).then do
203
+ begin
204
+ connection.flush.then(proc { |resp|
205
+ @log << resp.callback
206
+ }, proc { |error|
207
+ @log << error
208
+ }).finally { connection.destroy }
209
+ rescue => e
210
+ @log << e
211
+ connection.destroy
212
+ end
213
+ end
214
+ }
215
+
216
+ expect(@log).to eq([:callback_cbflush])
217
+ end
218
+
219
+ it "should perform a HTTP request" do
220
+ @reactor.run { |reactor|
221
+ connection = Libcouchbase::Connection.new
222
+ connection.connect.then do
223
+ connection.http("/pools/default/buckets/#{connection.bucket}/ddocs", type: :management).then(
224
+ proc { |resp|
225
+ @log << resp.headers.empty?
226
+ @log << resp.body.empty?
227
+ },
228
+ proc { |err|
229
+ @log << err
230
+ }
231
+ ).finally { connection.destroy }
232
+ end
233
+ }
234
+
235
+ expect(@log).to eq([false, false])
236
+ end
237
+
238
+ it "should fail a HTTP request" do
239
+ @reactor.run { |reactor|
240
+ connection = Libcouchbase::Connection.new
241
+ connection.connect.then do
242
+ connection.http("/pools/default/buckets/#{connection.bucket}/ddocs").then(
243
+ proc { |resp|
244
+ @log << resp.headers.empty?
245
+ @log << resp.body.empty?
246
+ },
247
+ proc { |err|
248
+ @log << err.message
249
+ @log << err.code
250
+ }
251
+ ).finally { connection.destroy }
252
+ end
253
+ }
254
+
255
+ expect(@log).to eq(['non success response for /pools/default/buckets/default/ddocs', 400])
256
+ end
257
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true, encoding: ASCII-8BIT
2
+
3
+ require 'libcouchbase'
4
+
5
+
6
+ describe Libcouchbase::DesignDocs, design_docs: true do
7
+ before :each do
8
+ @ddoc = Libcouchbase::Bucket.new.design_docs
9
+ end
10
+
11
+ it "should list the available designs" do
12
+ designs = @ddoc.designs
13
+ expect(designs.count).to eq(23)
14
+ end
15
+
16
+ it "should list the available views" do
17
+ views = @ddoc.design("user").views
18
+ expect(views).to eq([:is_sys_admin])
19
+
20
+ views = @ddoc[:user].views
21
+ expect(views).to eq([:is_sys_admin])
22
+ end
23
+
24
+ it "should provide access to view configuration" do
25
+ config = @ddoc.design("user").view_config
26
+ expect(config.keys).to eq([:is_sys_admin])
27
+
28
+ config = @ddoc[:user].view_config
29
+ expect(config.keys).to eq([:is_sys_admin])
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true, encoding: ASCII-8BIT
2
+
3
+ require 'libcouchbase'
4
+
5
+
6
+ describe Libcouchbase::Error do
7
+ it "define the error classes" do
8
+ expect(Libcouchbase::Error::MapChanged.new.is_a? StandardError).to be(true)
9
+ end
10
+
11
+ it "should be able to look up errors" do
12
+ expect(Libcouchbase::Error::Lookup[:empty_key]).to be(Libcouchbase::Error::EmptyKey)
13
+ expect(Libcouchbase::Error.lookup(:empty_key)).to be(Libcouchbase::Error::EmptyKey)
14
+ expect(Libcouchbase::Error.lookup(:whatwhat_key)).to be(Libcouchbase::Error::UnknownError)
15
+ expect(Libcouchbase::Error.lookup(2)).to be(Libcouchbase::Error::AuthError)
16
+ expect(Libcouchbase::Error.lookup(-2)).to be(Libcouchbase::Error::UnknownError)
17
+ end
18
+
19
+ it "should be able to catch generic errors" do
20
+ begin
21
+ raise ::Libcouchbase::Error::NoMemory, 'what what'
22
+ rescue ::Libcouchbase::Error => e
23
+ expect(e.message).to eq('what what')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true, encoding: ASCII-8BIT
2
+
3
+ require 'libcouchbase'
4
+
5
+
6
+ describe Libcouchbase::QueryFullText, full_text_search: true do
7
+ before :each do
8
+ # This will load the couchbase connection on a different thread
9
+ @bucket = Libcouchbase::Bucket.new
10
+ @reactor = ::Libuv::Reactor.default
11
+ @log = []
12
+ end
13
+
14
+ after :each do
15
+ @bucket = nil
16
+ @reactor = nil
17
+ @log = nil
18
+ end
19
+
20
+ describe 'perform native queries' do
21
+ it "should iterate a full text search with results" do
22
+ results = @bucket.full_text_search(:default, 'Toshiba')
23
+ @log << results.to_a.count
24
+ @log << results.count
25
+ @log << results.collect { |res| res.value.nil? }
26
+ expect(@log).to eq([4, 4, [false, false, false, false]])
27
+ end
28
+
29
+ it "should iterate a full text search without results" do
30
+ results = @bucket.full_text_search(:default, 'Toshiba', include_docs: false)
31
+ @log << results.to_a.count
32
+ @log << results.count
33
+ @log << results.collect { |res| res.value.nil? }
34
+ expect(@log).to eq([4, 4, [true, true, true, true]])
35
+ end
36
+
37
+ it "should cancel a full text search when an error occurs" do
38
+ results = @bucket.full_text_search(:default, 'Toshiba')
39
+ begin
40
+ count = 0
41
+ results.collect { |res|
42
+ raise 'err' if count > 0
43
+ @log << res.value.nil?
44
+ count += 1
45
+ }
46
+ rescue => e
47
+ @log << :error
48
+ end
49
+ expect(@log).to eq([false, :error])
50
+ end
51
+ end
52
+
53
+ describe 'perform queries in libuv reactor' do
54
+ it "should iterate a full text search with results" do
55
+ @reactor.run { |reactor|
56
+ results = @bucket.full_text_search(:default, 'Toshiba')
57
+ @log << results.to_a.count
58
+ @log << results.count
59
+ @log << results.collect { |res| res.value.nil? }
60
+ }
61
+ expect(@log).to eq([4, 4, [false, false, false, false]])
62
+ end
63
+
64
+ it "should iterate a full text search without results" do
65
+ @reactor.run { |reactor|
66
+ results = @bucket.full_text_search(:default, 'Toshiba', include_docs: false)
67
+ @log << results.to_a.count
68
+ @log << results.count
69
+ @log << results.collect { |res| res.value.nil? }
70
+ }
71
+ expect(@log).to eq([4, 4, [true, true, true, true]])
72
+ end
73
+
74
+ it "should cancel a full text search when an error occurs" do
75
+ @reactor.run { |reactor|
76
+ results = @bucket.full_text_search(:default, 'Toshiba')
77
+ begin
78
+ count = 0
79
+ results.collect { |res|
80
+ raise 'err' if count > 0
81
+ @log << res.value.nil?
82
+ count += 1
83
+ }
84
+ rescue => e
85
+ @log << :error
86
+ end
87
+ }
88
+ expect(@log).to eq([false, :error])
89
+ end
90
+ end
91
+
92
+ describe 'perform queries in event machine' do
93
+ require 'em-synchrony'
94
+
95
+ it "should iterate a full text search with results" do
96
+ EM.synchrony {
97
+ results = @bucket.full_text_search(:default, 'Toshiba')
98
+ @log << results.to_a.count
99
+ @log << results.count
100
+ @log << results.collect { |res| res.value.nil? }
101
+ EM.stop
102
+ }
103
+ expect(@log).to eq([4, 4, [false, false, false, false]])
104
+ end
105
+
106
+ it "should iterate a full text search without results" do
107
+ EM.synchrony {
108
+ results = @bucket.full_text_search(:default, 'Toshiba', include_docs: false)
109
+ @log << results.to_a.count
110
+ @log << results.count
111
+ @log << results.collect { |res| res.value.nil? }
112
+ EM.stop
113
+ }
114
+ expect(@log).to eq([4, 4, [true, true, true, true]])
115
+ end
116
+
117
+ it "should cancel a full text search when an error occurs" do
118
+ EM.synchrony {
119
+ results = @bucket.full_text_search(:default, 'Toshiba')
120
+ begin
121
+ count = 0
122
+ results.collect { |res|
123
+ raise 'err' if count > 0
124
+ @log << res.value.nil?
125
+ count += 1
126
+ }
127
+ rescue => e
128
+ @log << :error
129
+ end
130
+ EM.stop
131
+ }
132
+ expect(@log).to eq([false, :error])
133
+ end
134
+ end
135
+ end