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,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Client::Node do
|
4
|
+
before :each do
|
5
|
+
@client = Riak::Client.new
|
6
|
+
@node = Riak::Client::Node.new @client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'when initializing' do
|
10
|
+
it 'defaults to the local interface on port 8087' do
|
11
|
+
node = Riak::Client::Node.new @client
|
12
|
+
expect(node.host).to eq('127.0.0.1')
|
13
|
+
expect(node.pb_port).to eq(8087)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts a host' do
|
17
|
+
node = Riak::Client::Node.new(@client, :host => 'riak.basho.com')
|
18
|
+
expect(node.host).to eq("riak.basho.com")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'accepts a Protobuffs port' do
|
22
|
+
node = Riak::Client::Node.new @client, :pb_port => 9000
|
23
|
+
expect(node.pb_port).to eq(9000)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,496 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::RObject do
|
4
|
+
before :each do
|
5
|
+
@client = Riak::Client.new
|
6
|
+
@bucket = Riak::Bucket.new(@client, "foo")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "initialization" do
|
10
|
+
it "sets the bucket" do
|
11
|
+
@object = Riak::RObject.new(@bucket)
|
12
|
+
expect(@object.bucket).to eq(@bucket)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the key" do
|
16
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
17
|
+
expect(@object.key).to eq("bar")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "initializes the links to an empty set" do
|
21
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
22
|
+
expect(@object.links).to eq(Set.new)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "initializes the meta to an empty hash" do
|
26
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
27
|
+
expect(@object.meta).to eq({})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "initializes indexes to an empty hash with a Set for the default value" do
|
31
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
32
|
+
expect(@object.indexes).to be_kind_of(Hash)
|
33
|
+
expect(@object.indexes).to be_empty
|
34
|
+
expect(@object.indexes['foo_bin']).to be_kind_of(Set)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "yields itself to a given block" do
|
38
|
+
Riak::RObject.new(@bucket, "bar") do |r|
|
39
|
+
expect(r.key).to eq("bar")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "serialization" do
|
45
|
+
before :each do
|
46
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'delegates #serialize to the appropriate serializer for the content type' do
|
50
|
+
@object.content_type = 'text/plain'
|
51
|
+
expect(Riak::Serializers).to respond_to(:serialize).with(2).arguments
|
52
|
+
expect(Riak::Serializers).to receive(:serialize).with('text/plain', "foo").and_return("serialized foo")
|
53
|
+
expect(@object.content.serialize("foo")).to eq("serialized foo")
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'delegates #deserialize to the appropriate serializer for the content type' do
|
57
|
+
@object.content_type = 'text/plain'
|
58
|
+
expect(Riak::Serializers).to respond_to(:deserialize).with(2).arguments
|
59
|
+
expect(Riak::Serializers).to receive(:deserialize).with('text/plain', "foo").and_return("deserialized foo")
|
60
|
+
expect(@object.content.deserialize("foo")).to eq("deserialized foo")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "data access methods" do
|
65
|
+
before :each do
|
66
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
67
|
+
@object.content_type = "application/json"
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "for raw data" do
|
71
|
+
describe "when unserialized data was already provided" do
|
72
|
+
before do
|
73
|
+
@object.data = { 'some' => 'data' }
|
74
|
+
end
|
75
|
+
|
76
|
+
it "resets unserialized forms when stored" do
|
77
|
+
@object.raw_data = value = '{ "raw": "json" }'
|
78
|
+
|
79
|
+
expect(@object.raw_data).to eq(value)
|
80
|
+
expect(@object.data).to eq({ "raw" => "json" })
|
81
|
+
end
|
82
|
+
|
83
|
+
it "lazily serializes when read" do
|
84
|
+
expect(@object.raw_data).to eq('{"some":"data"}')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "only marshal/demarshals when necessary" do
|
89
|
+
expect(@object).not_to receive(:serialize)
|
90
|
+
expect(@object).not_to receive(:deserialize)
|
91
|
+
@object.raw_data = value = "{not even valid json!}}"
|
92
|
+
expect(@object.raw_data).to eq(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "for unserialized data" do
|
97
|
+
describe "when raw data was already provided" do
|
98
|
+
before do
|
99
|
+
@object.raw_data = '{"some":"data"}'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "resets previously stored raw data" do
|
103
|
+
@object.data = value = { "new" => "data" }
|
104
|
+
expect(@object.raw_data).to eq('{"new":"data"}')
|
105
|
+
expect(@object.data).to eq(value)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "lazily deserializes when read" do
|
109
|
+
expect(@object.data).to eq({ "some" => "data" })
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'for an IO-like object' do
|
113
|
+
let(:io_object) { double(:read => 'the io object') }
|
114
|
+
|
115
|
+
it 'reads the object before deserializing it' do
|
116
|
+
expect(@object.content).to receive(:deserialize).with('the io object').and_return('deserialized')
|
117
|
+
@object.raw_data = io_object
|
118
|
+
expect(@object.data).to eq('deserialized')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not allow it to be assigned directly to data' do
|
122
|
+
# it should be assigned to raw_data instead
|
123
|
+
expect {
|
124
|
+
@object.data = io_object
|
125
|
+
}.to raise_error(ArgumentError)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "only marshal/demarshals when necessary" do
|
131
|
+
expect(@object).not_to receive(:serialize)
|
132
|
+
expect(@object).not_to receive(:deserialize)
|
133
|
+
@object.data = value = { "some" => "data" }
|
134
|
+
expect(@object.data).to eq(value)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
describe "instantiating new object from a map reduce operation" do
|
141
|
+
before :each do
|
142
|
+
allow(@client).to receive(:[]).and_return(@bucket)
|
143
|
+
|
144
|
+
@sample_response = [
|
145
|
+
{"bucket"=>"users",
|
146
|
+
"key"=>"A2IbUQ2KEMbe4WGtdL97LoTi1DN%5B%28%5C%2F%29%5D",
|
147
|
+
"vclock"=> "a85hYGBgzmDKBVIsCfs+fc9gSN9wlA8q/hKosDpIOAsA",
|
148
|
+
"values"=> [
|
149
|
+
{"metadata"=>
|
150
|
+
{"Links"=>[%w(addresses A2cbUQ2KEMbeyWGtdz97LoTi1DN home_address)],
|
151
|
+
"X-Riak-VTag"=>"5bnavU3rrubcxLI8EvFXhB",
|
152
|
+
"content-type"=>"application/json",
|
153
|
+
"X-Riak-Last-Modified"=>"Mon, 12 Jul 2010 21:37:43 GMT",
|
154
|
+
"X-Riak-Meta"=>{"X-Riak-Meta-King-Of-Robots"=>"I"},
|
155
|
+
"index" => {
|
156
|
+
"email_bin" => ["sean@basho.com", "seancribbs@gmail.com"],
|
157
|
+
"rank_int" => 50
|
158
|
+
}
|
159
|
+
},
|
160
|
+
"data"=>
|
161
|
+
"{\"email\":\"mail@test.com\",\"_type\":\"User\"}"
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}
|
165
|
+
]
|
166
|
+
@object = Riak::RObject.load_from_mapreduce(@client, @sample_response).first
|
167
|
+
expect(@object).to be_kind_of(Riak::RObject)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "loads the content type" do
|
171
|
+
expect(@object.content_type).to eq("application/json")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "loads the body data" do
|
175
|
+
expect(@object.data).to be_present
|
176
|
+
end
|
177
|
+
|
178
|
+
it "deserializes the body data" do
|
179
|
+
expect(@object.data).to eq({"email" => "mail@test.com", "_type" => "User"})
|
180
|
+
end
|
181
|
+
|
182
|
+
it "sets the vclock" do
|
183
|
+
expect(@object.vclock).to eq("a85hYGBgzmDKBVIsCfs+fc9gSN9wlA8q/hKosDpIOAsA")
|
184
|
+
expect(@object.causal_context).to eq @object.vclock
|
185
|
+
end
|
186
|
+
|
187
|
+
it "loads and parse links" do
|
188
|
+
expect(@object.links.size).to eq(1)
|
189
|
+
expect(@object.links.first.url).to eq("/riak/addresses/A2cbUQ2KEMbeyWGtdz97LoTi1DN")
|
190
|
+
expect(@object.links.first.rel).to eq("home_address")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "loads and parse indexes" do
|
194
|
+
expect(@object.indexes.size).to eq(2)
|
195
|
+
expect(@object.indexes['email_bin'].size).to eq(2)
|
196
|
+
expect(@object.indexes['rank_int'].size).to eq(1)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "sets the ETag" do
|
200
|
+
expect(@object.etag).to eq("5bnavU3rrubcxLI8EvFXhB")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "sets modified date" do
|
204
|
+
expect(@object.last_modified.to_i).to eq(Time.httpdate("Mon, 12 Jul 2010 21:37:43 GMT").to_i)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "loads meta information" do
|
208
|
+
expect(@object.meta["King-Of-Robots"]).to eq(["I"])
|
209
|
+
end
|
210
|
+
|
211
|
+
it "sets the key" do
|
212
|
+
expect(@object.key).to eq("A2IbUQ2KEMbe4WGtdL97LoTi1DN[(\\/)]")
|
213
|
+
end
|
214
|
+
|
215
|
+
it "doesn't set conflict when there is none" do
|
216
|
+
expect(@object.conflict?).to be_falsey
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'returns [RContent] for siblings' do
|
220
|
+
expect(@object.siblings).to eq([@object.content])
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "when there are multiple values in an object" do
|
224
|
+
before :each do
|
225
|
+
response = @sample_response.dup
|
226
|
+
response[0]['values'] << {
|
227
|
+
"metadata"=> {
|
228
|
+
"Links"=>[],
|
229
|
+
"X-Riak-VTag"=>"7jDZLdu0fIj2iRsjGD8qq8",
|
230
|
+
"content-type"=>"application/json",
|
231
|
+
"X-Riak-Last-Modified"=>"Mon, 14 Jul 2010 19:28:27 GMT",
|
232
|
+
"X-Riak-Meta"=>[]
|
233
|
+
},
|
234
|
+
"data"=> "{\"email\":\"mail@domain.com\",\"_type\":\"User\"}"
|
235
|
+
}
|
236
|
+
@object = Riak::RObject.load_from_mapreduce( @client, response ).first
|
237
|
+
end
|
238
|
+
|
239
|
+
it "exposes siblings" do
|
240
|
+
expect(@object.siblings.size).to eq(2)
|
241
|
+
expect(@object.siblings[0].etag).to eq("5bnavU3rrubcxLI8EvFXhB")
|
242
|
+
expect(@object.siblings[1].etag).to eq("7jDZLdu0fIj2iRsjGD8qq8")
|
243
|
+
end
|
244
|
+
|
245
|
+
it "raises the conflict? flag when in conflict" do
|
246
|
+
expect { @object.data }.to raise_error(Riak::Conflict)
|
247
|
+
expect(@object).to be_conflict
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
it "doesn't allow duplicate links" do
|
253
|
+
@object = Riak::RObject.new(@bucket, "foo")
|
254
|
+
@object.links << Riak::Link.new("/riak/foo/baz", "next")
|
255
|
+
@object.links << Riak::Link.new("/riak/foo/baz", "next")
|
256
|
+
expect(@object.links.length).to eq(1)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "allows mass-overwriting indexes while preserving default behavior" do
|
260
|
+
@object = described_class.new(@bucket, 'foo')
|
261
|
+
@object.indexes = {"ts_int" => [12345], "foo_bin" => "bar"}
|
262
|
+
expect(@object.indexes['ts_int']).to eq(Set.new([12345]))
|
263
|
+
expect(@object.indexes['foo_bin']).to eq(Set.new(["bar"]))
|
264
|
+
expect(@object.indexes['unset_bin']).to eq(Set.new)
|
265
|
+
end
|
266
|
+
|
267
|
+
describe "when storing the object normally" do
|
268
|
+
before :each do
|
269
|
+
@backend = double("Backend")
|
270
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
271
|
+
@object = Riak::RObject.new(@bucket)
|
272
|
+
@object.content_type = "text/plain"
|
273
|
+
@object.data = "This is some text."
|
274
|
+
# @headers = @object.store_headers
|
275
|
+
end
|
276
|
+
|
277
|
+
it "raises an error when the content_type is blank" do
|
278
|
+
expect do
|
279
|
+
@object.content_type = nil
|
280
|
+
@object.store
|
281
|
+
end.to raise_error(ArgumentError)
|
282
|
+
expect do
|
283
|
+
@object.content_type = ' '
|
284
|
+
@object.store
|
285
|
+
end.to raise_error(ArgumentError)
|
286
|
+
end
|
287
|
+
|
288
|
+
it "raises an error when given an empty string as key" do
|
289
|
+
expect do
|
290
|
+
@object.key = ''
|
291
|
+
@object.store
|
292
|
+
end.to raise_error(ArgumentError)
|
293
|
+
end
|
294
|
+
|
295
|
+
it "passes quorum parameters and returnbody to the backend" do
|
296
|
+
expect(@backend).to receive(:store_object).
|
297
|
+
with(@object,
|
298
|
+
returnbody: false,
|
299
|
+
w: 3,
|
300
|
+
dw: 2).
|
301
|
+
and_return(true)
|
302
|
+
@object.store(returnbody: false, w: 3, dw: 2)
|
303
|
+
end
|
304
|
+
|
305
|
+
it "raises an error if the object is in conflict" do
|
306
|
+
@object.siblings << Riak::RContent.new(@object)
|
307
|
+
expect { @object.store }.to raise_error(Riak::Conflict)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "when reloading the object" do
|
312
|
+
before :each do
|
313
|
+
@backend = double("Backend")
|
314
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
315
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
316
|
+
@object.vclock = "somereallylongstring"
|
317
|
+
end
|
318
|
+
|
319
|
+
it "returns without requesting if the key is blank" do
|
320
|
+
@object.key = nil
|
321
|
+
expect(@backend).not_to receive(:reload_object)
|
322
|
+
@object.reload
|
323
|
+
end
|
324
|
+
|
325
|
+
it "returns without requesting if the vclock is blank" do
|
326
|
+
@object.vclock = nil
|
327
|
+
expect(@backend).not_to receive(:reload_object)
|
328
|
+
@object.reload
|
329
|
+
end
|
330
|
+
|
331
|
+
it "reloads the object if the key is present" do
|
332
|
+
expect(@backend).to receive(:reload_object).with(@object, {}).and_return(@object)
|
333
|
+
@object.reload
|
334
|
+
end
|
335
|
+
|
336
|
+
it "passes the requested R quorum to the backend" do
|
337
|
+
expect(@backend).to receive(:reload_object).with(@object, :r => 2).and_return(@object)
|
338
|
+
@object.reload :r => 2
|
339
|
+
end
|
340
|
+
|
341
|
+
it "disables matching conditions if the key is present and the :force option is given" do
|
342
|
+
expect(@backend).to receive(:reload_object) do |obj, _|
|
343
|
+
expect(obj.etag).to be_nil
|
344
|
+
expect(obj.last_modified).to be_nil
|
345
|
+
obj
|
346
|
+
end
|
347
|
+
@object.reload :force => true
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
describe "when deleting" do
|
352
|
+
before :each do
|
353
|
+
@backend = double("Backend")
|
354
|
+
allow(@client).to receive(:backend).and_yield(@backend)
|
355
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
356
|
+
end
|
357
|
+
|
358
|
+
it "makes a DELETE request to the Riak server and freeze the object" do
|
359
|
+
expect(@backend).to receive(:delete_object).with(@bucket, "bar", {})
|
360
|
+
@object.delete
|
361
|
+
expect(@object).to be_frozen
|
362
|
+
end
|
363
|
+
|
364
|
+
it "does nothing when the key is blank" do
|
365
|
+
expect(@backend).not_to receive(:delete_object)
|
366
|
+
@object.key = nil
|
367
|
+
@object.delete
|
368
|
+
end
|
369
|
+
|
370
|
+
it "raises a failed request exception when the backend returns a server error" do
|
371
|
+
expect(@backend).to receive(:delete_object).
|
372
|
+
and_raise(Riak::ProtobuffsFailedRequest.new(:server_error, "server error"))
|
373
|
+
expect { @object.delete }.to raise_error(Riak::FailedRequest)
|
374
|
+
end
|
375
|
+
|
376
|
+
it "sends the vector clock to the backend if present" do
|
377
|
+
@object.vclock = "somevclock"
|
378
|
+
expect(@backend).to receive(:delete_object).with(@bucket, "bar", {:vclock => "somevclock"})
|
379
|
+
@object.delete
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
it "doesn't convert to link without a tag" do
|
384
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
385
|
+
expect { @object.to_link }.to raise_error
|
386
|
+
end
|
387
|
+
|
388
|
+
it "converts to a link having the same url and a supplied tag" do
|
389
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
390
|
+
expect(@object.to_link("next")).to eq(Riak::Link.new("/riak/foo/bar", "next"))
|
391
|
+
end
|
392
|
+
|
393
|
+
it "escapes the bucket and key when converting to a link" do
|
394
|
+
@object = Riak::RObject.new(@bucket, "deep/path")
|
395
|
+
expect(@bucket).to receive(:name).and_return("bucket spaces")
|
396
|
+
expect(@object.to_link("bar").url).to eq("/riak/bucket%20spaces/deep%2Fpath")
|
397
|
+
end
|
398
|
+
|
399
|
+
describe "#inspect" do
|
400
|
+
let(:object) { Riak::RObject.new(@bucket) }
|
401
|
+
|
402
|
+
it "provides useful output even when the key is nil" do
|
403
|
+
expect { object.inspect }.not_to raise_error
|
404
|
+
expect(object.inspect).to be_kind_of(String)
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'uses the serializer output in inspect' do
|
408
|
+
object.raw_data = { 'a' => 7 }
|
409
|
+
object.content_type = 'inspect/type'
|
410
|
+
Riak::Serializers['inspect/type'] = Object.new.tap do |o|
|
411
|
+
def o.load(object)
|
412
|
+
"serialize for inspect"
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
expect(object.inspect).to match(/serialize for inspect/)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe '.on_conflict' do
|
421
|
+
it 'adds the hook to the list of on conflict hooks' do
|
422
|
+
hook_run = false
|
423
|
+
expect(described_class.on_conflict_hooks).to be_empty
|
424
|
+
described_class.on_conflict { hook_run = true }
|
425
|
+
expect(described_class.on_conflict_hooks.size).to eq(1)
|
426
|
+
described_class.on_conflict_hooks.first.call
|
427
|
+
expect(hook_run).to eq(true)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe '#attempt_conflict_resolution' do
|
432
|
+
let(:conflicted_robject) do
|
433
|
+
Riak::RObject.new(@bucket, "conflicted") do |r|
|
434
|
+
r.siblings = [ Riak::RContent.new(r), Riak::RContent.new(r)]
|
435
|
+
end
|
436
|
+
end
|
437
|
+
let(:resolved_robject) { Riak::RObject.new(@bucket, "resolved") }
|
438
|
+
let(:invoked_resolvers) { [] }
|
439
|
+
let(:resolver_1) do
|
440
|
+
lambda do |r|
|
441
|
+
invoked_resolvers << :resolver_1
|
442
|
+
nil
|
443
|
+
end
|
444
|
+
end
|
445
|
+
let(:resolver_2) do
|
446
|
+
lambda do |r|
|
447
|
+
invoked_resolvers << :resolver_2
|
448
|
+
:not_an_robject
|
449
|
+
end
|
450
|
+
end
|
451
|
+
let(:resolver_3) do
|
452
|
+
lambda do |r|
|
453
|
+
invoked_resolvers << :resolver_3
|
454
|
+
r
|
455
|
+
end
|
456
|
+
end
|
457
|
+
let(:resolver_4) do
|
458
|
+
lambda do |r|
|
459
|
+
invoked_resolvers << :resolver_4
|
460
|
+
resolved_robject
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
before(:each) do
|
465
|
+
described_class.on_conflict(&resolver_1)
|
466
|
+
described_class.on_conflict(&resolver_2)
|
467
|
+
end
|
468
|
+
|
469
|
+
it 'calls each resolver until one of them returns an robject' do
|
470
|
+
described_class.on_conflict(&resolver_3)
|
471
|
+
described_class.on_conflict(&resolver_4)
|
472
|
+
conflicted_robject.attempt_conflict_resolution
|
473
|
+
expect(invoked_resolvers).to eq([:resolver_1, :resolver_2, :resolver_3])
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'returns the robject returned by the last invoked resolver' do
|
477
|
+
described_class.on_conflict(&resolver_4)
|
478
|
+
expect(conflicted_robject.attempt_conflict_resolution).to be(resolved_robject)
|
479
|
+
end
|
480
|
+
|
481
|
+
it 'allows the resolver to return the original robject' do
|
482
|
+
described_class.on_conflict(&resolver_3)
|
483
|
+
expect(conflicted_robject.attempt_conflict_resolution).to be(conflicted_robject)
|
484
|
+
end
|
485
|
+
|
486
|
+
it 'returns the robject and does not call any resolvers if the robject is not in conflict' do
|
487
|
+
expect(resolved_robject.attempt_conflict_resolution).to be(resolved_robject)
|
488
|
+
expect(invoked_resolvers).to eq([])
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'returns the original robject if none of the resolvers returns an robject' do
|
492
|
+
expect(conflicted_robject.attempt_conflict_resolution).to be(conflicted_robject)
|
493
|
+
expect(invoked_resolvers).to eq([:resolver_1, :resolver_2])
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|