riak-client 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/RELNOTES.md +3 -0
- data/lib/riak/bucket.rb +1 -1
- data/lib/riak/client.rb +14 -7
- data/lib/riak/client/beefcake/messages.rb +13 -0
- data/lib/riak/multi.rb +101 -0
- data/lib/riak/multiexist.rb +14 -0
- data/lib/riak/multiget.rb +7 -107
- data/lib/riak/version.rb +1 -1
- metadata +12 -234
- data/.document +0 -5
- data/.gitignore +0 -44
- data/.rspec +0 -2
- data/Gemfile +0 -17
- data/Guardfile +0 -20
- data/Rakefile +0 -124
- data/riak-client.gemspec +0 -71
- data/spec/failover/failover.rb +0 -59
- data/spec/fixtures/bitcask.txt +0 -25
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-basic-conflict.txt +0 -15
- data/spec/fixtures/multipart-blank.txt +0 -7
- data/spec/fixtures/multipart-mapreduce.txt +0 -10
- data/spec/fixtures/multipart-with-body.txt +0 -16
- data/spec/fixtures/multipart-with-marked-tombstones.txt +0 -17
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +0 -16
- data/spec/fixtures/server.cert.crt +0 -15
- data/spec/fixtures/server.cert.key +0 -15
- data/spec/fixtures/test.pem +0 -1
- data/spec/fixtures/yz_schema_template.xml +0 -18
- data/spec/integration/riak/bucket_types_spec.rb +0 -308
- data/spec/integration/riak/conflict_resolution_spec.rb +0 -96
- data/spec/integration/riak/counters_spec.rb +0 -36
- data/spec/integration/riak/crdt/configuration_spec.rb +0 -38
- data/spec/integration/riak/crdt_search_spec.rb +0 -176
- data/spec/integration/riak/crdt_spec.rb +0 -332
- data/spec/integration/riak/crdt_validation/map_spec.rb +0 -63
- data/spec/integration/riak/crdt_validation/set_spec.rb +0 -122
- data/spec/integration/riak/encodings/crdt_spec.rb +0 -122
- data/spec/integration/riak/encodings/kv_spec.rb +0 -87
- data/spec/integration/riak/encodings/yz_spec.rb +0 -142
- data/spec/integration/riak/preflist_spec.rb +0 -43
- data/spec/integration/riak/properties_spec.rb +0 -69
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +0 -33
- data/spec/integration/riak/protobuffs/timeouts_spec.rb +0 -178
- data/spec/integration/riak/protobuffs_backends_spec.rb +0 -40
- data/spec/integration/riak/search_spec.rb +0 -104
- data/spec/integration/riak/secondary_index_spec.rb +0 -72
- data/spec/integration/riak/security_spec.rb +0 -105
- data/spec/integration/riak/threading_spec.rb +0 -154
- data/spec/integration/riak/time_series_spec.rb +0 -212
- data/spec/integration/yokozuna/index_spec.rb +0 -61
- data/spec/integration/yokozuna/queries_spec.rb +0 -115
- data/spec/integration/yokozuna/schema_spec.rb +0 -49
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +0 -247
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +0 -244
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +0 -53
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +0 -189
- data/spec/riak/beefcake_protobuffs_backend/ts_cell_codec_spec.rb +0 -124
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +0 -162
- data/spec/riak/bucket_properties_spec.rb +0 -135
- data/spec/riak/bucket_spec.rb +0 -275
- data/spec/riak/bucket_type_spec.rb +0 -50
- data/spec/riak/bucket_typed/bucket_spec.rb +0 -78
- data/spec/riak/client_spec.rb +0 -304
- data/spec/riak/core_ext/to_param_spec.rb +0 -15
- data/spec/riak/counter_spec.rb +0 -122
- data/spec/riak/crdt/counter_spec.rb +0 -55
- data/spec/riak/crdt/hyper_log_log_spec.rb +0 -56
- data/spec/riak/crdt/inner_counter_spec.rb +0 -21
- data/spec/riak/crdt/inner_flag_spec.rb +0 -39
- data/spec/riak/crdt/inner_map_spec.rb +0 -47
- data/spec/riak/crdt/inner_register_spec.rb +0 -40
- data/spec/riak/crdt/inner_set_spec.rb +0 -33
- data/spec/riak/crdt/map_spec.rb +0 -78
- data/spec/riak/crdt/set_spec.rb +0 -61
- data/spec/riak/crdt/shared_examples.rb +0 -88
- data/spec/riak/crdt/typed_collection_spec.rb +0 -225
- data/spec/riak/escape_spec.rb +0 -72
- data/spec/riak/feature_detection_spec.rb +0 -77
- data/spec/riak/index_collection_spec.rb +0 -53
- data/spec/riak/instrumentation_spec.rb +0 -124
- data/spec/riak/link_spec.rb +0 -85
- data/spec/riak/list_buckets_spec.rb +0 -41
- data/spec/riak/map_reduce/filter_builder_spec.rb +0 -32
- data/spec/riak/map_reduce/phase_spec.rb +0 -142
- data/spec/riak/map_reduce_spec.rb +0 -434
- data/spec/riak/multiget_spec.rb +0 -81
- data/spec/riak/node_spec.rb +0 -26
- data/spec/riak/robject_spec.rb +0 -542
- data/spec/riak/search/index_spec.rb +0 -72
- data/spec/riak/search/query_spec.rb +0 -88
- data/spec/riak/search/result_collection_spec.rb +0 -89
- data/spec/riak/search/result_document_spec.rb +0 -106
- data/spec/riak/search/schema_spec.rb +0 -63
- data/spec/riak/search_spec.rb +0 -107
- data/spec/riak/secondary_index_spec.rb +0 -225
- data/spec/riak/serializers_spec.rb +0 -121
- data/spec/riak/stamp_spec.rb +0 -54
- data/spec/riak/time_series/deletion_spec.rb +0 -33
- data/spec/riak/time_series/listing_spec.rb +0 -51
- data/spec/riak/time_series/submission_spec.rb +0 -35
- data/spec/riak/util/gzip_spec.rb +0 -49
- data/spec/riak/walk_spec_spec.rb +0 -203
- data/spec/spec_helper.rb +0 -67
- data/spec/support/certs/README.md +0 -13
- data/spec/support/certs/ca.crt +0 -21
- data/spec/support/certs/client.crl +0 -13
- data/spec/support/certs/client.crt +0 -94
- data/spec/support/certs/client.csr +0 -18
- data/spec/support/certs/client.key +0 -27
- data/spec/support/certs/empty_ca.crt +0 -21
- data/spec/support/certs/server.crl +0 -13
- data/spec/support/certs/server.crt +0 -94
- data/spec/support/certs/server.key +0 -27
- data/spec/support/crdt_search_config.rb +0 -112
- data/spec/support/crdt_search_fixtures.rb +0 -42
- data/spec/support/integration_setup.rb +0 -10
- data/spec/support/search_config.rb +0 -83
- data/spec/support/search_corpus_setup.rb +0 -39
- data/spec/support/test_client.rb +0 -52
- data/spec/support/test_client.yml.example +0 -10
- data/spec/support/unified_backend_examples.rb +0 -402
- data/spec/support/version_filter.rb +0 -12
- data/spec/support/wait_until.rb +0 -20
@@ -1,434 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Riak::MapReduce do
|
4
|
-
|
5
|
-
let(:backend){ double 'Backend' }
|
6
|
-
let(:client) do
|
7
|
-
Riak::Client.new.tap do |c|
|
8
|
-
allow(c).to receive(:backend).and_yield(backend)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
let(:mr) { Riak::MapReduce.new(client) }
|
12
|
-
|
13
|
-
let(:bucket_type){ client.bucket_type 'type' }
|
14
|
-
let(:typed_bucket){ bucket_type.bucket 'bucket' }
|
15
|
-
let(:typed_object){ Riak::RObject.new typed_bucket, 'key' }
|
16
|
-
|
17
|
-
let(:default_type){ client.bucket_type Riak::BucketType::DEFAULT_NAME }
|
18
|
-
let(:default_bucket){ default_type.bucket 'bucket' }
|
19
|
-
let(:default_object){ Riak::RObject.new default_bucket, 'key' }
|
20
|
-
|
21
|
-
it "requires a client" do
|
22
|
-
expect { Riak::MapReduce.new }.to raise_error
|
23
|
-
expect { Riak::MapReduce.new(client) }.not_to raise_error
|
24
|
-
end
|
25
|
-
|
26
|
-
it "initializes the inputs and query to empty arrays" do
|
27
|
-
expect(mr.inputs).to eq([])
|
28
|
-
expect(mr.query).to eq([])
|
29
|
-
end
|
30
|
-
|
31
|
-
it "yields itself when given a block on initializing" do
|
32
|
-
mapred2 = nil
|
33
|
-
mapred = Riak::MapReduce.new(client) do |mr|
|
34
|
-
mapred2 = mr
|
35
|
-
end
|
36
|
-
expect(mapred2).to eq(mapred)
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "adding inputs" do
|
40
|
-
it "returns self for chaining" do
|
41
|
-
expect(mr.add("foo", "bar")).to eq(mr)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds bucket/key pairs to the inputs" do
|
45
|
-
mr.add("foo", "bar")
|
46
|
-
expect(mr.inputs).to eq([%w(foo bar)])
|
47
|
-
end
|
48
|
-
|
49
|
-
it "adds an array containing a bucket/key pair to the inputs" do
|
50
|
-
mr.add(%w(foo bar))
|
51
|
-
expect(mr.inputs).to eq([%w(foo bar)])
|
52
|
-
end
|
53
|
-
|
54
|
-
it "adds an object to the inputs by its bucket and key" do
|
55
|
-
bucket = Riak::Bucket.new(client, "foo")
|
56
|
-
obj = Riak::RObject.new(bucket, "bar")
|
57
|
-
mr.add(obj)
|
58
|
-
expect(mr.inputs).to eq([%w(foo bar)])
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'adds a bucket-typed object to the inputs' do
|
62
|
-
mr.add typed_object
|
63
|
-
expect(mr.inputs).to eq [[typed_bucket.name,
|
64
|
-
typed_object.key,
|
65
|
-
'',
|
66
|
-
typed_bucket.type.name
|
67
|
-
]]
|
68
|
-
end
|
69
|
-
|
70
|
-
it "adds an array containing a bucket/key/key-data triple to the inputs" do
|
71
|
-
mr.add(["foo", "bar", 1000])
|
72
|
-
expect(mr.inputs).to eq([["foo", "bar", 1000]])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "uses a bucket name as the single input" do
|
76
|
-
mr.add(Riak::Bucket.new(client, "foo"))
|
77
|
-
expect(mr.inputs).to eq("foo")
|
78
|
-
mr.add("docs")
|
79
|
-
expect(mr.inputs).to eq("docs")
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'accepts a bucket typed bucket as a single input' do
|
83
|
-
mr.add typed_bucket
|
84
|
-
expect(mr.inputs).to eq([bucket_type.name, typed_bucket.name ])
|
85
|
-
end
|
86
|
-
|
87
|
-
it "doesn't pass a default bucket type name" do
|
88
|
-
mr.add default_bucket
|
89
|
-
expect(mr.inputs).to eq default_bucket.name
|
90
|
-
end
|
91
|
-
|
92
|
-
it "accepts a list of key-filters along with a bucket" do
|
93
|
-
mr.add("foo",
|
94
|
-
[[:tokenize, "-", 3],
|
95
|
-
[:string_to_int],
|
96
|
-
[:between, 2009, 2010]])
|
97
|
-
expect(mr.inputs).to eq({bucket: "foo",
|
98
|
-
key_filters: [[:tokenize, "-", 3],
|
99
|
-
[:string_to_int],
|
100
|
-
[:between, 2009, 2010]]})
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'accepts a list of key-filters along with a bucket-typed bucket' do
|
104
|
-
filters = [
|
105
|
-
[:tokenize, '-', 3],
|
106
|
-
[:string_to_int],
|
107
|
-
[:between, 2009, 2010]
|
108
|
-
]
|
109
|
-
|
110
|
-
mr.add(typed_bucket, filters)
|
111
|
-
|
112
|
-
expect(mr.inputs).to eq(
|
113
|
-
bucket: [typed_bucket.type.name,
|
114
|
-
typed_bucket.name],
|
115
|
-
key_filters: filters
|
116
|
-
)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "adds a bucket and filter list via a builder block" do
|
120
|
-
mr.filter("foo") do
|
121
|
-
tokenize "-", 3
|
122
|
-
string_to_int
|
123
|
-
between 2009, 2010
|
124
|
-
end
|
125
|
-
expect(mr.inputs).to eq(bucket: "foo",
|
126
|
-
key_filters: [[:tokenize, "-", 3],
|
127
|
-
[:string_to_int],
|
128
|
-
[:between, 2009, 2010]])
|
129
|
-
end
|
130
|
-
|
131
|
-
context "using secondary indexes as inputs" do
|
132
|
-
it "set the inputs for a bucket-typed bucket" do
|
133
|
-
expect(mr.index(typed_bucket, "email_bin", "sean@basho.com")).to eq(mr)
|
134
|
-
expect(mr.inputs).to eq(bucket: [typed_bucket.type.name, typed_bucket.name],
|
135
|
-
index: "email_bin",
|
136
|
-
key: "sean@basho.com")
|
137
|
-
end
|
138
|
-
|
139
|
-
it "sets the inputs for equality" do
|
140
|
-
expect(mr.index("foo", "email_bin", "sean@basho.com")).to eq(mr)
|
141
|
-
expect(mr.inputs).to eq(bucket: "foo",
|
142
|
-
index: "email_bin",
|
143
|
-
key: "sean@basho.com")
|
144
|
-
end
|
145
|
-
|
146
|
-
it "sets the inputs for a range" do
|
147
|
-
expect(mr.index("foo", "rank_int", 10..20)).to eq(mr)
|
148
|
-
expect(mr.inputs).to eq(bucket: "foo",
|
149
|
-
index: "rank_int",
|
150
|
-
start: 10,
|
151
|
-
end: 20)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "raises an error when given an invalid query" do
|
155
|
-
expect do
|
156
|
-
mr.index("foo", "rank_int", 1.0348)
|
157
|
-
end.to raise_error(ArgumentError)
|
158
|
-
expect do
|
159
|
-
mr.index("foo", "rank_int", Range.new(1.03, 1.05))
|
160
|
-
end.to raise_error(ArgumentError)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
describe "escaping" do
|
165
|
-
before { @oldesc, Riak.escaper = Riak.escaper, CGI }
|
166
|
-
after { Riak.escaper = @oldesc }
|
167
|
-
|
168
|
-
context "when url_decoding is false" do
|
169
|
-
before { @urldecode, Riak.url_decoding = Riak.url_decoding, false }
|
170
|
-
after { Riak.url_decoding = @urldecode }
|
171
|
-
|
172
|
-
it "adds bucket/key pairs to the inputs with bucket and key escaped" do
|
173
|
-
mr.add("[foo]", "(bar)")
|
174
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
175
|
-
end
|
176
|
-
|
177
|
-
it "adds an escaped array containing a bucket/key pair to the inputs" do
|
178
|
-
mr.add(["[foo]", "(bar)"])
|
179
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
180
|
-
end
|
181
|
-
|
182
|
-
it "adds an object to the inputs by its escaped bucket and key" do
|
183
|
-
bucket = Riak::Bucket.new(client, "[foo]")
|
184
|
-
obj = Riak::RObject.new(bucket, "(bar)")
|
185
|
-
mr.add(obj)
|
186
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
187
|
-
end
|
188
|
-
|
189
|
-
it "adds an escaped array containing a bucket/key/key-data triple to the inputs" do
|
190
|
-
mr.add(["[foo]", "(bar)", "[]()"])
|
191
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29", "[]()"]])
|
192
|
-
end
|
193
|
-
|
194
|
-
it "uses an escaped bucket name as the single input" do
|
195
|
-
mr.add(Riak::Bucket.new(client, "[foo]"))
|
196
|
-
expect(mr.inputs).to eq("%5Bfoo%5D")
|
197
|
-
mr.add("docs")
|
198
|
-
expect(mr.inputs).to eq("docs")
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "when url_decoding is true" do
|
203
|
-
before { @urldecode, Riak.url_decoding = Riak.url_decoding, true }
|
204
|
-
after { Riak.url_decoding = @urldecode }
|
205
|
-
|
206
|
-
it "adds bucket/key pairs to the inputs with bucket and key unescaped" do
|
207
|
-
mr.add("[foo]", "(bar)")
|
208
|
-
expect(mr.inputs).to eq([["[foo]", "(bar)"]])
|
209
|
-
end
|
210
|
-
|
211
|
-
it "adds an unescaped array containing a bucket/key pair to the inputs" do
|
212
|
-
mr.add(["[foo]", "(bar)"])
|
213
|
-
expect(mr.inputs).to eq([["[foo]", "(bar)"]])
|
214
|
-
end
|
215
|
-
|
216
|
-
it "adds an object to the inputs by its unescaped bucket and key" do
|
217
|
-
bucket = Riak::Bucket.new(client, "[foo]")
|
218
|
-
obj = Riak::RObject.new(bucket, "(bar)")
|
219
|
-
mr.add(obj)
|
220
|
-
expect(mr.inputs).to eq([["[foo]", "(bar)"]])
|
221
|
-
end
|
222
|
-
|
223
|
-
it "adds an unescaped array containing a bucket/key/key-data triple to the inputs" do
|
224
|
-
mr.add(["[foo]", "(bar)", "[]()"])
|
225
|
-
expect(mr.inputs).to eq([["[foo]", "(bar)", "[]()"]])
|
226
|
-
end
|
227
|
-
|
228
|
-
it "uses an unescaped bucket name as the single input" do
|
229
|
-
mr.add(Riak::Bucket.new(client, "[foo]"))
|
230
|
-
expect(mr.inputs).to eq("[foo]")
|
231
|
-
mr.add("docs")
|
232
|
-
expect(mr.inputs).to eq("docs")
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
context "escaping" do
|
238
|
-
before { @oldesc, Riak.escaper = Riak.escaper, CGI }
|
239
|
-
after { Riak.escaper = @oldesc }
|
240
|
-
|
241
|
-
it "adds bucket/key pairs to the inputs with bucket and key escaped" do
|
242
|
-
mr.add("[foo]", "(bar)")
|
243
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
244
|
-
end
|
245
|
-
|
246
|
-
it "adds an escaped array containing a bucket/key pair to the inputs" do
|
247
|
-
mr.add(["[foo]", "(bar)"])
|
248
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
249
|
-
end
|
250
|
-
|
251
|
-
it "adds an object to the inputs by its escaped bucket and key" do
|
252
|
-
bucket = Riak::Bucket.new(client, "[foo]")
|
253
|
-
obj = Riak::RObject.new(bucket, "(bar)")
|
254
|
-
mr.add(obj)
|
255
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
256
|
-
end
|
257
|
-
|
258
|
-
it "adds an escaped array containing a bucket/key/key-data triple to the inputs" do
|
259
|
-
mr.add(["[foo]", "(bar)", "[]()"])
|
260
|
-
expect(mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29", "[]()"]])
|
261
|
-
end
|
262
|
-
|
263
|
-
it "uses an escaped bucket name as the single input" do
|
264
|
-
mr.add(Riak::Bucket.new(client, "[foo]"))
|
265
|
-
expect(mr.inputs).to eq("%5Bfoo%5D")
|
266
|
-
mr.add("docs")
|
267
|
-
expect(mr.inputs).to eq("docs")
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context "when adding an input that will result in full-bucket mapreduce" do
|
272
|
-
before { Riak.disable_list_keys_warnings = false }
|
273
|
-
after { Riak.disable_list_keys_warnings = true }
|
274
|
-
|
275
|
-
it "warns about list-keys on buckets" do
|
276
|
-
expect(mr).to receive(:warn).twice
|
277
|
-
mr.add("foo")
|
278
|
-
mr.add(Riak::Bucket.new(client, "foo"))
|
279
|
-
end
|
280
|
-
|
281
|
-
it "warns about list-keys on key-filters" do
|
282
|
-
expect(mr).to receive(:warn)
|
283
|
-
mr.filter("foo") { matches "bar" }
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
[:map, :reduce].each do |type|
|
289
|
-
describe "adding #{type} phases" do
|
290
|
-
it "returns self for chaining" do
|
291
|
-
expect(mr.send(type, "function(){}")).to eq(mr)
|
292
|
-
end
|
293
|
-
|
294
|
-
it "accepts a function string" do
|
295
|
-
mr.send(type, "function(){}")
|
296
|
-
expect(mr.query.size).to eq(1)
|
297
|
-
phase = mr.query.first
|
298
|
-
expect(phase.function).to eq("function(){}")
|
299
|
-
expect(phase.type).to eq(type)
|
300
|
-
end
|
301
|
-
|
302
|
-
it "accepts a function and options" do
|
303
|
-
mr.send(type, "function(){}", :keep => true)
|
304
|
-
expect(mr.query.size).to eq(1)
|
305
|
-
phase = mr.query.first
|
306
|
-
expect(phase.function).to eq("function(){}")
|
307
|
-
expect(phase.type).to eq(type)
|
308
|
-
expect(phase.keep).to be_truthy
|
309
|
-
end
|
310
|
-
|
311
|
-
it "accepts a module/function pair" do
|
312
|
-
mr.send(type, %w(riak mapsomething))
|
313
|
-
expect(mr.query.size).to eq(1)
|
314
|
-
phase = mr.query.first
|
315
|
-
expect(phase.function).to eq(%w(riak mapsomething))
|
316
|
-
expect(phase.type).to eq(type)
|
317
|
-
expect(phase.language).to eq("erlang")
|
318
|
-
end
|
319
|
-
|
320
|
-
it "accepts a module/function pair with extra options" do
|
321
|
-
mr.send(type, %w(riak mapsomething), :arg => [1000])
|
322
|
-
expect(mr.query.size).to eq(1)
|
323
|
-
phase = mr.query.first
|
324
|
-
expect(phase.function).to eq(%w(riak mapsomething))
|
325
|
-
expect(phase.type).to eq(type)
|
326
|
-
expect(phase.language).to eq("erlang")
|
327
|
-
expect(phase.arg).to eq([1000])
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe "adding link phases" do
|
333
|
-
it "returns self for chaining" do
|
334
|
-
expect(mr.link({})).to eq(mr)
|
335
|
-
end
|
336
|
-
|
337
|
-
it "accepts a WalkSpec" do
|
338
|
-
mr.link(Riak::WalkSpec.new(:tag => "next"))
|
339
|
-
expect(mr.query.size).to eq(1)
|
340
|
-
phase = mr.query.first
|
341
|
-
expect(phase.type).to eq(:link)
|
342
|
-
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
343
|
-
expect(phase.function.tag).to eq("next")
|
344
|
-
end
|
345
|
-
|
346
|
-
it "accepts a WalkSpec and a hash of options" do
|
347
|
-
mr.link(Riak::WalkSpec.new(:bucket => "foo"), :keep => true)
|
348
|
-
expect(mr.query.size).to eq(1)
|
349
|
-
phase = mr.query.first
|
350
|
-
expect(phase.type).to eq(:link)
|
351
|
-
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
352
|
-
expect(phase.function.bucket).to eq("foo")
|
353
|
-
expect(phase.keep).to be_truthy
|
354
|
-
end
|
355
|
-
|
356
|
-
it "accepts a hash of options intermingled with the walk spec options" do
|
357
|
-
mr.link(:tag => "snakes", :arg => [1000])
|
358
|
-
expect(mr.query.size).to eq(1)
|
359
|
-
phase = mr.query.first
|
360
|
-
expect(phase.arg).to eq([1000])
|
361
|
-
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
362
|
-
expect(phase.function.tag).to eq("snakes")
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
describe "converting to JSON for the job" do
|
367
|
-
it "includes the inputs and query keys" do
|
368
|
-
expect(mr.to_json).to match(/"inputs":/)
|
369
|
-
end
|
370
|
-
|
371
|
-
it "maps phases to their JSON equivalents" do
|
372
|
-
phase = Riak::MapReduce::Phase.new(:type => :map, :function => "function(){}")
|
373
|
-
mr.query << phase
|
374
|
-
expect(mr.to_json).to include('"source":"function(){}"')
|
375
|
-
expect(mr.to_json).to include('"query":[{"map":{')
|
376
|
-
end
|
377
|
-
|
378
|
-
it "emits only the bucket name when the input is the whole bucket" do
|
379
|
-
mr.add("foo")
|
380
|
-
expect(mr.to_json).to include('"inputs":"foo"')
|
381
|
-
end
|
382
|
-
|
383
|
-
it "emits an array of inputs when there are multiple inputs" do
|
384
|
-
mr.add("foo", "bar", 1000).add("foo", "baz")
|
385
|
-
expect(mr.to_json).to include('"inputs":[["foo","bar",1000],["foo","baz"]]')
|
386
|
-
end
|
387
|
-
|
388
|
-
it "adds the timeout value when set" do
|
389
|
-
mr.timeout(50000)
|
390
|
-
expect(mr.to_json).to include('"timeout":50000')
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
it "returns self from setting the timeout" do
|
395
|
-
expect(mr.timeout(5000)).to eq(mr)
|
396
|
-
end
|
397
|
-
|
398
|
-
describe "executing the map reduce job" do
|
399
|
-
before :each do
|
400
|
-
mr.map("Riak.mapValues", :keep => true)
|
401
|
-
end
|
402
|
-
|
403
|
-
it "submits the query to the backend" do
|
404
|
-
expect(backend).to receive(:mapred).with(mr).and_return([])
|
405
|
-
expect(mr.run).to eq([])
|
406
|
-
end
|
407
|
-
|
408
|
-
it "passes the given block to the backend for streaming" do
|
409
|
-
arr = []
|
410
|
-
expect(backend).to receive(:mapred).with(mr).and_yield("foo").and_yield("bar")
|
411
|
-
mr.run {|v| arr << v }
|
412
|
-
expect(arr).to eq(%w(foo bar))
|
413
|
-
end
|
414
|
-
|
415
|
-
it "interprets failed requests with JSON content-types as map reduce errors" do
|
416
|
-
allow(backend).to receive(:mapred).
|
417
|
-
and_raise(Riak::ProtobuffsFailedRequest.new(:server_error, '{"error":"syntax error"}'))
|
418
|
-
expect{ mr.run }.to raise_error(Riak::MapReduceError)
|
419
|
-
begin
|
420
|
-
mr.run
|
421
|
-
rescue Riak::MapReduceError => mre
|
422
|
-
expect(mre.message).to include('{"error":"syntax error"}')
|
423
|
-
else
|
424
|
-
fail "No exception raised!"
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
it "re-raises non-JSON error responses" do
|
429
|
-
allow(backend).to receive(:mapred).
|
430
|
-
and_raise(Riak::ProtobuffsFailedRequest.new(:server_error, 'Oops, you bwoke it.'))
|
431
|
-
expect { mr.run }.to raise_error(Riak::FailedRequest)
|
432
|
-
end
|
433
|
-
end
|
434
|
-
end
|
data/spec/riak/multiget_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Riak::Multiget do
|
4
|
-
before :each do
|
5
|
-
@client = Riak::Client.new
|
6
|
-
@bucket = Riak::Bucket.new(@client, 'foo')
|
7
|
-
@pairs = [[@bucket, 'key1'], [@bucket, 'key2']]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "initialization" do
|
11
|
-
it "accepts a client and an array of bucket/key pairs" do
|
12
|
-
expect { Riak::Multiget.new(@client, @pairs) }.not_to raise_error
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "operation" do
|
17
|
-
it "fetches both keys from the bucket" do
|
18
|
-
expect(@bucket).to receive(:[]).with('key1')
|
19
|
-
expect(@bucket).to receive(:[]).with('key2')
|
20
|
-
|
21
|
-
@multiget = Riak::Multiget.new(@client, @pairs)
|
22
|
-
@multiget.fetch
|
23
|
-
@multiget.wait_for_finish
|
24
|
-
end
|
25
|
-
|
26
|
-
it "fetches asynchronously" do
|
27
|
-
# make fetches slow
|
28
|
-
@slow_mtx = Mutex.new
|
29
|
-
@slow_mtx.lock
|
30
|
-
|
31
|
-
# set up fetch process to wait on key2
|
32
|
-
expect(@bucket).to receive(:[]) { |key|
|
33
|
-
next if key == 'key1'
|
34
|
-
|
35
|
-
# wait for test process
|
36
|
-
@slow_mtx.lock
|
37
|
-
}.twice
|
38
|
-
|
39
|
-
# start fetch process
|
40
|
-
@multiget = Riak::Multiget.new(@client, @pairs)
|
41
|
-
@multiget.fetch
|
42
|
-
|
43
|
-
expect(@multiget.finished?).to be_falsey
|
44
|
-
|
45
|
-
# allow fetch
|
46
|
-
@slow_mtx.unlock
|
47
|
-
|
48
|
-
@results = @multiget.results
|
49
|
-
expect(@multiget.finished?).to be_truthy
|
50
|
-
expect(@results).to be_a Hash
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns found objects when only some objects are found" do
|
54
|
-
expect(@bucket).to receive(:[]).
|
55
|
-
with('key1').
|
56
|
-
and_raise(Riak::ProtobuffsFailedRequest.new(:not_found, "not found"))
|
57
|
-
|
58
|
-
expect(@bucket).to receive(:[]).
|
59
|
-
with('key2').
|
60
|
-
and_return(true)
|
61
|
-
|
62
|
-
@results = Riak::Multiget.get_all @client, @pairs
|
63
|
-
|
64
|
-
expect(@results[[@bucket, 'key1']]).to be_nil
|
65
|
-
expect(@results[[@bucket, 'key2']]).to be_truthy
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "results" do
|
70
|
-
it "returns a hash of pairs to values" do
|
71
|
-
expect(@bucket).to receive(:[]).with('key1')
|
72
|
-
expect(@bucket).to receive(:[]).with('key2')
|
73
|
-
|
74
|
-
@multiget = Riak::Multiget.new(@client, @pairs)
|
75
|
-
@multiget.fetch
|
76
|
-
@results = @multiget.results
|
77
|
-
|
78
|
-
expect(@results).to be_a Hash
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|