riak-client-noenc 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +42 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Guardfile +20 -0
- data/LICENSE.md +16 -0
- data/README.markdown +640 -0
- data/RELEASE_NOTES.md +392 -0
- data/Rakefile +119 -0
- data/lib/riak.rb +22 -0
- data/lib/riak/bucket.rb +297 -0
- data/lib/riak/bucket_properties.rb +74 -0
- data/lib/riak/bucket_type.rb +77 -0
- data/lib/riak/bucket_typed/bucket.rb +121 -0
- data/lib/riak/client.rb +433 -0
- data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
- data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -0
- data/lib/riak/client/beefcake/crdt/set_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt_loader.rb +84 -0
- data/lib/riak/client/beefcake/crdt_operator.rb +223 -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 +89 -0
- data/lib/riak/client/beefcake/message_overlay.rb +87 -0
- data/lib/riak/client/beefcake/messages.rb +772 -0
- data/lib/riak/client/beefcake/object_methods.rb +112 -0
- data/lib/riak/client/beefcake/protocol.rb +105 -0
- data/lib/riak/client/beefcake/socket.rb +260 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +538 -0
- data/lib/riak/client/decaying.rb +36 -0
- data/lib/riak/client/feature_detection.rb +120 -0
- data/lib/riak/client/instrumentation.rb +19 -0
- data/lib/riak/client/node.rb +49 -0
- data/lib/riak/client/protobuffs_backend.rb +143 -0
- data/lib/riak/client/search.rb +27 -0
- data/lib/riak/client/yokozuna.rb +52 -0
- data/lib/riak/conflict.rb +13 -0
- data/lib/riak/core_ext.rb +7 -0
- data/lib/riak/core_ext/blank.rb +53 -0
- data/lib/riak/core_ext/deep_dup.rb +13 -0
- data/lib/riak/core_ext/extract_options.rb +7 -0
- data/lib/riak/core_ext/json.rb +15 -0
- data/lib/riak/core_ext/slice.rb +18 -0
- data/lib/riak/core_ext/stringify_keys.rb +10 -0
- data/lib/riak/core_ext/symbolize_keys.rb +10 -0
- data/lib/riak/core_ext/to_param.rb +31 -0
- data/lib/riak/counter.rb +101 -0
- data/lib/riak/crdt.rb +21 -0
- data/lib/riak/crdt/base.rb +183 -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 +82 -0
- data/lib/riak/crdt/inner_counter.rb +81 -0
- data/lib/riak/crdt/inner_flag.rb +42 -0
- data/lib/riak/crdt/inner_map.rb +75 -0
- data/lib/riak/crdt/inner_register.rb +26 -0
- data/lib/riak/crdt/inner_set.rb +102 -0
- data/lib/riak/crdt/map.rb +121 -0
- data/lib/riak/crdt/operation.rb +19 -0
- data/lib/riak/crdt/set.rb +166 -0
- data/lib/riak/crdt/typed_collection.rb +181 -0
- data/lib/riak/encoding.rb +6 -0
- data/lib/riak/errors/backend_creation.rb +9 -0
- data/lib/riak/errors/base.rb +9 -0
- data/lib/riak/errors/connection_error.rb +50 -0
- data/lib/riak/errors/crdt_error.rb +38 -0
- data/lib/riak/errors/failed_request.rb +58 -0
- data/lib/riak/errors/protobuffs_error.rb +11 -0
- data/lib/riak/errors/search_error.rb +35 -0
- data/lib/riak/i18n.rb +7 -0
- data/lib/riak/index_collection.rb +71 -0
- data/lib/riak/instrumentation.rb +6 -0
- data/lib/riak/json.rb +52 -0
- data/lib/riak/link.rb +96 -0
- data/lib/riak/list_buckets.rb +28 -0
- data/lib/riak/locale/en.yml +107 -0
- data/lib/riak/locale/fr.yml +51 -0
- data/lib/riak/map_reduce.rb +295 -0
- data/lib/riak/map_reduce/filter_builder.rb +103 -0
- data/lib/riak/map_reduce/phase.rb +98 -0
- data/lib/riak/map_reduce/results.rb +49 -0
- data/lib/riak/map_reduce_error.rb +7 -0
- data/lib/riak/multiget.rb +122 -0
- data/lib/riak/preflist_item.rb +7 -0
- data/lib/riak/rcontent.rb +173 -0
- data/lib/riak/robject.rb +222 -0
- data/lib/riak/search.rb +11 -0
- data/lib/riak/search/index.rb +87 -0
- data/lib/riak/search/query.rb +141 -0
- data/lib/riak/search/result_collection.rb +144 -0
- data/lib/riak/search/result_document.rb +129 -0
- data/lib/riak/search/schema.rb +65 -0
- data/lib/riak/secondary_index.rb +81 -0
- data/lib/riak/serializers.rb +73 -0
- data/lib/riak/stamp.rb +77 -0
- data/lib/riak/util/escape.rb +80 -0
- data/lib/riak/util/tcp_socket_extensions.rb +58 -0
- data/lib/riak/util/translation.rb +18 -0
- data/lib/riak/version.rb +3 -0
- data/lib/riak/walk_spec.rb +145 -0
- data/spec/failover/failover.rb +59 -0
- data/spec/fixtures/bitcask.txt +25 -0
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-basic-conflict.txt +15 -0
- data/spec/fixtures/multipart-blank.txt +7 -0
- data/spec/fixtures/multipart-mapreduce.txt +10 -0
- data/spec/fixtures/multipart-with-body.txt +16 -0
- data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
- data/spec/fixtures/server.cert.crt +15 -0
- data/spec/fixtures/server.cert.key +15 -0
- data/spec/fixtures/test.pem +1 -0
- data/spec/fixtures/yz_schema_template.xml +18 -0
- data/spec/integration/riak/bucket_types_spec.rb +270 -0
- data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
- data/spec/integration/riak/counters_spec.rb +36 -0
- data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
- data/spec/integration/riak/crdt_search_spec.rb +176 -0
- data/spec/integration/riak/crdt_spec.rb +250 -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/preflist_spec.rb +31 -0
- data/spec/integration/riak/properties_spec.rb +69 -0
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +33 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +40 -0
- data/spec/integration/riak/search_spec.rb +104 -0
- data/spec/integration/riak/secondary_index_spec.rb +72 -0
- data/spec/integration/riak/security_spec.rb +100 -0
- data/spec/integration/riak/threading_spec.rb +150 -0
- data/spec/integration/yokozuna/index_spec.rb +61 -0
- data/spec/integration/yokozuna/queries_spec.rb +115 -0
- data/spec/integration/yokozuna/schema_spec.rb +49 -0
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +162 -0
- data/spec/riak/bucket_properties_spec.rb +135 -0
- data/spec/riak/bucket_spec.rb +275 -0
- data/spec/riak/bucket_type_spec.rb +50 -0
- data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
- data/spec/riak/client_spec.rb +246 -0
- data/spec/riak/core_ext/to_param_spec.rb +15 -0
- data/spec/riak/counter_spec.rb +122 -0
- data/spec/riak/crdt/counter_spec.rb +55 -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 +78 -0
- data/spec/riak/crdt/set_spec.rb +61 -0
- data/spec/riak/crdt/shared_examples.rb +74 -0
- data/spec/riak/crdt/typed_collection_spec.rb +225 -0
- data/spec/riak/escape_spec.rb +72 -0
- data/spec/riak/feature_detection_spec.rb +77 -0
- data/spec/riak/index_collection_spec.rb +53 -0
- data/spec/riak/instrumentation_spec.rb +124 -0
- data/spec/riak/link_spec.rb +85 -0
- data/spec/riak/list_buckets_spec.rb +41 -0
- data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
- data/spec/riak/map_reduce/phase_spec.rb +142 -0
- data/spec/riak/map_reduce_spec.rb +434 -0
- data/spec/riak/multiget_spec.rb +81 -0
- data/spec/riak/node_spec.rb +26 -0
- data/spec/riak/robject_spec.rb +496 -0
- data/spec/riak/search/index_spec.rb +72 -0
- data/spec/riak/search/query_spec.rb +88 -0
- data/spec/riak/search/result_collection_spec.rb +89 -0
- data/spec/riak/search/result_document_spec.rb +106 -0
- data/spec/riak/search/schema_spec.rb +63 -0
- data/spec/riak/search_spec.rb +107 -0
- data/spec/riak/secondary_index_spec.rb +225 -0
- data/spec/riak/serializers_spec.rb +121 -0
- data/spec/riak/stamp_spec.rb +54 -0
- data/spec/riak/walk_spec_spec.rb +203 -0
- data/spec/spec_helper.rb +66 -0
- data/spec/support/certs/README.md +13 -0
- data/spec/support/certs/ca.crt +21 -0
- data/spec/support/certs/client.crl +13 -0
- data/spec/support/certs/client.crt +94 -0
- data/spec/support/certs/client.csr +18 -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 +94 -0
- data/spec/support/certs/server.key +27 -0
- data/spec/support/crdt_search_config.rb +112 -0
- data/spec/support/crdt_search_fixtures.rb +42 -0
- data/spec/support/integration_setup.rb +10 -0
- data/spec/support/search_config.rb +83 -0
- data/spec/support/search_corpus_setup.rb +39 -0
- data/spec/support/test_client.rb +46 -0
- data/spec/support/test_client.yml.example +10 -0
- data/spec/support/unified_backend_examples.rb +380 -0
- data/spec/support/version_filter.rb +12 -0
- data/spec/support/wait_until.rb +20 -0
- metadata +511 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::IndexCollection do
|
4
|
+
describe "json initialization" do
|
5
|
+
it "accepts a list of keys" do
|
6
|
+
@input = {
|
7
|
+
'keys' => %w{first second third}
|
8
|
+
}.to_json
|
9
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
10
|
+
expect(%w{first second third}).to eq(@coll)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "accepts a list of keys and a continuation" do
|
14
|
+
@input = {
|
15
|
+
'keys' => %w{first second third},
|
16
|
+
'continuation' => 'examplecontinuation'
|
17
|
+
}.to_json
|
18
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
19
|
+
expect(%w{first second third}).to eq(@coll)
|
20
|
+
expect(@coll.continuation).to eq('examplecontinuation')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "accepts a list of results hashes" do
|
24
|
+
@input = {
|
25
|
+
'results' => [
|
26
|
+
{'first' => 'first'},
|
27
|
+
{'second' => 'second'},
|
28
|
+
{'second' => 'other'}
|
29
|
+
]
|
30
|
+
}.to_json
|
31
|
+
|
32
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
33
|
+
expect(%w{first second other}).to eq(@coll)
|
34
|
+
expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "accepts a list of results hashes and a continuation" do
|
38
|
+
@input = {
|
39
|
+
'results' => [
|
40
|
+
{'first' => 'first'},
|
41
|
+
{'second' => 'second'},
|
42
|
+
{'second' => 'other'}
|
43
|
+
],
|
44
|
+
'continuation' => 'examplecontinuation'
|
45
|
+
}.to_json
|
46
|
+
|
47
|
+
expect { @coll = Riak::IndexCollection.new_from_json @input }.not_to raise_error
|
48
|
+
expect(%w{first second other}).to eq(@coll)
|
49
|
+
expect(@coll.continuation).to eq('examplecontinuation')
|
50
|
+
expect({'first' => %w{first}, 'second' => %w{second other}}).to eq(@coll.with_terms)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = Riak::Client.new
|
7
|
+
@backend = double("Backend")
|
8
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
9
|
+
allow(@client).to receive(:http).and_yield(@backend)
|
10
|
+
@bucket = Riak::Bucket.new(@client, "foo")
|
11
|
+
|
12
|
+
@events = []
|
13
|
+
@notifier = ActiveSupport::Notifications.notifier
|
14
|
+
@notifier.subscribe { |*args| (@events ||= []) << event(*args) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "instrumentation", instrumentation: true do
|
18
|
+
|
19
|
+
it "should notify on the 'buckets' operation" do
|
20
|
+
expect(@backend).to receive(:list_buckets).and_return(%w{test test2})
|
21
|
+
test_client_event(@client, 'riak.list_buckets') do
|
22
|
+
@client.buckets
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should notify on the 'list_buckets' operation" do
|
27
|
+
expect(@backend).to receive(:list_buckets).and_return(%w{test test2})
|
28
|
+
test_client_event(@client, 'riak.list_buckets') do
|
29
|
+
@client.list_buckets
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should notify on the 'list_keys' operation" do
|
34
|
+
expect(@backend).to receive(:list_keys).and_return(%w{test test2})
|
35
|
+
test_client_event(@client, 'riak.list_keys') do
|
36
|
+
@client.list_keys(@bucket)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should notify on the 'get_bucket_props' operation" do
|
41
|
+
expect(@backend).to receive(:get_bucket_props).and_return({})
|
42
|
+
test_client_event(@client, 'riak.get_bucket_props') do
|
43
|
+
@client.get_bucket_props(@bucket)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should notify on the 'set_bucket_props' operation" do
|
48
|
+
expect(@backend).to receive(:set_bucket_props).and_return({})
|
49
|
+
test_client_event(@client, 'riak.set_bucket_props') do
|
50
|
+
@client.set_bucket_props(@bucket, {})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should notify on the 'clear_bucket_props' operation" do
|
55
|
+
expect(@backend).to receive(:reset_bucket_props).and_return({})
|
56
|
+
test_client_event(@client, 'riak.clear_bucket_props') do
|
57
|
+
@client.clear_bucket_props(@bucket)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should notify on the 'get_index' operation" do
|
62
|
+
expect(@backend).to receive(:get_index).and_return({})
|
63
|
+
test_client_event(@client, 'riak.get_index') do
|
64
|
+
@client.get_index(@bucket, 'index', 'query', {})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should notify on the 'get_object' operation" do
|
69
|
+
expect(@backend).to receive(:fetch_object).and_return(nil)
|
70
|
+
test_client_event(@client, 'riak.get_object') do
|
71
|
+
@client.get_object(@bucket, 'bar')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should notify on the 'store_object' operation" do
|
76
|
+
expect(@backend).to receive(:store_object).and_return(nil)
|
77
|
+
test_client_event(@client, 'riak.store_object') do
|
78
|
+
@client.store_object(Object.new)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should notify on the 'reload_object' operation" do
|
83
|
+
expect(@backend).to receive(:reload_object).and_return(nil)
|
84
|
+
test_client_event(@client, 'riak.reload_object') do
|
85
|
+
@client.reload_object(Object.new)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should notify on the 'delete_object' operation" do
|
90
|
+
expect(@backend).to receive(:delete_object).and_return(nil)
|
91
|
+
test_client_event(@client, 'riak.delete_object') do
|
92
|
+
@client.delete_object(@bucket, 'bar')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should notify on the 'mapred' operation" do
|
97
|
+
@mapred = Riak::MapReduce.new(@client).add('test').map("function(){}").map("function(){}")
|
98
|
+
expect(@backend).to receive(:mapred).and_return(nil)
|
99
|
+
test_client_event(@client, 'riak.map_reduce') do
|
100
|
+
@client.mapred(@mapred)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should notify on the 'ping' operation" do
|
105
|
+
expect(@backend).to receive(:ping).and_return(nil)
|
106
|
+
test_client_event(@client, 'riak.ping') do
|
107
|
+
@client.ping
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_client_event(client, event_name, &block)
|
114
|
+
block.call
|
115
|
+
expect(@events.size).to eql(1)
|
116
|
+
event = @events.first
|
117
|
+
expect(event.name).to eql(event_name)
|
118
|
+
expect(event.payload[:client_id]).to eql(client.client_id)
|
119
|
+
end
|
120
|
+
|
121
|
+
# name, start, finish, id, payload
|
122
|
+
def event(*args)
|
123
|
+
ActiveSupport::Notifications::Event.new(*args)
|
124
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Link do
|
4
|
+
describe "parsing a link header" do
|
5
|
+
it "creates Link objects from the data" do
|
6
|
+
result = Riak::Link.parse('</riak/foo/bar>; rel="tag", </riak/foo>; rel="up"')
|
7
|
+
expect(result).to be_kind_of(Array)
|
8
|
+
expect(result).to be_all {|i| Riak::Link === i }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "sets the bucket, key, url and rel parameters properly" do
|
12
|
+
result = Riak::Link.parse('</riak/foo/bar>; riaktag="tag", </riak/foo>; rel="up"')
|
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
|
+
end
|
22
|
+
|
23
|
+
it "keeps the url intact if it does not point to a bucket or bucket/key" do
|
24
|
+
result = Riak::Link.parse('</mapred>; rel="riak_kv_wm_mapred"')
|
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
|
+
end
|
29
|
+
|
30
|
+
it "parses the Riak 1.0 URL scheme" do
|
31
|
+
result = Riak::Link.parse('</buckets/b/keys/k>; riaktag="tag"').first
|
32
|
+
expect(result.bucket).to eq('b')
|
33
|
+
expect(result.key).to eq('k')
|
34
|
+
expect(result.tag).to eq('tag')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "converting to a string" do
|
39
|
+
it "to a string appropriate for use in the Link header" do
|
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
|
+
end
|
44
|
+
|
45
|
+
it "converts to a string using the new URL scheme" do
|
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
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "converts to a walk spec when pointing to an object" do
|
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
|
+
end
|
55
|
+
|
56
|
+
it "is equivalent to a link with the same url and rel" do
|
57
|
+
one = Riak::Link.new("/riak/foo/bar", "next")
|
58
|
+
two = Riak::Link.new("/riak/foo/bar", "next")
|
59
|
+
expect(one).to eq(two)
|
60
|
+
expect([one]).to include(two)
|
61
|
+
expect([two]).to include(one)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "unescapes the bucket name" do
|
65
|
+
expect(Riak::Link.new("/riak/bucket%20spaces/key", "foo").bucket).to eq("bucket spaces")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "unescapes the key name" do
|
69
|
+
expect(Riak::Link.new("/riak/bucket/key%2Fname", "foo").key).to eq("key/name")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "doesn't rely on the prefix to equal /riak/ when extracting the bucket and key" do
|
73
|
+
link = Riak::Link.new("/raw/bucket/key", "foo")
|
74
|
+
expect(link.bucket).to eq("bucket")
|
75
|
+
expect(link.key).to eq("key")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "constructs from bucket, key and tag" do
|
79
|
+
link = Riak::Link.new("bucket", "key", "tag")
|
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
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::ListBuckets do
|
4
|
+
before :each do
|
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
|
+
|
10
|
+
@expect_list = expect(@backend).to receive(:list_buckets)
|
11
|
+
|
12
|
+
@client.instance_variable_set :@protobuffs_pool, @fake_pool
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "non-streaming" do
|
16
|
+
it 'calls the backend without a block' do
|
17
|
+
@expect_list.with({}).and_return(%w{a b c d})
|
18
|
+
|
19
|
+
@client.list_buckets
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "streaming" do
|
24
|
+
it 'calls the backend with a block' do
|
25
|
+
@expect_list.
|
26
|
+
and_yield(%w{abc abd abe}).
|
27
|
+
and_yield(%w{bbb ccc ddd})
|
28
|
+
|
29
|
+
@yielded = []
|
30
|
+
|
31
|
+
@client.list_buckets do |bucket|
|
32
|
+
@yielded << bucket
|
33
|
+
end
|
34
|
+
|
35
|
+
@yielded.each do |b|
|
36
|
+
expect(b).to be_a Riak::Bucket
|
37
|
+
end
|
38
|
+
expect(@yielded.map(&:name)).to eq(%w{abc abd abe bbb ccc ddd})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::MapReduce::FilterBuilder do
|
4
|
+
subject { Riak::MapReduce::FilterBuilder.new }
|
5
|
+
it "evaluates the passed block on initialization" do
|
6
|
+
expect(subject.class.new do
|
7
|
+
matches "foo"
|
8
|
+
end.to_a).to eq([[:matches, "foo"]])
|
9
|
+
end
|
10
|
+
|
11
|
+
it "adds filters to the list" do
|
12
|
+
subject.to_lower
|
13
|
+
subject.similar_to("ripple", 3)
|
14
|
+
expect(subject.to_a).to eq([[:to_lower], [:similar_to, "ripple", 3]])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "adds a logical operation with a block" do
|
18
|
+
subject.OR do
|
19
|
+
starts_with "foo"
|
20
|
+
ends_with "bar"
|
21
|
+
end
|
22
|
+
expect(subject.to_a).to eq([[:or, [[:starts_with, "foo"], [:ends_with, "bar"]]]])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises an error on a filter arity mismatch" do
|
26
|
+
expect { subject.less_than }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an error when a block is not given to a logical operation" do
|
30
|
+
expect { subject._or }.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::MapReduce::Phase do
|
4
|
+
before :each do
|
5
|
+
@js_fun = "function(v,_,_){ return v['values'][0]['data']; }"
|
6
|
+
@erl_fun = "fun(Obj, _KeyData, _Arg) -> [{riak_object:key(Obj), riak_object:get_value(Obj)}] end."
|
7
|
+
end
|
8
|
+
|
9
|
+
it "initializes with a type and a function" do
|
10
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun, :language => "javascript")
|
11
|
+
expect(phase.type).to eq(:map)
|
12
|
+
expect(phase.function).to eq(@js_fun)
|
13
|
+
expect(phase.language).to eq("javascript")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "initializes with a type and an MF" do
|
17
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => %w(module function), :language => "erlang")
|
18
|
+
expect(phase.type).to eq(:map)
|
19
|
+
expect(phase.function).to eq(%w(module function))
|
20
|
+
expect(phase.language).to eq("erlang")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "initializes with a type and a bucket/key" do
|
24
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "funs", :key => "awesome_map"}, :language => "javascript")
|
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
|
+
end
|
29
|
+
|
30
|
+
it "assumes the language is erlang when the function is an array" do
|
31
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => %w(module function))
|
32
|
+
expect(phase.language).to eq("erlang")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "assumes the language is javascript when the function is a string and starts with function" do
|
36
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @js_fun)
|
37
|
+
expect(phase.language).to eq("javascript")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "assumes the language is erlang when the function is a string and starts with anon fun" do
|
41
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => @erl_fun)
|
42
|
+
expect(phase.language).to eq("erlang")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "assumes the language is javascript when the function is a hash" do
|
46
|
+
phase = Riak::MapReduce::Phase.new(:type => :map, :function => {:bucket => "jobs", :key => "awesome_map"})
|
47
|
+
expect(phase.language).to eq("javascript")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "accepts a WalkSpec for the function when a link phase" do
|
51
|
+
phase = Riak::MapReduce::Phase.new(:type => :link, :function => Riak::WalkSpec.new({}))
|
52
|
+
expect(phase.function).to be_kind_of(Riak::WalkSpec)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises an error if a WalkSpec is given for a phase type other than :link" do
|
56
|
+
expect { Riak::MapReduce::Phase.new(:type => :map, :function => Riak::WalkSpec.new({})) }.to raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "converting to JSON for the job" do
|
60
|
+
before :each do
|
61
|
+
@phase = Riak::MapReduce::Phase.new(:type => :map, :function => "")
|
62
|
+
end
|
63
|
+
|
64
|
+
[:map, :reduce].each do |type|
|
65
|
+
describe "when a #{type} phase" do
|
66
|
+
before :each do
|
67
|
+
@phase.type = type
|
68
|
+
end
|
69
|
+
|
70
|
+
it "is an object with a single key of '#{type}'" do
|
71
|
+
expect(@phase.to_json).to match(/^\{"#{type}":/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "includes the language" do
|
75
|
+
expect(@phase.to_json).to match(/"language":/)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "includes the keep value" do
|
79
|
+
expect(@phase.to_json).to match(/"keep":false/)
|
80
|
+
@phase.keep = true
|
81
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "includes the function source when the function is a source string" do
|
85
|
+
@phase.function = "function(v,_,_){ return v; }"
|
86
|
+
expect(@phase.to_json).to include(@phase.function)
|
87
|
+
expect(@phase.to_json).to match(/"source":/)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "includes the function name when the function is not a lambda" do
|
91
|
+
@phase.function = "Riak.mapValues"
|
92
|
+
expect(@phase.to_json).to include('"name":"Riak.mapValues"')
|
93
|
+
expect(@phase.to_json).not_to include('"source"')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "includes the bucket and key when referring to a stored function" do
|
97
|
+
@phase.function = {:bucket => "design", :key => "wordcount_map"}
|
98
|
+
expect(@phase.to_json).to include('"bucket":"design"')
|
99
|
+
expect(@phase.to_json).to include('"key":"wordcount_map"')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "includes the module and function when invoking an Erlang function" do
|
103
|
+
@phase.function = %w(riak_mapreduce mapreduce_fun)
|
104
|
+
expect(@phase.to_json).to include('"module":"riak_mapreduce"')
|
105
|
+
expect(@phase.to_json).to include('"function":"mapreduce_fun"')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "when a link phase" do
|
111
|
+
before :each do
|
112
|
+
@phase.type = :link
|
113
|
+
@phase.function = {}
|
114
|
+
end
|
115
|
+
|
116
|
+
it "is an object of a single key 'link'" do
|
117
|
+
expect(@phase.to_json).to match(/^\{"link":/)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "includes the bucket" do
|
121
|
+
expect(@phase.to_json).to match(/"bucket":"_"/)
|
122
|
+
@phase.function[:bucket] = "foo"
|
123
|
+
expect(@phase.to_json).to match(/"bucket":"foo"/)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "includes the tag" do
|
127
|
+
expect(@phase.to_json).to match(/"tag":"_"/)
|
128
|
+
@phase.function[:tag] = "parent"
|
129
|
+
expect(@phase.to_json).to match(/"tag":"parent"/)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "includes the keep value" do
|
133
|
+
expect(@phase.to_json).to match(/"keep":false/)
|
134
|
+
@phase.keep = true
|
135
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
136
|
+
@phase.keep = false
|
137
|
+
@phase.function[:keep] = true
|
138
|
+
expect(@phase.to_json).to match(/"keep":true/)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|