riak-client 1.4.5 → 2.0.0.rc1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/{LICENSE → LICENSE.md} +0 -0
- data/README.markdown +211 -66
- data/RELEASE_NOTES.md +22 -47
- data/Rakefile +45 -0
- data/lib/riak.rb +1 -1
- data/lib/riak/bucket.rb +2 -2
- data/lib/riak/client.rb +22 -195
- data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
- data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
- data/lib/riak/client/beefcake/footer +4 -0
- data/lib/riak/client/beefcake/header +6 -0
- data/lib/riak/client/beefcake/message_codes.rb +29 -0
- data/lib/riak/client/beefcake/message_overlay.rb +61 -0
- data/lib/riak/client/beefcake/messages.rb +733 -371
- data/lib/riak/client/beefcake/object_methods.rb +1 -1
- data/lib/riak/client/beefcake/protocol.rb +105 -0
- data/lib/riak/client/beefcake/socket.rb +243 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
- data/lib/riak/client/node.rb +4 -75
- data/lib/riak/client/protobuffs_backend.rb +6 -14
- data/lib/riak/client/search.rb +0 -64
- data/lib/riak/client/yokozuna.rb +52 -0
- data/lib/riak/counter.rb +1 -1
- data/lib/riak/crdt.rb +21 -0
- data/lib/riak/crdt/base.rb +97 -0
- data/lib/riak/crdt/batch_counter.rb +19 -0
- data/lib/riak/crdt/batch_map.rb +41 -0
- data/lib/riak/crdt/counter.rb +71 -0
- data/lib/riak/crdt/inner_counter.rb +74 -0
- data/lib/riak/crdt/inner_flag.rb +42 -0
- data/lib/riak/crdt/inner_map.rb +53 -0
- data/lib/riak/crdt/inner_register.rb +26 -0
- data/lib/riak/crdt/inner_set.rb +95 -0
- data/lib/riak/crdt/map.rb +88 -0
- data/lib/riak/crdt/operation.rb +19 -0
- data/lib/riak/crdt/set.rb +156 -0
- data/lib/riak/crdt/typed_collection.rb +131 -0
- data/lib/riak/errors/base.rb +9 -0
- data/lib/riak/errors/connection_error.rb +44 -0
- data/lib/riak/errors/crdt_error.rb +18 -0
- data/lib/riak/errors/failed_request.rb +56 -0
- data/lib/riak/errors/protobuffs_error.rb +11 -0
- data/lib/riak/i18n.rb +2 -0
- data/lib/riak/json.rb +1 -1
- data/lib/riak/locale/en.yml +26 -1
- data/lib/riak/locale/fr.yml +0 -1
- data/lib/riak/map_reduce.rb +1 -1
- data/lib/riak/map_reduce/results.rb +1 -1
- data/lib/riak/multiget.rb +1 -2
- data/lib/riak/rcontent.rb +8 -3
- data/lib/riak/robject.rb +2 -8
- data/lib/riak/secondary_index.rb +4 -4
- data/lib/riak/serializers.rb +1 -1
- data/lib/riak/util/escape.rb +3 -5
- data/lib/riak/version.rb +1 -1
- data/lib/riak/walk_spec.rb +7 -3
- data/riak-client.gemspec +10 -8
- data/spec/fixtures/bitcask.txt +25 -0
- data/spec/integration/riak/bucket_types_spec.rb +61 -0
- data/spec/integration/riak/counters_spec.rb +17 -32
- data/spec/integration/riak/crdt_spec.rb +181 -0
- data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
- data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
- data/spec/integration/riak/security_spec.rb +94 -0
- data/spec/integration/riak/threading_spec.rb +24 -67
- data/spec/integration/yokozuna/index_spec.rb +61 -0
- data/spec/integration/yokozuna/queries_spec.rb +116 -0
- data/spec/integration/yokozuna/schema_spec.rb +49 -0
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
- data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
- data/spec/riak/bucket_spec.rb +81 -77
- data/spec/riak/client_spec.rb +43 -340
- data/spec/riak/core_ext/to_param_spec.rb +2 -2
- data/spec/riak/counter_spec.rb +20 -20
- data/spec/riak/crdt/counter_spec.rb +52 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -0
- data/spec/riak/crdt/inner_flag_spec.rb +39 -0
- data/spec/riak/crdt/inner_map_spec.rb +47 -0
- data/spec/riak/crdt/inner_register_spec.rb +40 -0
- data/spec/riak/crdt/inner_set_spec.rb +33 -0
- data/spec/riak/crdt/map_spec.rb +77 -0
- data/spec/riak/crdt/set_spec.rb +58 -0
- data/spec/riak/crdt/shared_examples.rb +74 -0
- data/spec/riak/crdt/typed_collection_spec.rb +231 -0
- data/spec/riak/escape_spec.rb +33 -37
- data/spec/riak/feature_detection_spec.rb +45 -45
- data/spec/riak/index_collection_spec.rb +12 -12
- data/spec/riak/link_spec.rb +34 -34
- data/spec/riak/list_buckets_spec.rb +7 -7
- data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
- data/spec/riak/map_reduce/phase_spec.rb +35 -35
- data/spec/riak/map_reduce_spec.rb +89 -87
- data/spec/riak/multiget_spec.rb +20 -15
- data/spec/riak/node_spec.rb +5 -152
- data/spec/riak/robject_spec.rb +95 -108
- data/spec/riak/search_spec.rb +17 -139
- data/spec/riak/secondary_index_spec.rb +49 -49
- data/spec/riak/serializers_spec.rb +9 -9
- data/spec/riak/stamp_spec.rb +9 -9
- data/spec/riak/walk_spec_spec.rb +46 -46
- data/spec/spec_helper.rb +14 -22
- data/spec/support/certs/README.md +13 -0
- data/spec/support/certs/ca.crt +22 -0
- data/spec/support/certs/client.crt +95 -0
- data/spec/support/certs/client.key +27 -0
- data/spec/support/certs/empty_ca.crt +21 -0
- data/spec/support/certs/server.crl +13 -0
- data/spec/support/certs/server.crt +95 -0
- data/spec/support/certs/server.key +27 -0
- data/spec/support/integration_setup.rb +1 -1
- data/spec/support/search_corpus_setup.rb +29 -8
- data/spec/support/test_client.rb +46 -0
- data/spec/support/test_client.yml.example +10 -0
- data/spec/support/unified_backend_examples.rb +104 -83
- data/spec/support/version_filter.rb +2 -2
- data/spec/support/wait_until.rb +14 -0
- metadata +134 -132
- data/erl_src/riak_kv_test014_backend.beam +0 -0
- data/erl_src/riak_kv_test014_backend.erl +0 -189
- data/erl_src/riak_kv_test_backend.beam +0 -0
- data/erl_src/riak_kv_test_backend.erl +0 -731
- data/erl_src/riak_search_test_backend.beam +0 -0
- data/erl_src/riak_search_test_backend.erl +0 -175
- data/lib/riak/client/excon_backend.rb +0 -172
- data/lib/riak/client/http_backend.rb +0 -413
- data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
- data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
- data/lib/riak/client/http_backend/configuration.rb +0 -227
- data/lib/riak/client/http_backend/key_streamer.rb +0 -15
- data/lib/riak/client/http_backend/object_methods.rb +0 -114
- data/lib/riak/client/http_backend/request_headers.rb +0 -34
- data/lib/riak/client/http_backend/transport_methods.rb +0 -201
- data/lib/riak/client/instrumentation.rb +0 -25
- data/lib/riak/client/net_http_backend.rb +0 -82
- data/lib/riak/cluster.rb +0 -151
- data/lib/riak/failed_request.rb +0 -81
- data/lib/riak/instrumentation.rb +0 -6
- data/lib/riak/node.rb +0 -40
- data/lib/riak/node/configuration.rb +0 -304
- data/lib/riak/node/console.rb +0 -133
- data/lib/riak/node/control.rb +0 -207
- data/lib/riak/node/defaults.rb +0 -85
- data/lib/riak/node/generation.rb +0 -127
- data/lib/riak/node/log.rb +0 -34
- data/lib/riak/node/version.rb +0 -29
- data/lib/riak/search.rb +0 -3
- data/lib/riak/test_server.rb +0 -89
- data/lib/riak/util/headers.rb +0 -32
- data/lib/riak/util/multipart.rb +0 -52
- data/lib/riak/util/multipart/stream_parser.rb +0 -62
- data/spec/fixtures/munchausen.txt +0 -1033
- data/spec/integration/riak/cluster_spec.rb +0 -88
- data/spec/integration/riak/http_backends_spec.rb +0 -180
- data/spec/integration/riak/node_spec.rb +0 -170
- data/spec/integration/riak/test_server_spec.rb +0 -57
- data/spec/riak/excon_backend_spec.rb +0 -102
- data/spec/riak/headers_spec.rb +0 -21
- data/spec/riak/http_backend/configuration_spec.rb +0 -273
- data/spec/riak/http_backend/object_methods_spec.rb +0 -243
- data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
- data/spec/riak/http_backend_spec.rb +0 -367
- data/spec/riak/instrumentation_spec.rb +0 -167
- data/spec/riak/multipart_spec.rb +0 -23
- data/spec/riak/net_http_backend_spec.rb +0 -15
- data/spec/riak/stream_parser_spec.rb +0 -53
- data/spec/support/drb_mock_server.rb +0 -39
- data/spec/support/http_backend_implementation_examples.rb +0 -253
- data/spec/support/mock_server.rb +0 -81
- data/spec/support/mocks.rb +0 -4
- data/spec/support/riak_test.rb +0 -77
- data/spec/support/sometimes.rb +0 -46
- data/spec/support/test_server.rb +0 -61
- data/spec/support/test_server.yml.example +0 -14
@@ -6,17 +6,17 @@ describe Riak::IndexCollection do
|
|
6
6
|
@input = {
|
7
7
|
'keys' => %w{first second third}
|
8
8
|
}.to_json
|
9
|
-
|
10
|
-
%w{first second third}.
|
9
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
10
|
+
expect(%w{first second third}).to eq(@coll)
|
11
11
|
end
|
12
12
|
it "should accept a list of keys and a continuation" do
|
13
13
|
@input = {
|
14
14
|
'keys' => %w{first second third},
|
15
15
|
'continuation' => 'examplecontinuation'
|
16
16
|
}.to_json
|
17
|
-
|
18
|
-
%w{first second third}.
|
19
|
-
@coll.continuation.
|
17
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
18
|
+
expect(%w{first second third}).to eq(@coll)
|
19
|
+
expect(@coll.continuation).to eq('examplecontinuation')
|
20
20
|
end
|
21
21
|
it "should accept a list of results hashes" do
|
22
22
|
@input = {
|
@@ -27,9 +27,9 @@ describe Riak::IndexCollection do
|
|
27
27
|
]
|
28
28
|
}.to_json
|
29
29
|
|
30
|
-
|
31
|
-
%w{first second other}.
|
32
|
-
{'first' => %w{first}, 'second' => %w{second other}}.
|
30
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
31
|
+
expect(%w{first second other}).to eq(@coll)
|
32
|
+
expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
|
33
33
|
end
|
34
34
|
it "should accept a list of results hashes and a continuation" do
|
35
35
|
@input = {
|
@@ -41,10 +41,10 @@ describe Riak::IndexCollection do
|
|
41
41
|
'continuation' => 'examplecontinuation'
|
42
42
|
}.to_json
|
43
43
|
|
44
|
-
|
45
|
-
%w{first second other}.
|
46
|
-
@coll.continuation.
|
47
|
-
{'first' => %w{first}, 'second' => %w{second other}}.
|
44
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
45
|
+
expect(%w{first second other}).to eq(@coll)
|
46
|
+
expect(@coll.continuation).to eq('examplecontinuation')
|
47
|
+
expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/spec/riak/link_spec.rb
CHANGED
@@ -4,82 +4,82 @@ describe Riak::Link do
|
|
4
4
|
describe "parsing a link header" do
|
5
5
|
it "should create Link objects from the data" do
|
6
6
|
result = Riak::Link.parse('</riak/foo/bar>; rel="tag", </riak/foo>; rel="up"')
|
7
|
-
result.
|
8
|
-
result.
|
7
|
+
expect(result).to be_kind_of(Array)
|
8
|
+
expect(result).to be_all {|i| Riak::Link === i }
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should set the bucket, key, url and rel parameters properly" do
|
12
12
|
result = Riak::Link.parse('</riak/foo/bar>; riaktag="tag", </riak/foo>; rel="up"')
|
13
|
-
result[0].url.
|
14
|
-
result[0].bucket.
|
15
|
-
result[0].key.
|
16
|
-
result[0].rel.
|
17
|
-
result[1].url.
|
18
|
-
result[1].bucket.
|
19
|
-
result[1].key.
|
20
|
-
result[1].rel.
|
13
|
+
expect(result[0].url).to eq("/riak/foo/bar")
|
14
|
+
expect(result[0].bucket).to eq("foo")
|
15
|
+
expect(result[0].key).to eq("bar")
|
16
|
+
expect(result[0].rel).to eq("tag")
|
17
|
+
expect(result[1].url).to eq("/riak/foo")
|
18
|
+
expect(result[1].bucket).to eq("foo")
|
19
|
+
expect(result[1].key).to eq(nil)
|
20
|
+
expect(result[1].rel).to eq("up")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should keep the url intact if it does not point to a bucket or bucket/key" do
|
24
24
|
result = Riak::Link.parse('</mapred>; rel="riak_kv_wm_mapred"')
|
25
|
-
result[0].url.
|
26
|
-
result[0].bucket.
|
27
|
-
result[0].key.
|
25
|
+
expect(result[0].url).to eq("/mapred")
|
26
|
+
expect(result[0].bucket).to be_nil
|
27
|
+
expect(result[0].key).to be_nil
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should parse the Riak 1.0 URL scheme" do
|
31
31
|
result = Riak::Link.parse('</buckets/b/keys/k>; riaktag="tag"').first
|
32
|
-
result.bucket.
|
33
|
-
result.key.
|
34
|
-
result.tag.
|
32
|
+
expect(result.bucket).to eq('b')
|
33
|
+
expect(result.key).to eq('k')
|
34
|
+
expect(result.tag).to eq('tag')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context "converting to a string" do
|
39
39
|
it "should convert to a string appropriate for use in the Link header" do
|
40
|
-
Riak::Link.new("/riak/foo", "up").to_s.
|
41
|
-
Riak::Link.new("/riak/foo/bar", "next").to_s.
|
42
|
-
Riak::Link.new("/riak", "riak_kv_wm_raw").to_s.
|
40
|
+
expect(Riak::Link.new("/riak/foo", "up").to_s).to eq('</riak/foo>; riaktag="up"')
|
41
|
+
expect(Riak::Link.new("/riak/foo/bar", "next").to_s).to eq('</riak/foo/bar>; riaktag="next"')
|
42
|
+
expect(Riak::Link.new("/riak", "riak_kv_wm_raw").to_s).to eq('</riak>; riaktag="riak_kv_wm_raw"')
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should convert to a string using the new URL scheme" do
|
46
|
-
Riak::Link.new("bucket", "key", "tag").to_s(true).
|
47
|
-
Riak::Link.parse('</riak/bucket/key>; riaktag="tag"').first.to_s(true).
|
46
|
+
expect(Riak::Link.new("bucket", "key", "tag").to_s(true)).to eq('</buckets/bucket/keys/key>; riaktag="tag"')
|
47
|
+
expect(Riak::Link.parse('</riak/bucket/key>; riaktag="tag"').first.to_s(true)).to eq('</buckets/bucket/keys/key>; riaktag="tag"')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should convert to a walk spec when pointing to an object" do
|
52
|
-
Riak::Link.new("/riak/foo/bar", "next").to_walk_spec.to_s.
|
53
|
-
|
52
|
+
expect(Riak::Link.new("/riak/foo/bar", "next").to_walk_spec.to_s).to eq("foo,next,_")
|
53
|
+
expect { Riak::Link.new("/riak/foo", "up").to_walk_spec }.to raise_error
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should be equivalent to a link with the same url and rel" do
|
57
57
|
one = Riak::Link.new("/riak/foo/bar", "next")
|
58
58
|
two = Riak::Link.new("/riak/foo/bar", "next")
|
59
|
-
one.
|
60
|
-
[one].
|
61
|
-
[two].
|
59
|
+
expect(one).to eq(two)
|
60
|
+
expect([one]).to include(two)
|
61
|
+
expect([two]).to include(one)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should unescape the bucket name" do
|
65
|
-
Riak::Link.new("/riak/bucket%20spaces/key", "foo").bucket.
|
65
|
+
expect(Riak::Link.new("/riak/bucket%20spaces/key", "foo").bucket).to eq("bucket spaces")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should unescape the key name" do
|
69
|
-
Riak::Link.new("/riak/bucket/key%2Fname", "foo").key.
|
69
|
+
expect(Riak::Link.new("/riak/bucket/key%2Fname", "foo").key).to eq("key/name")
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should not rely on the prefix to equal /riak/ when extracting the bucket and key" do
|
73
73
|
link = Riak::Link.new("/raw/bucket/key", "foo")
|
74
|
-
link.bucket.
|
75
|
-
link.key.
|
74
|
+
expect(link.bucket).to eq("bucket")
|
75
|
+
expect(link.key).to eq("key")
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should construct from bucket, key and tag" do
|
79
79
|
link = Riak::Link.new("bucket", "key", "tag")
|
80
|
-
link.bucket.
|
81
|
-
link.key.
|
82
|
-
link.tag.
|
83
|
-
link.url.
|
80
|
+
expect(link.bucket).to eq("bucket")
|
81
|
+
expect(link.key).to eq("key")
|
82
|
+
expect(link.tag).to eq("tag")
|
83
|
+
expect(link.url).to eq("/riak/bucket/key")
|
84
84
|
end
|
85
85
|
end
|
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Riak::ListBuckets do
|
4
4
|
before :each do
|
5
|
-
@client = Riak::Client.new
|
6
|
-
@backend =
|
7
|
-
@fake_pool =
|
8
|
-
@fake_pool.
|
5
|
+
@client = Riak::Client.new
|
6
|
+
@backend = double 'backend'
|
7
|
+
@fake_pool = double 'connection pool'
|
8
|
+
allow(@fake_pool).to receive(:take).and_yield(@backend)
|
9
9
|
|
10
|
-
@expect_list = @backend.
|
10
|
+
@expect_list = expect(@backend).to receive(:list_buckets)
|
11
11
|
|
12
12
|
@client.instance_variable_set :@protobuffs_pool, @fake_pool
|
13
13
|
end
|
@@ -33,9 +33,9 @@ describe Riak::ListBuckets do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
@yielded.each do |b|
|
36
|
-
b.
|
36
|
+
expect(b).to be_a Riak::Bucket
|
37
37
|
end
|
38
|
-
@yielded.map(&:name).
|
38
|
+
expect(@yielded.map(&:name)).to eq(%w{abc abd abe bbb ccc ddd})
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Riak::MapReduce::FilterBuilder do
|
4
4
|
subject { Riak::MapReduce::FilterBuilder.new }
|
5
5
|
it "should evaluate the passed block on initialization" do
|
6
|
-
subject.class.new do
|
6
|
+
expect(subject.class.new do
|
7
7
|
matches "foo"
|
8
|
-
end.to_a.
|
8
|
+
end.to_a).to eq([[:matches, "foo"]])
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should add filters to the list" do
|
12
12
|
subject.to_lower
|
13
13
|
subject.similar_to("ripple", 3)
|
14
|
-
subject.to_a.
|
14
|
+
expect(subject.to_a).to eq([[:to_lower],[:similar_to, "ripple", 3]])
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should add a logical operation with a block" do
|
@@ -19,14 +19,14 @@ describe Riak::MapReduce::FilterBuilder do
|
|
19
19
|
starts_with "foo"
|
20
20
|
ends_with "bar"
|
21
21
|
end
|
22
|
-
subject.to_a.
|
22
|
+
expect(subject.to_a).to eq([[:or, [[:starts_with, "foo"],[:ends_with, "bar"]]]])
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should raise an error on a filter arity mismatch" do
|
26
|
-
|
26
|
+
expect { subject.less_than }.to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise an error when a block is not given to a logical operation" do
|
30
|
-
|
30
|
+
expect { subject._or }.to raise_error(ArgumentError)
|
31
31
|
end
|
32
32
|
end
|
@@ -8,52 +8,52 @@ describe Riak::MapReduce::Phase do
|
|
8
8
|
|
9
9
|
it "should initialize with a type and a function" do
|
10
10
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun, :language => "javascript")
|
11
|
-
phase.type.
|
12
|
-
phase.function.
|
13
|
-
phase.language.
|
11
|
+
expect(phase.type).to eq(:map)
|
12
|
+
expect(phase.function).to eq(@js_fun)
|
13
|
+
expect(phase.language).to eq("javascript")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should initialize with a type and an MF" do
|
17
17
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => ["module", "function"], :language => "erlang")
|
18
|
-
phase.type.
|
19
|
-
phase.function.
|
20
|
-
phase.language.
|
18
|
+
expect(phase.type).to eq(:map)
|
19
|
+
expect(phase.function).to eq(["module", "function"])
|
20
|
+
expect(phase.language).to eq("erlang")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should initialize with a type and a bucket/key" do
|
24
24
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "funs", :key => "awesome_map"}, :language => "javascript")
|
25
|
-
phase.type.
|
26
|
-
phase.function.
|
27
|
-
phase.language.
|
25
|
+
expect(phase.type).to eq(:map)
|
26
|
+
expect(phase.function).to eq({:bucket => "funs", :key => "awesome_map"})
|
27
|
+
expect(phase.language).to eq("javascript")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should assume the language is erlang when the function is an array" do
|
31
31
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => ["module", "function"])
|
32
|
-
phase.language.
|
32
|
+
expect(phase.language).to eq("erlang")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should assume the language is javascript when the function is a string and starts with function" do
|
36
36
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun)
|
37
|
-
phase.language.
|
37
|
+
expect(phase.language).to eq("javascript")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should assume the language is erlang when the function is a string and starts with anon fun" do
|
41
41
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @erl_fun)
|
42
|
-
phase.language.
|
42
|
+
expect(phase.language).to eq("erlang")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should assume the language is javascript when the function is a hash" do
|
46
46
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "jobs", :key => "awesome_map"})
|
47
|
-
phase.language.
|
47
|
+
expect(phase.language).to eq("javascript")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should accept a WalkSpec for the function when a link phase" do
|
51
51
|
phase = Riak::MapReduce::Phase.new(:type => :link, :function => Riak::WalkSpec.new({}))
|
52
|
-
phase.function.
|
52
|
+
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should raise an error if a WalkSpec is given for a phase type other than :link" do
|
56
|
-
|
56
|
+
expect { Riak::MapReduce::Phase.new(:type => :map, :function => Riak::WalkSpec.new({})) }.to raise_error(ArgumentError)
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "converting to JSON for the job" do
|
@@ -68,41 +68,41 @@ describe Riak::MapReduce::Phase do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should be an object with a single key of '#{type}'" do
|
71
|
-
@phase.to_json.
|
71
|
+
expect(@phase.to_json).to match(/^\{"#{type}":/)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should include the language" do
|
75
|
-
@phase.to_json.
|
75
|
+
expect(@phase.to_json).to match(/"language":/)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should include the keep value" do
|
79
|
-
@phase.to_json.
|
79
|
+
expect(@phase.to_json).to match(/"keep":false/)
|
80
80
|
@phase.keep = true
|
81
|
-
@phase.to_json.
|
81
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should include the function source when the function is a source string" do
|
85
85
|
@phase.function = "function(v,_,_){ return v; }"
|
86
|
-
@phase.to_json.
|
87
|
-
@phase.to_json.
|
86
|
+
expect(@phase.to_json).to include(@phase.function)
|
87
|
+
expect(@phase.to_json).to match(/"source":/)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should include the function name when the function is not a lambda" do
|
91
91
|
@phase.function = "Riak.mapValues"
|
92
|
-
@phase.to_json.
|
93
|
-
@phase.to_json.
|
92
|
+
expect(@phase.to_json).to include('"name":"Riak.mapValues"')
|
93
|
+
expect(@phase.to_json).not_to include('"source"')
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should include the bucket and key when referring to a stored function" do
|
97
97
|
@phase.function = {:bucket => "design", :key => "wordcount_map"}
|
98
|
-
@phase.to_json.
|
99
|
-
@phase.to_json.
|
98
|
+
expect(@phase.to_json).to include('"bucket":"design"')
|
99
|
+
expect(@phase.to_json).to include('"key":"wordcount_map"')
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should include the module and function when invoking an Erlang function" do
|
103
103
|
@phase.function = ["riak_mapreduce", "mapreduce_fun"]
|
104
|
-
@phase.to_json.
|
105
|
-
@phase.to_json.
|
104
|
+
expect(@phase.to_json).to include('"module":"riak_mapreduce"')
|
105
|
+
expect(@phase.to_json).to include('"function":"mapreduce_fun"')
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -114,28 +114,28 @@ describe Riak::MapReduce::Phase do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should be an object of a single key 'link'" do
|
117
|
-
@phase.to_json.
|
117
|
+
expect(@phase.to_json).to match(/^\{"link":/)
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should include the bucket" do
|
121
|
-
@phase.to_json.
|
121
|
+
expect(@phase.to_json).to match(/"bucket":"_"/)
|
122
122
|
@phase.function[:bucket] = "foo"
|
123
|
-
@phase.to_json.
|
123
|
+
expect(@phase.to_json).to match(/"bucket":"foo"/)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should include the tag" do
|
127
|
-
@phase.to_json.
|
127
|
+
expect(@phase.to_json).to match(/"tag":"_"/)
|
128
128
|
@phase.function[:tag] = "parent"
|
129
|
-
@phase.to_json.
|
129
|
+
expect(@phase.to_json).to match(/"tag":"parent"/)
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should include the keep value" do
|
133
|
-
@phase.to_json.
|
133
|
+
expect(@phase.to_json).to match(/"keep":false/)
|
134
134
|
@phase.keep = true
|
135
|
-
@phase.to_json.
|
135
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
136
136
|
@phase.keep = false
|
137
137
|
@phase.function[:keep] = true
|
138
|
-
@phase.to_json.
|
138
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -3,19 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe Riak::MapReduce do
|
4
4
|
before :each do
|
5
5
|
@client = Riak::Client.new
|
6
|
-
@backend =
|
7
|
-
@client.
|
6
|
+
@backend = double("Backend")
|
7
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
8
8
|
@mr = Riak::MapReduce.new(@client)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should require a client" do
|
12
|
-
|
13
|
-
|
12
|
+
expect { Riak::MapReduce.new }.to raise_error
|
13
|
+
expect { Riak::MapReduce.new(@client) }.not_to raise_error
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should initialize the inputs and query to empty arrays" do
|
17
|
-
@mr.inputs.
|
18
|
-
@mr.query.
|
17
|
+
expect(@mr.inputs).to eq([])
|
18
|
+
expect(@mr.query).to eq([])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should yield itself when given a block on initializing" do
|
@@ -23,46 +23,46 @@ describe Riak::MapReduce do
|
|
23
23
|
@mr = Riak::MapReduce.new(@client) do |mr|
|
24
24
|
@mr2 = mr
|
25
25
|
end
|
26
|
-
@mr2.
|
26
|
+
expect(@mr2).to eq(@mr)
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "adding inputs" do
|
30
30
|
it "should return self for chaining" do
|
31
|
-
@mr.add("foo", "bar").
|
31
|
+
expect(@mr.add("foo", "bar")).to eq(@mr)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should add bucket/key pairs to the inputs" do
|
35
35
|
@mr.add("foo","bar")
|
36
|
-
@mr.inputs.
|
36
|
+
expect(@mr.inputs).to eq([["foo","bar"]])
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should add an array containing a bucket/key pair to the inputs" do
|
40
40
|
@mr.add(["foo","bar"])
|
41
|
-
@mr.inputs.
|
41
|
+
expect(@mr.inputs).to eq([["foo","bar"]])
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should add an object to the inputs by its bucket and key" do
|
45
45
|
bucket = Riak::Bucket.new(@client, "foo")
|
46
46
|
obj = Riak::RObject.new(bucket, "bar")
|
47
47
|
@mr.add(obj)
|
48
|
-
@mr.inputs.
|
48
|
+
expect(@mr.inputs).to eq([["foo", "bar"]])
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should add an array containing a bucket/key/key-data triple to the inputs" do
|
52
52
|
@mr.add(["foo","bar",1000])
|
53
|
-
@mr.inputs.
|
53
|
+
expect(@mr.inputs).to eq([["foo","bar",1000]])
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should use a bucket name as the single input" do
|
57
57
|
@mr.add(Riak::Bucket.new(@client, "foo"))
|
58
|
-
@mr.inputs.
|
58
|
+
expect(@mr.inputs).to eq("foo")
|
59
59
|
@mr.add("docs")
|
60
|
-
@mr.inputs.
|
60
|
+
expect(@mr.inputs).to eq("docs")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should accept a list of key-filters along with a bucket" do
|
64
64
|
@mr.add("foo", [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]])
|
65
|
-
@mr.inputs.
|
65
|
+
expect(@mr.inputs).to eq({:bucket => "foo", :key_filters => [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]]})
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should add a bucket and filter list via a builder block" do
|
@@ -71,18 +71,18 @@ describe Riak::MapReduce do
|
|
71
71
|
string_to_int
|
72
72
|
between 2009, 2010
|
73
73
|
end
|
74
|
-
@mr.inputs.
|
74
|
+
expect(@mr.inputs).to eq({:bucket => "foo", :key_filters => [[:tokenize, "-", 3], [:string_to_int], [:between, 2009, 2010]]})
|
75
75
|
end
|
76
76
|
|
77
77
|
context "using secondary indexes as inputs" do
|
78
78
|
it "should set the inputs for equality" do
|
79
|
-
@mr.index("foo", "email_bin", "sean@basho.com").
|
80
|
-
@mr.inputs.
|
79
|
+
expect(@mr.index("foo", "email_bin", "sean@basho.com")).to eq(@mr)
|
80
|
+
expect(@mr.inputs).to eq({:bucket => "foo", :index => "email_bin", :key => "sean@basho.com"})
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should set the inputs for a range" do
|
84
|
-
@mr.index("foo", "rank_int", 10..20).
|
85
|
-
@mr.inputs.
|
84
|
+
expect(@mr.index("foo", "rank_int", 10..20)).to eq(@mr)
|
85
|
+
expect(@mr.inputs).to eq({:bucket => "foo", :index => "rank_int", :start => 10, :end => 20})
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should raise an error when given an invalid query" do
|
@@ -101,31 +101,31 @@ describe Riak::MapReduce do
|
|
101
101
|
|
102
102
|
it "should add bucket/key pairs to the inputs with bucket and key escaped" do
|
103
103
|
@mr.add("[foo]","(bar)")
|
104
|
-
@mr.inputs.
|
104
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D","%28bar%29"]])
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should add an escaped array containing a bucket/key pair to the inputs" do
|
108
108
|
@mr.add(["[foo]","(bar)"])
|
109
|
-
@mr.inputs.
|
109
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D","%28bar%29"]])
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should add an object to the inputs by its escaped bucket and key" do
|
113
113
|
bucket = Riak::Bucket.new(@client, "[foo]")
|
114
114
|
obj = Riak::RObject.new(bucket, "(bar)")
|
115
115
|
@mr.add(obj)
|
116
|
-
@mr.inputs.
|
116
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should add an escaped array containing a bucket/key/key-data triple to the inputs" do
|
120
120
|
@mr.add(["[foo]","(bar)","[]()"])
|
121
|
-
@mr.inputs.
|
121
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29","[]()"]])
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should use an escaped bucket name as the single input" do
|
125
125
|
@mr.add(Riak::Bucket.new(@client, "[foo]"))
|
126
|
-
@mr.inputs.
|
126
|
+
expect(@mr.inputs).to eq("%5Bfoo%5D")
|
127
127
|
@mr.add("docs")
|
128
|
-
@mr.inputs.
|
128
|
+
expect(@mr.inputs).to eq("docs")
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -135,31 +135,31 @@ describe Riak::MapReduce do
|
|
135
135
|
|
136
136
|
it "should add bucket/key pairs to the inputs with bucket and key unescaped" do
|
137
137
|
@mr.add("[foo]","(bar)")
|
138
|
-
@mr.inputs.
|
138
|
+
expect(@mr.inputs).to eq([["[foo]","(bar)"]])
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should add an unescaped array containing a bucket/key pair to the inputs" do
|
142
142
|
@mr.add(["[foo]","(bar)"])
|
143
|
-
@mr.inputs.
|
143
|
+
expect(@mr.inputs).to eq([["[foo]","(bar)"]])
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should add an object to the inputs by its unescaped bucket and key" do
|
147
147
|
bucket = Riak::Bucket.new(@client, "[foo]")
|
148
148
|
obj = Riak::RObject.new(bucket, "(bar)")
|
149
149
|
@mr.add(obj)
|
150
|
-
@mr.inputs.
|
150
|
+
expect(@mr.inputs).to eq([["[foo]","(bar)"]])
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should add an unescaped array containing a bucket/key/key-data triple to the inputs" do
|
154
154
|
@mr.add(["[foo]","(bar)","[]()"])
|
155
|
-
@mr.inputs.
|
155
|
+
expect(@mr.inputs).to eq([["[foo]","(bar)","[]()"]])
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should use an unescaped bucket name as the single input" do
|
159
159
|
@mr.add(Riak::Bucket.new(@client, "[foo]"))
|
160
|
-
@mr.inputs.
|
160
|
+
expect(@mr.inputs).to eq("[foo]")
|
161
161
|
@mr.add("docs")
|
162
|
-
@mr.inputs.
|
162
|
+
expect(@mr.inputs).to eq("docs")
|
163
163
|
end
|
164
164
|
end
|
165
165
|
end
|
@@ -170,31 +170,31 @@ describe Riak::MapReduce do
|
|
170
170
|
|
171
171
|
it "should add bucket/key pairs to the inputs with bucket and key escaped" do
|
172
172
|
@mr.add("[foo]","(bar)")
|
173
|
-
@mr.inputs.
|
173
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D","%28bar%29"]])
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should add an escaped array containing a bucket/key pair to the inputs" do
|
177
177
|
@mr.add(["[foo]","(bar)"])
|
178
|
-
@mr.inputs.
|
178
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D","%28bar%29"]])
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should add an object to the inputs by its escaped bucket and key" do
|
182
182
|
bucket = Riak::Bucket.new(@client, "[foo]")
|
183
183
|
obj = Riak::RObject.new(bucket, "(bar)")
|
184
184
|
@mr.add(obj)
|
185
|
-
@mr.inputs.
|
185
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29"]])
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should add an escaped array containing a bucket/key/key-data triple to the inputs" do
|
189
189
|
@mr.add(["[foo]","(bar)","[]()"])
|
190
|
-
@mr.inputs.
|
190
|
+
expect(@mr.inputs).to eq([["%5Bfoo%5D", "%28bar%29","[]()"]])
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should use an escaped bucket name as the single input" do
|
194
194
|
@mr.add(Riak::Bucket.new(@client, "[foo]"))
|
195
|
-
@mr.inputs.
|
195
|
+
expect(@mr.inputs).to eq("%5Bfoo%5D")
|
196
196
|
@mr.add("docs")
|
197
|
-
@mr.inputs.
|
197
|
+
expect(@mr.inputs).to eq("docs")
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
@@ -203,13 +203,13 @@ describe Riak::MapReduce do
|
|
203
203
|
after { Riak.disable_list_keys_warnings = true }
|
204
204
|
|
205
205
|
it "should warn about list-keys on buckets" do
|
206
|
-
@mr.
|
206
|
+
expect(@mr).to receive(:warn).twice
|
207
207
|
@mr.add("foo")
|
208
208
|
@mr.add(Riak::Bucket.new(@client, "foo"))
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should warn about list-keys on key-filters" do
|
212
|
-
@mr.
|
212
|
+
expect(@mr).to receive(:warn)
|
213
213
|
@mr.filter("foo") { matches "bar" }
|
214
214
|
end
|
215
215
|
end
|
@@ -218,111 +218,111 @@ describe Riak::MapReduce do
|
|
218
218
|
[:map, :reduce].each do |type|
|
219
219
|
describe "adding #{type} phases" do
|
220
220
|
it "should return self for chaining" do
|
221
|
-
@mr.send(type, "function(){}").
|
221
|
+
expect(@mr.send(type, "function(){}")).to eq(@mr)
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should accept a function string" do
|
225
225
|
@mr.send(type, "function(){}")
|
226
|
-
@mr.query.
|
226
|
+
expect(@mr.query.size).to eq(1)
|
227
227
|
phase = @mr.query.first
|
228
|
-
phase.function.
|
229
|
-
phase.type.
|
228
|
+
expect(phase.function).to eq("function(){}")
|
229
|
+
expect(phase.type).to eq(type)
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should accept a function and options" do
|
233
233
|
@mr.send(type, "function(){}", :keep => true)
|
234
|
-
@mr.query.
|
234
|
+
expect(@mr.query.size).to eq(1)
|
235
235
|
phase = @mr.query.first
|
236
|
-
phase.function.
|
237
|
-
phase.type.
|
238
|
-
phase.keep.
|
236
|
+
expect(phase.function).to eq("function(){}")
|
237
|
+
expect(phase.type).to eq(type)
|
238
|
+
expect(phase.keep).to be_truthy
|
239
239
|
end
|
240
240
|
|
241
241
|
it "should accept a module/function pair" do
|
242
242
|
@mr.send(type, ["riak","mapsomething"])
|
243
|
-
@mr.query.
|
243
|
+
expect(@mr.query.size).to eq(1)
|
244
244
|
phase = @mr.query.first
|
245
|
-
phase.function.
|
246
|
-
phase.type.
|
247
|
-
phase.language.
|
245
|
+
expect(phase.function).to eq(["riak", "mapsomething"])
|
246
|
+
expect(phase.type).to eq(type)
|
247
|
+
expect(phase.language).to eq("erlang")
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should accept a module/function pair with extra options" do
|
251
251
|
@mr.send(type, ["riak", "mapsomething"], :arg => [1000])
|
252
|
-
@mr.query.
|
252
|
+
expect(@mr.query.size).to eq(1)
|
253
253
|
phase = @mr.query.first
|
254
|
-
phase.function.
|
255
|
-
phase.type.
|
256
|
-
phase.language.
|
257
|
-
phase.arg.
|
254
|
+
expect(phase.function).to eq(["riak", "mapsomething"])
|
255
|
+
expect(phase.type).to eq(type)
|
256
|
+
expect(phase.language).to eq("erlang")
|
257
|
+
expect(phase.arg).to eq([1000])
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
262
|
describe "adding link phases" do
|
263
263
|
it "should return self for chaining" do
|
264
|
-
@mr.link({}).
|
264
|
+
expect(@mr.link({})).to eq(@mr)
|
265
265
|
end
|
266
266
|
|
267
267
|
it "should accept a WalkSpec" do
|
268
268
|
@mr.link(Riak::WalkSpec.new(:tag => "next"))
|
269
|
-
@mr.query.
|
269
|
+
expect(@mr.query.size).to eq(1)
|
270
270
|
phase = @mr.query.first
|
271
|
-
phase.type.
|
272
|
-
phase.function.
|
273
|
-
phase.function.tag.
|
271
|
+
expect(phase.type).to eq(:link)
|
272
|
+
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
273
|
+
expect(phase.function.tag).to eq("next")
|
274
274
|
end
|
275
275
|
|
276
276
|
it "should accept a WalkSpec and a hash of options" do
|
277
277
|
@mr.link(Riak::WalkSpec.new(:bucket => "foo"), :keep => true)
|
278
|
-
@mr.query.
|
278
|
+
expect(@mr.query.size).to eq(1)
|
279
279
|
phase = @mr.query.first
|
280
|
-
phase.type.
|
281
|
-
phase.function.
|
282
|
-
phase.function.bucket.
|
283
|
-
phase.keep.
|
280
|
+
expect(phase.type).to eq(:link)
|
281
|
+
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
282
|
+
expect(phase.function.bucket).to eq("foo")
|
283
|
+
expect(phase.keep).to be_truthy
|
284
284
|
end
|
285
285
|
|
286
286
|
it "should accept a hash of options intermingled with the walk spec options" do
|
287
287
|
@mr.link(:tag => "snakes", :arg => [1000])
|
288
|
-
@mr.query.
|
288
|
+
expect(@mr.query.size).to eq(1)
|
289
289
|
phase = @mr.query.first
|
290
|
-
phase.arg.
|
291
|
-
phase.function.
|
292
|
-
phase.function.tag.
|
290
|
+
expect(phase.arg).to eq([1000])
|
291
|
+
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
292
|
+
expect(phase.function.tag).to eq("snakes")
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
296
|
describe "converting to JSON for the job" do
|
297
297
|
it "should include the inputs and query keys" do
|
298
|
-
@mr.to_json.
|
298
|
+
expect(@mr.to_json).to match(/"inputs":/)
|
299
299
|
end
|
300
300
|
|
301
301
|
it "should map phases to their JSON equivalents" do
|
302
302
|
phase = Riak::MapReduce::Phase.new(:type => :map, :function => "function(){}")
|
303
303
|
@mr.query << phase
|
304
|
-
@mr.to_json.
|
305
|
-
@mr.to_json.
|
304
|
+
expect(@mr.to_json).to include('"source":"function(){}"')
|
305
|
+
expect(@mr.to_json).to include('"query":[{"map":{')
|
306
306
|
end
|
307
307
|
|
308
308
|
it "should emit only the bucket name when the input is the whole bucket" do
|
309
309
|
@mr.add("foo")
|
310
|
-
@mr.to_json.
|
310
|
+
expect(@mr.to_json).to include('"inputs":"foo"')
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should emit an array of inputs when there are multiple inputs" do
|
314
314
|
@mr.add("foo","bar",1000).add("foo","baz")
|
315
|
-
@mr.to_json.
|
315
|
+
expect(@mr.to_json).to include('"inputs":[["foo","bar",1000],["foo","baz"]]')
|
316
316
|
end
|
317
317
|
|
318
318
|
it "should add the timeout value when set" do
|
319
319
|
@mr.timeout(50000)
|
320
|
-
@mr.to_json.
|
320
|
+
expect(@mr.to_json).to include('"timeout":50000')
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should return self from setting the timeout" do
|
325
|
-
@mr.timeout(5000).
|
325
|
+
expect(@mr.timeout(5000)).to eq(@mr)
|
326
326
|
end
|
327
327
|
|
328
328
|
describe "executing the map reduce job" do
|
@@ -331,32 +331,34 @@ describe Riak::MapReduce do
|
|
331
331
|
end
|
332
332
|
|
333
333
|
it "should submit the query to the backend" do
|
334
|
-
@backend.
|
335
|
-
@mr.run.
|
334
|
+
expect(@backend).to receive(:mapred).with(@mr).and_return([])
|
335
|
+
expect(@mr.run).to eq([])
|
336
336
|
end
|
337
337
|
|
338
338
|
it "should pass the given block to the backend for streaming" do
|
339
339
|
arr = []
|
340
|
-
@backend.
|
340
|
+
expect(@backend).to receive(:mapred).with(@mr).and_yield("foo").and_yield("bar")
|
341
341
|
@mr.run {|v| arr << v }
|
342
|
-
arr.
|
342
|
+
expect(arr).to eq(["foo", "bar"])
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should interpret failed requests with JSON content-types as map reduce errors" do
|
346
|
-
@backend.
|
347
|
-
|
346
|
+
allow(@backend).to receive(:mapred).
|
347
|
+
and_raise(Riak::ProtobuffsFailedRequest.new(:server_error, '{"error":"syntax error"}'))
|
348
|
+
expect{ @mr.run }.to raise_error(Riak::MapReduceError)
|
348
349
|
begin
|
349
350
|
@mr.run
|
350
351
|
rescue Riak::MapReduceError => mre
|
351
|
-
mre.message.
|
352
|
+
expect(mre.message).to include('{"error":"syntax error"}')
|
352
353
|
else
|
353
354
|
fail "No exception raised!"
|
354
355
|
end
|
355
356
|
end
|
356
357
|
|
357
358
|
it "should re-raise non-JSON error responses" do
|
358
|
-
@backend.
|
359
|
-
|
359
|
+
allow(@backend).to receive(:mapred).
|
360
|
+
and_raise(Riak::ProtobuffsFailedRequest.new(:server_error, 'Oops, you bwoke it.'))
|
361
|
+
expect { @mr.run }.to raise_error(Riak::FailedRequest)
|
360
362
|
end
|
361
363
|
end
|
362
364
|
end
|