riak-client 1.4.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/riak/search_spec.rb
CHANGED
@@ -5,148 +5,26 @@ describe "Search features" do
|
|
5
5
|
describe Riak::Client do
|
6
6
|
before :each do
|
7
7
|
@client = Riak::Client.new
|
8
|
-
@
|
9
|
-
@client.
|
8
|
+
@pb = double(Riak::Client::BeefcakeProtobuffsBackend)
|
9
|
+
allow(@client).to receive(:backend).and_yield(@pb)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "searching" do
|
13
13
|
it "should search the default index" do
|
14
|
-
@
|
14
|
+
expect(@pb).to receive(:search).with(nil, "foo", {}).and_return({})
|
15
15
|
@client.search("foo")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should search the default index with additional options" do
|
19
|
-
@
|
19
|
+
expect(@pb).to receive(:search).with(nil, 'foo', 'rows' => 30).and_return({})
|
20
20
|
@client.search("foo", 'rows' => 30)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should search the specified index" do
|
24
|
-
@
|
24
|
+
expect(@pb).to receive(:search).with('search', 'foo', {}).and_return({})
|
25
25
|
@client.search("search", "foo")
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
describe "indexing documents" do
|
30
|
-
it "should update the default index" do
|
31
|
-
doc = {'field' => "value", 'id' => 1}
|
32
|
-
expect_update_body do |body|
|
33
|
-
root = REXML::Document.new(body).root
|
34
|
-
root.name.should == 'add'
|
35
|
-
root.elements.should have(1).item
|
36
|
-
root.elements[1].each_element do |el|
|
37
|
-
case el.attributes['name']
|
38
|
-
when 'field'
|
39
|
-
el.text.should == 'value'
|
40
|
-
when 'id'
|
41
|
-
el.text.should == '1'
|
42
|
-
else
|
43
|
-
fail "Spurious element in #{root.elements[1]}! #{el}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
@client.index(doc)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should update the specified index" do
|
51
|
-
doc = {'field' => "value", 'id' => 1}
|
52
|
-
expect_update_body(nil, "foo") do |body|
|
53
|
-
root = REXML::Document.new(body).root
|
54
|
-
root.name.should == 'add'
|
55
|
-
root.elements.should have(1).item
|
56
|
-
root.elements[1].each_element do |el|
|
57
|
-
case el.attributes['name']
|
58
|
-
when 'field'
|
59
|
-
el.text.should == 'value'
|
60
|
-
when 'id'
|
61
|
-
el.text.should == '1'
|
62
|
-
else
|
63
|
-
fail "Spurious element in #{root.elements[1]}! #{el}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
@client.index("foo", doc)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should raise an error when documents do not contain an id" do
|
71
|
-
@http.stub!(:update_search_index).and_return(true)
|
72
|
-
lambda { @client.index({:field => "value"}) }.should raise_error(ArgumentError)
|
73
|
-
lambda { @client.index({:id => 1, :field => "value"}) }.should_not raise_error(ArgumentError)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should include multiple documents in the <add> request" do
|
77
|
-
docs = {'field' => "value", 'id' => 1}, {'foo' => "bar", 'id' => 2}
|
78
|
-
expect_update_body do |body|
|
79
|
-
root = REXML::Document.new(body).root
|
80
|
-
root.name.should == 'add'
|
81
|
-
docs = root.elements
|
82
|
-
docs.each do |d|
|
83
|
-
d.name.should == 'doc'
|
84
|
-
d.elements.size.should == 2
|
85
|
-
end
|
86
|
-
docs[1].each_element do |el|
|
87
|
-
case el.attributes['name']
|
88
|
-
when 'field'
|
89
|
-
el.text.should == 'value'
|
90
|
-
when 'id'
|
91
|
-
el.text.should == '1'
|
92
|
-
else
|
93
|
-
fail "Spurious element in #{docs[0]}! #{el}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
docs[2].each_element do |el|
|
97
|
-
case el.attributes['name']
|
98
|
-
when 'foo'
|
99
|
-
el.text.should == 'bar'
|
100
|
-
when 'id'
|
101
|
-
el.text.should == '2'
|
102
|
-
else
|
103
|
-
fail "Spurious element in #{docs[1]}! #{el}"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
@client.index(*docs)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "removing documents" do
|
112
|
-
it "should remove documents from the default index" do
|
113
|
-
expect_update_body('<delete><id>1</id></delete>')
|
114
|
-
@client.remove({:id => 1})
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should remove documents from the specified index" do
|
118
|
-
expect_update_body('<delete><id>1</id></delete>', 'foo')
|
119
|
-
@client.remove("foo", {:id => 1})
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should raise an error when document specifications don't include an id or query" do
|
123
|
-
@http.stub!(:update_search_index).and_return({:code => 200})
|
124
|
-
lambda { @client.remove({:foo => "bar"}) }.should raise_error(ArgumentError)
|
125
|
-
lambda { @client.remove({:id => 1}) }.should_not raise_error
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should build a Solr <delete> request" do
|
129
|
-
expect_update_body('<delete><id>1</id></delete>')
|
130
|
-
@client.remove(:id => 1)
|
131
|
-
expect_update_body('<delete><query>title:old</query></delete>')
|
132
|
-
@client.remove(:query => "title:old")
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should include multiple specs in the <delete> request" do
|
136
|
-
expect_update_body('<delete><id>1</id><query>title:old</query></delete>')
|
137
|
-
@client.remove({:id => 1}, {:query => "title:old"})
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def expect_update_body(body=nil, index=nil)
|
142
|
-
if block_given?
|
143
|
-
@http.should_receive(:update_search_index).with(index, kind_of(String)) do |i, b|
|
144
|
-
yield b
|
145
|
-
end
|
146
|
-
else
|
147
|
-
@http.should_receive(:update_search_index).with(index, body)
|
148
|
-
end
|
149
|
-
end
|
150
28
|
end
|
151
29
|
|
152
30
|
describe Riak::Bucket do
|
@@ -165,22 +43,22 @@ describe "Search features" do
|
|
165
43
|
|
166
44
|
it "should detect whether the indexing hook is installed" do
|
167
45
|
load_without_index_hook
|
168
|
-
@bucket.is_indexed
|
46
|
+
expect(@bucket.is_indexed?).to be_falsey
|
169
47
|
|
170
48
|
load_with_index_hook
|
171
|
-
@bucket.is_indexed
|
49
|
+
expect(@bucket.is_indexed?).to be_truthy
|
172
50
|
end
|
173
51
|
|
174
52
|
describe "enabling indexing" do
|
175
53
|
it "should add the index hook when not present" do
|
176
54
|
load_without_index_hook
|
177
|
-
@bucket.
|
55
|
+
expect(@bucket).to receive(:props=).with({"precommit" => [Riak::Bucket::SEARCH_PRECOMMIT_HOOK], "search" => true})
|
178
56
|
@bucket.enable_index!
|
179
57
|
end
|
180
58
|
|
181
59
|
it "should not modify the precommit when the hook is present" do
|
182
60
|
load_with_index_hook
|
183
|
-
@bucket.
|
61
|
+
expect(@bucket).not_to receive(:props=)
|
184
62
|
@bucket.enable_index!
|
185
63
|
end
|
186
64
|
end
|
@@ -188,13 +66,13 @@ describe "Search features" do
|
|
188
66
|
describe "disabling indexing" do
|
189
67
|
it "should remove the index hook when present" do
|
190
68
|
load_with_index_hook
|
191
|
-
@bucket.
|
69
|
+
expect(@bucket).to receive(:props=).with({"precommit" => [], "search" => false})
|
192
70
|
@bucket.disable_index!
|
193
71
|
end
|
194
72
|
|
195
73
|
it "should not modify the precommit when the hook is missing" do
|
196
74
|
load_without_index_hook
|
197
|
-
@bucket.
|
75
|
+
expect(@bucket).not_to receive(:props=)
|
198
76
|
@bucket.disable_index!
|
199
77
|
end
|
200
78
|
end
|
@@ -209,20 +87,20 @@ describe "Search features" do
|
|
209
87
|
describe "using a search query as inputs" do
|
210
88
|
it "should accept a bucket name and query" do
|
211
89
|
@mr.search("foo", "bar OR baz")
|
212
|
-
@mr.inputs.
|
90
|
+
expect(@mr.inputs).to eq({:module => "riak_search", :function => "mapred_search", :arg => ["foo", "bar OR baz"]})
|
213
91
|
end
|
214
92
|
|
215
93
|
it "should accept a Riak::Bucket and query" do
|
216
94
|
@mr.search(Riak::Bucket.new(@client, "foo"), "bar OR baz")
|
217
|
-
@mr.inputs.
|
95
|
+
expect(@mr.inputs).to eq({:module => "riak_search", :function => "mapred_search", :arg => ["foo", "bar OR baz"]})
|
218
96
|
end
|
219
97
|
|
220
98
|
it "should emit the Erlang function and arguments" do
|
221
99
|
@mr.search("foo", "bar OR baz")
|
222
|
-
@mr.to_json.
|
223
|
-
@mr.to_json.
|
224
|
-
@mr.to_json.
|
225
|
-
@mr.to_json.
|
100
|
+
expect(@mr.to_json).to include('"inputs":{')
|
101
|
+
expect(@mr.to_json).to include('"module":"riak_search"')
|
102
|
+
expect(@mr.to_json).to include('"function":"mapred_search"')
|
103
|
+
expect(@mr.to_json).to include('"arg":["foo","bar OR baz"]')
|
226
104
|
end
|
227
105
|
end
|
228
106
|
end
|
@@ -8,49 +8,49 @@ describe Riak::SecondaryIndex do
|
|
8
8
|
|
9
9
|
describe "initialization" do
|
10
10
|
it "should accept a bucket, index name, and scalar" do
|
11
|
-
|
12
|
-
|
11
|
+
expect { Riak::SecondaryIndex.new @bucket, 'asdf', 'aaaa' }.not_to raise_error
|
12
|
+
expect { Riak::SecondaryIndex.new @bucket, 'asdf', 12345 }.not_to raise_error
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should accept a bucket, index name, and a range" do
|
16
|
-
|
17
|
-
|
16
|
+
expect { Riak::SecondaryIndex.new @bucket, 'asdf', 'aaaa'..'zzzz' }.not_to raise_error
|
17
|
+
expect { Riak::SecondaryIndex.new @bucket, 'asdf', 1..5 }.not_to raise_error
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "operation" do
|
22
22
|
before(:each) do
|
23
|
-
@backend =
|
24
|
-
@client.
|
23
|
+
@backend = double 'Backend'
|
24
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
25
25
|
@args = [@bucket, 'asdf', 'aaaa'..'zzzz', {}]
|
26
26
|
@index = Riak::SecondaryIndex.new *@args
|
27
27
|
|
28
|
-
@backend.
|
28
|
+
expect(@backend).to receive(:get_index).with(*@args).and_return(%w{abcd efgh})
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should return an array of keys" do
|
32
32
|
@results = @index.keys
|
33
|
-
@results.
|
34
|
-
@results.first.
|
33
|
+
expect(@results).to be_a Array
|
34
|
+
expect(@results.first).to be_a String
|
35
35
|
end
|
36
36
|
it "should return an array of values" do
|
37
|
-
@backend.
|
38
|
-
@backend.
|
37
|
+
expect(@backend).to receive(:fetch_object).with(@bucket, 'abcd', {}).and_return('abcd')
|
38
|
+
expect(@backend).to receive(:fetch_object).with(@bucket, 'efgh', {}).and_return('efgh')
|
39
39
|
|
40
40
|
@results = @index.values
|
41
|
-
@results.
|
42
|
-
@results.length.
|
41
|
+
expect(@results).to be_a Array
|
42
|
+
expect(@results.length).to eq(2)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe "streaming" do
|
47
47
|
it "should stream keys into a block" do
|
48
|
-
@backend =
|
49
|
-
@client.
|
48
|
+
@backend = double 'Backend'
|
49
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
50
50
|
@args = [@bucket, 'asdf', 'aaaa'..'zzzz', {stream: true}]
|
51
51
|
@index = Riak::SecondaryIndex.new *@args
|
52
52
|
|
53
|
-
@backend.
|
53
|
+
expect(@backend).to receive(:get_index).with(*@args).and_yield('abcd').and_yield('efgh')
|
54
54
|
|
55
55
|
@index.keys {|b| :noop }
|
56
56
|
end
|
@@ -65,10 +65,10 @@ describe Riak::SecondaryIndex do
|
|
65
65
|
'continuation' => 'examplecontinuation'
|
66
66
|
}.to_json)
|
67
67
|
|
68
|
-
@backend =
|
69
|
-
@client.
|
70
|
-
@backend.
|
71
|
-
|
68
|
+
@backend = double 'Backend'
|
69
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
70
|
+
expect(@backend).
|
71
|
+
to receive(:get_index).
|
72
72
|
with(
|
73
73
|
@bucket,
|
74
74
|
'asdf',
|
@@ -76,7 +76,7 @@ describe Riak::SecondaryIndex do
|
|
76
76
|
:max_results => @max_results
|
77
77
|
).
|
78
78
|
and_return(@expected_collection)
|
79
|
-
@backend.
|
79
|
+
allow(@backend).to receive(:get_server_version).and_return('1.4.0')
|
80
80
|
|
81
81
|
|
82
82
|
@index = Riak::SecondaryIndex.new(
|
@@ -87,9 +87,9 @@ describe Riak::SecondaryIndex do
|
|
87
87
|
)
|
88
88
|
|
89
89
|
@results = @index.keys
|
90
|
-
@results.
|
91
|
-
@results.
|
92
|
-
@results.length.
|
90
|
+
expect(@results).to be_an Array
|
91
|
+
expect(@results).to eq(@expected_collection)
|
92
|
+
expect(@results.length).to eq(@max_results)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should support continuations" do
|
@@ -99,10 +99,10 @@ describe Riak::SecondaryIndex do
|
|
99
99
|
'keys' => %w{ffff gggg hhhh}
|
100
100
|
}.to_json)
|
101
101
|
|
102
|
-
@backend =
|
103
|
-
@client.
|
104
|
-
@backend.
|
105
|
-
|
102
|
+
@backend = double 'Backend'
|
103
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
104
|
+
expect(@backend).
|
105
|
+
to receive(:get_index).
|
106
106
|
with(
|
107
107
|
@bucket,
|
108
108
|
'asdf',
|
@@ -111,7 +111,7 @@ describe Riak::SecondaryIndex do
|
|
111
111
|
continuation: 'examplecontinuation'
|
112
112
|
).
|
113
113
|
and_return(@expected_collection)
|
114
|
-
@backend.
|
114
|
+
allow(@backend).to receive(:get_server_version).and_return('1.4.0')
|
115
115
|
|
116
116
|
|
117
117
|
@index = Riak::SecondaryIndex.new(
|
@@ -123,8 +123,8 @@ describe Riak::SecondaryIndex do
|
|
123
123
|
)
|
124
124
|
|
125
125
|
@results = @index.keys
|
126
|
-
@results.
|
127
|
-
@results.
|
126
|
+
expect(@results).to be_an Array
|
127
|
+
expect(@results).to eq(@expected_collection)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should support a next_page method" do
|
@@ -135,10 +135,10 @@ describe Riak::SecondaryIndex do
|
|
135
135
|
'continuation' => 'examplecontinuation'
|
136
136
|
}.to_json)
|
137
137
|
|
138
|
-
@backend =
|
139
|
-
@client.
|
140
|
-
@backend.
|
141
|
-
|
138
|
+
@backend = double 'Backend'
|
139
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
140
|
+
expect(@backend).
|
141
|
+
to receive(:get_index).
|
142
142
|
once.
|
143
143
|
with(
|
144
144
|
@bucket,
|
@@ -147,7 +147,7 @@ describe Riak::SecondaryIndex do
|
|
147
147
|
:max_results => @max_results
|
148
148
|
).
|
149
149
|
and_return(@expected_collection)
|
150
|
-
@backend.
|
150
|
+
allow(@backend).to receive(:get_server_version).and_return('1.4.0')
|
151
151
|
|
152
152
|
|
153
153
|
@index = Riak::SecondaryIndex.new(
|
@@ -158,13 +158,13 @@ describe Riak::SecondaryIndex do
|
|
158
158
|
)
|
159
159
|
|
160
160
|
@results = @index.keys
|
161
|
-
@results.
|
161
|
+
expect(@results).to eq(@expected_collection)
|
162
162
|
|
163
163
|
@second_collection = Riak::IndexCollection.new_from_json({
|
164
164
|
'keys' => %w{ffff gggg hhhh}
|
165
165
|
}.to_json)
|
166
|
-
@backend.
|
167
|
-
|
166
|
+
expect(@backend).
|
167
|
+
to receive(:get_index).
|
168
168
|
once.
|
169
169
|
with(
|
170
170
|
@bucket,
|
@@ -177,7 +177,7 @@ describe Riak::SecondaryIndex do
|
|
177
177
|
|
178
178
|
@second_page = @index.next_page
|
179
179
|
@second_results = @second_page.keys
|
180
|
-
@second_results.
|
180
|
+
expect(@second_results).to eq(@second_collection)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -192,10 +192,10 @@ describe Riak::SecondaryIndex do
|
|
192
192
|
}.to_json)
|
193
193
|
|
194
194
|
|
195
|
-
@backend =
|
196
|
-
@client.
|
197
|
-
@backend.
|
198
|
-
|
195
|
+
@backend = double 'Backend'
|
196
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
197
|
+
expect(@backend).
|
198
|
+
to receive(:get_index).
|
199
199
|
with(
|
200
200
|
@bucket,
|
201
201
|
'asdf',
|
@@ -203,7 +203,7 @@ describe Riak::SecondaryIndex do
|
|
203
203
|
:return_terms => true
|
204
204
|
).
|
205
205
|
and_return(@expected_collection)
|
206
|
-
@backend.
|
206
|
+
allow(@backend).to receive(:get_server_version).and_return('1.4.0')
|
207
207
|
|
208
208
|
|
209
209
|
@index = Riak::SecondaryIndex.new(
|
@@ -214,12 +214,12 @@ describe Riak::SecondaryIndex do
|
|
214
214
|
)
|
215
215
|
|
216
216
|
@results = @index.keys
|
217
|
-
@results.
|
218
|
-
@results.
|
219
|
-
@results.with_terms.
|
217
|
+
expect(@results).to be_an Array
|
218
|
+
expect(@results).to eq(@expected_collection)
|
219
|
+
expect(@results.with_terms).to eq({
|
220
220
|
'aaaa' => %w{aaaa},
|
221
221
|
'bbbb' => %w{bbbb bbbb2}
|
222
|
-
}
|
222
|
+
})
|
223
223
|
end
|
224
224
|
end
|
225
225
|
end
|
@@ -4,16 +4,16 @@ describe Riak::Serializers do
|
|
4
4
|
shared_examples_for "a serializer" do |type, deserialized, serialized|
|
5
5
|
context "for #{type}" do
|
6
6
|
it "serializes #{deserialized} to #{serialized}" do
|
7
|
-
described_class.serialize(type, deserialized).
|
7
|
+
expect(described_class.serialize(type, deserialized)).to eq(serialized)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "deserializes #{serialized} to #{deserialized}" do
|
11
|
-
described_class.deserialize(type, serialized).
|
11
|
+
expect(described_class.deserialize(type, serialized)).to eq(deserialized)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "round trips properly" do
|
15
15
|
str = described_class.serialize(type, deserialized)
|
16
|
-
described_class.deserialize(type, str).
|
16
|
+
expect(described_class.deserialize(type, str)).to eq(deserialized)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -28,17 +28,17 @@ describe Riak::Serializers do
|
|
28
28
|
|
29
29
|
%w[ serialize deserialize ].each do |meth|
|
30
30
|
describe ".#{meth}" do
|
31
|
-
it 'raises
|
31
|
+
it 'raises an IOError when given an unrecognized content type' do
|
32
32
|
expect {
|
33
33
|
described_class.send(meth, "application/unrecognized", "string")
|
34
|
-
}.to raise_error(
|
34
|
+
}.to raise_error(IOError)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "plain text serializer" do
|
40
40
|
it 'calls #to_s to convert the object to a string' do
|
41
|
-
described_class.serialize("text/plain", :a_string).
|
41
|
+
expect(described_class.serialize("text/plain", :a_string)).to eq("a_string")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -57,11 +57,11 @@ describe Riak::Serializers do
|
|
57
57
|
s = h.to_json(Riak.json_options)
|
58
58
|
expect {
|
59
59
|
described_class.serialize('application/json', h)
|
60
|
-
}.
|
60
|
+
}.to_not raise_error
|
61
61
|
|
62
62
|
expect {
|
63
63
|
described_class.deserialize('application/json', s)
|
64
|
-
}.
|
64
|
+
}.to_not raise_error
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -80,7 +80,7 @@ describe Riak::Serializers do
|
|
80
80
|
|
81
81
|
it 'can be registered' do
|
82
82
|
described_class['application/custom-type-1'] = custom_serializer
|
83
|
-
described_class['application/custom-type-1'].
|
83
|
+
expect(described_class['application/custom-type-1']).to be(custom_serializer)
|
84
84
|
# fail
|
85
85
|
end
|
86
86
|
|