riak-client 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.document +5 -5
- data/.gitignore +3 -0
- data/Gemfile +17 -17
- data/Guardfile +20 -20
- data/LICENSE.md +16 -16
- data/RELNOTES.md +4 -0
- data/Rakefile +6 -1
- data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -18
- data/lib/riak/client/beefcake/crdt/hyper_log_log_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -64
- data/lib/riak/client/beefcake/crdt_loader.rb +4 -1
- data/lib/riak/client/beefcake/crdt_operator.rb +13 -0
- data/lib/riak/client/beefcake/footer +4 -4
- data/lib/riak/client/beefcake/header +6 -6
- data/lib/riak/client/beefcake/messages.rb +67 -10
- data/lib/riak/client/decaying.rb +36 -36
- data/lib/riak/client/feature_detection.rb +120 -120
- data/lib/riak/client/instrumentation.rb +19 -19
- data/lib/riak/client/node.rb +49 -49
- data/lib/riak/client/search.rb +27 -27
- data/lib/riak/conflict.rb +13 -13
- data/lib/riak/core_ext.rb +7 -7
- data/lib/riak/core_ext/blank.rb +53 -53
- data/lib/riak/core_ext/extract_options.rb +7 -7
- data/lib/riak/core_ext/json.rb +15 -15
- data/lib/riak/core_ext/slice.rb +18 -18
- data/lib/riak/core_ext/stringify_keys.rb +10 -10
- data/lib/riak/core_ext/symbolize_keys.rb +10 -10
- data/lib/riak/core_ext/to_param.rb +31 -31
- data/lib/riak/crdt.rb +23 -21
- data/lib/riak/crdt/base.rb +1 -1
- data/lib/riak/crdt/hyper_log_log.rb +97 -0
- data/lib/riak/crdt/operation.rb +19 -19
- data/lib/riak/encoding.rb +6 -6
- data/lib/riak/errors/backend_creation.rb +9 -9
- data/lib/riak/errors/connection_error.rb +50 -50
- data/lib/riak/errors/protobuffs_error.rb +11 -11
- data/lib/riak/i18n.rb +7 -7
- data/lib/riak/instrumentation.rb +6 -6
- data/lib/riak/json.rb +52 -52
- data/lib/riak/list_buckets.rb +28 -28
- data/lib/riak/locale/en.yml +1 -0
- data/lib/riak/locale/fr.yml +51 -51
- data/lib/riak/map_reduce/results.rb +49 -49
- data/lib/riak/map_reduce_error.rb +7 -7
- data/lib/riak/multiget.rb +122 -122
- data/lib/riak/robject.rb +17 -1
- data/lib/riak/search/result_document.rb +9 -0
- data/lib/riak/stamp.rb +77 -77
- data/lib/riak/tombstone.rb +13 -0
- data/lib/riak/util/tcp_socket_extensions.rb +58 -58
- data/lib/riak/version.rb +1 -1
- data/spec/failover/failover.rb +59 -59
- data/spec/fixtures/bitcask.txt +25 -25
- data/spec/fixtures/multipart-basic-conflict.txt +15 -15
- data/spec/fixtures/multipart-blank.txt +7 -7
- data/spec/fixtures/multipart-mapreduce.txt +10 -10
- data/spec/fixtures/multipart-with-body.txt +16 -16
- data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -17
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -16
- data/spec/fixtures/server.cert.crt +15 -15
- data/spec/fixtures/server.cert.key +15 -15
- data/spec/fixtures/test.pem +1 -1
- data/spec/integration/riak/bucket_types_spec.rb +38 -0
- data/spec/integration/riak/crdt/configuration_spec.rb +4 -3
- data/spec/integration/riak/crdt_spec.rb +70 -0
- data/spec/integration/riak/encodings/crdt_spec.rb +29 -3
- data/spec/integration/riak/encodings/yz_spec.rb +2 -1
- data/spec/integration/riak/preflist_spec.rb +15 -3
- data/spec/integration/riak/protobuffs/timeouts_spec.rb +1 -1
- data/spec/integration/riak/security_spec.rb +11 -6
- data/spec/integration/riak/threading_spec.rb +154 -150
- data/spec/integration/yokozuna/index_spec.rb +61 -61
- data/spec/integration/yokozuna/queries_spec.rb +1 -1
- data/spec/integration/yokozuna/schema_spec.rb +49 -49
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +22 -0
- data/spec/riak/core_ext/to_param_spec.rb +15 -15
- data/spec/riak/crdt/hyper_log_log_spec.rb +56 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -21
- data/spec/riak/crdt/inner_set_spec.rb +33 -33
- data/spec/riak/crdt/set_spec.rb +61 -61
- data/spec/riak/crdt/shared_examples.rb +14 -0
- data/spec/riak/escape_spec.rb +72 -72
- data/spec/riak/feature_detection_spec.rb +77 -77
- data/spec/riak/index_collection_spec.rb +53 -53
- data/spec/riak/instrumentation_spec.rb +124 -124
- data/spec/riak/link_spec.rb +85 -85
- data/spec/riak/list_buckets_spec.rb +41 -41
- data/spec/riak/node_spec.rb +26 -26
- data/spec/riak/robject_spec.rb +45 -0
- data/spec/support/certs/README.md +12 -12
- data/spec/support/certs/ca.crt +21 -21
- data/spec/support/certs/client.crl +13 -13
- data/spec/support/certs/client.crt +94 -94
- data/spec/support/certs/client.csr +18 -18
- data/spec/support/certs/client.key +27 -27
- data/spec/support/certs/empty_ca.crt +21 -21
- data/spec/support/certs/server.crl +13 -13
- data/spec/support/certs/server.crt +94 -94
- data/spec/support/certs/server.key +27 -27
- data/spec/support/crdt_search_fixtures.rb +1 -1
- data/spec/support/integration_setup.rb +10 -10
- data/spec/support/test_client.rb +1 -1
- data/spec/support/test_client.yml.example +10 -10
- metadata +10 -3
@@ -75,7 +75,7 @@ describe "Yokozuna queries", test_client: true, integration: true do
|
|
75
75
|
|
76
76
|
it "supports utf8" do
|
77
77
|
build_json_obj(@bucket, "ja", {"text_ja"=>"私はハイビスカスを食べるのが 大好き"})
|
78
|
-
sleep
|
78
|
+
sleep 2.1 # pause for index commit to trigger
|
79
79
|
resp = @client.search(@index, "text_ja:大好き")
|
80
80
|
expect(resp).to include('docs')
|
81
81
|
expect(resp['docs'].size).to eq 1
|
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'riak'
|
3
|
-
|
4
|
-
describe "Yokozuna", test_client: true, integration: true do
|
5
|
-
before(:all) do
|
6
|
-
@client = test_client
|
7
|
-
|
8
|
-
@index = 'yz_spec-' + random_key
|
9
|
-
@schema = 'yz_spec-' + random_key
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with no schema' do
|
13
|
-
it 'allows schema creation' do
|
14
|
-
@client.create_search_schema(@schema, SCHEMA_CONTENT)
|
15
|
-
wait_until{ !@client.get_search_schema(@schema).nil? }
|
16
|
-
expect(@client.get_search_schema(@schema)).not_to be_nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
context 'with a schema' do
|
20
|
-
it 'has a readable schema' do
|
21
|
-
@client.create_search_schema(@schema, SCHEMA_CONTENT)
|
22
|
-
wait_until{ !@client.get_search_schema(@schema).nil? }
|
23
|
-
schema_resp = @client.get_search_schema(@schema)
|
24
|
-
expect(schema_resp.name).to eq(@schema)
|
25
|
-
expect(schema_resp.content).to eq(SCHEMA_CONTENT)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
SCHEMA_CONTENT = <<-XML
|
30
|
-
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
|
31
|
-
<schema name=\"#{@index}\" version=\"1.5\">
|
32
|
-
<fields>
|
33
|
-
<field name=\"_yz_id\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\" required=\"true\" />
|
34
|
-
<field name=\"_yz_ed\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
35
|
-
<field name=\"_yz_pn\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
36
|
-
<field name=\"_yz_fpn\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
37
|
-
<field name=\"_yz_vtag\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
38
|
-
<field name=\"_yz_rk\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
39
|
-
<field name=\"_yz_rb\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
40
|
-
<field name=\"_yz_rt\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
41
|
-
<field name=\"_yz_err\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
42
|
-
</fields>
|
43
|
-
<uniqueKey>_yz_id</uniqueKey>
|
44
|
-
<types>
|
45
|
-
<fieldType name=\"_yz_str\" class=\"solr.StrField\" sortMissingLast=\"true\" />
|
46
|
-
</types>
|
47
|
-
</schema>
|
48
|
-
XML
|
49
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'riak'
|
3
|
+
|
4
|
+
describe "Yokozuna", test_client: true, integration: true do
|
5
|
+
before(:all) do
|
6
|
+
@client = test_client
|
7
|
+
|
8
|
+
@index = 'yz_spec-' + random_key
|
9
|
+
@schema = 'yz_spec-' + random_key
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with no schema' do
|
13
|
+
it 'allows schema creation' do
|
14
|
+
@client.create_search_schema(@schema, SCHEMA_CONTENT)
|
15
|
+
wait_until{ !@client.get_search_schema(@schema).nil? }
|
16
|
+
expect(@client.get_search_schema(@schema)).not_to be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context 'with a schema' do
|
20
|
+
it 'has a readable schema' do
|
21
|
+
@client.create_search_schema(@schema, SCHEMA_CONTENT)
|
22
|
+
wait_until{ !@client.get_search_schema(@schema).nil? }
|
23
|
+
schema_resp = @client.get_search_schema(@schema)
|
24
|
+
expect(schema_resp.name).to eq(@schema)
|
25
|
+
expect(schema_resp.content).to eq(SCHEMA_CONTENT)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
SCHEMA_CONTENT = <<-XML
|
30
|
+
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
|
31
|
+
<schema name=\"#{@index}\" version=\"1.5\">
|
32
|
+
<fields>
|
33
|
+
<field name=\"_yz_id\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\" required=\"true\" />
|
34
|
+
<field name=\"_yz_ed\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
35
|
+
<field name=\"_yz_pn\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
36
|
+
<field name=\"_yz_fpn\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
37
|
+
<field name=\"_yz_vtag\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
38
|
+
<field name=\"_yz_rk\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
39
|
+
<field name=\"_yz_rb\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
40
|
+
<field name=\"_yz_rt\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
41
|
+
<field name=\"_yz_err\" type=\"_yz_str\" indexed=\"true\" stored=\"true\" multiValued=\"false\"/>
|
42
|
+
</fields>
|
43
|
+
<uniqueKey>_yz_id</uniqueKey>
|
44
|
+
<types>
|
45
|
+
<fieldType name=\"_yz_str\" class=\"solr.StrField\" sortMissingLast=\"true\" />
|
46
|
+
</types>
|
47
|
+
</schema>
|
48
|
+
XML
|
49
|
+
end
|
@@ -61,6 +61,28 @@ describe Riak::Client::BeefcakeProtobuffsBackend::CrdtOperator do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
describe 'operating on a hyper_log_log' do
|
65
|
+
let(:added_element){ 'added_element' }
|
66
|
+
let(:operation) do
|
67
|
+
Riak::Crdt::Operation::Update.new.tap do |op|
|
68
|
+
op.type = :hll
|
69
|
+
op.value = {
|
70
|
+
add: [added_element]
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'serializes a hyper_log_log operation into protobuffs' do
|
76
|
+
result = subject.serialize operation
|
77
|
+
|
78
|
+
expect{result.encode}.to_not raise_error
|
79
|
+
|
80
|
+
expect(result).to be_a backend_class::DtOp
|
81
|
+
expect(result.hll_op).to be_a backend_class::HllOp
|
82
|
+
expect(result.hll_op.adds).to eq [added_element]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
64
86
|
describe 'operating on a map' do
|
65
87
|
it 'serializes inner counter operations' do
|
66
88
|
counter_op = Riak::Crdt::Operation::Update.new.tap do |op|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
describe Riak do
|
3
|
-
require 'riak/core_ext/to_param'
|
4
|
-
|
5
|
-
it "converts params correctly" do
|
6
|
-
expect({ :name => 'David', :nationality => 'Danish' }.to_param).to eq("name=David&nationality=Danish")
|
7
|
-
end
|
8
|
-
|
9
|
-
# Based on the activesupport implementation.
|
10
|
-
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_param.rb
|
11
|
-
it "converts namespaced params correctly" do
|
12
|
-
expect({ :name => 'David', :nationality => 'Danish' }.to_param('user')).to eq("user%5Bname%5D=David&user%5Bnationality%5D=Danish")
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
1
|
+
|
2
|
+
describe Riak do
|
3
|
+
require 'riak/core_ext/to_param'
|
4
|
+
|
5
|
+
it "converts params correctly" do
|
6
|
+
expect({ :name => 'David', :nationality => 'Danish' }.to_param).to eq("name=David&nationality=Danish")
|
7
|
+
end
|
8
|
+
|
9
|
+
# Based on the activesupport implementation.
|
10
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_param.rb
|
11
|
+
it "converts namespaced params correctly" do
|
12
|
+
expect({ :name => 'David', :nationality => 'Danish' }.to_param('user')).to eq("user%5Bname%5D=David&user%5Bnationality%5D=Danish")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples'
|
3
|
+
|
4
|
+
describe Riak::Crdt::HyperLogLog, hll: true do
|
5
|
+
let(:bucket) do
|
6
|
+
double('bucket').tap do |b|
|
7
|
+
allow(b).to receive(:name).and_return('bucket')
|
8
|
+
allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true)
|
9
|
+
allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'initializes with bucket, key, and bucket-type' do
|
14
|
+
expect{described_class.new bucket, 'key', 'bucket type'}.
|
15
|
+
to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
subject{ described_class.new bucket, 'key' }
|
19
|
+
|
20
|
+
describe 'with a client' do
|
21
|
+
let(:response){ double 'response', key: nil }
|
22
|
+
let(:operator){ double 'operator' }
|
23
|
+
let(:loader){ double 'loader', get_loader_for_value: nil }
|
24
|
+
let(:backend){ double 'backend' }
|
25
|
+
let(:client){ double 'client' }
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
allow(bucket).to receive(:client).and_return(client)
|
29
|
+
allow(client).to receive(:backend).and_yield(backend)
|
30
|
+
allow(backend).to receive(:crdt_operator).and_return(operator)
|
31
|
+
allow(backend).to receive(:crdt_loader).and_return(loader)
|
32
|
+
end
|
33
|
+
|
34
|
+
include_examples 'HyperLogLog CRDT'
|
35
|
+
|
36
|
+
it 'batches properly' do
|
37
|
+
expect(operator).
|
38
|
+
to receive(:operate) { |bucket, key, type, operations|
|
39
|
+
expect(bucket).to eq bucket
|
40
|
+
expect(key).to eq 'key'
|
41
|
+
expect(type).to eq subject.bucket_type
|
42
|
+
|
43
|
+
expect(operations).to be_a Riak::Crdt::Operation::Update
|
44
|
+
expect(operations.value).to eq({add: %w{alpha bravo}})
|
45
|
+
}.
|
46
|
+
and_return(response)
|
47
|
+
|
48
|
+
subject.instance_variable_set :@context, 'placeholder'
|
49
|
+
|
50
|
+
subject.batch do |s|
|
51
|
+
s.add 'alpha'
|
52
|
+
s.add 'bravo'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative 'shared_examples'
|
3
|
-
|
4
|
-
describe Riak::Crdt::InnerCounter do
|
5
|
-
let(:parent){ double 'parent' }
|
6
|
-
let(:counter_name){ 'counter name' }
|
7
|
-
subject do
|
8
|
-
described_class.new(parent, 0).tap do |c|
|
9
|
-
c.name = counter_name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
include_examples 'Counter CRDT'
|
14
|
-
|
15
|
-
it 'sends increments to the parent' do
|
16
|
-
expect(parent).to receive(:increment).
|
17
|
-
with(counter_name, 1)
|
18
|
-
|
19
|
-
subject.increment
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples'
|
3
|
+
|
4
|
+
describe Riak::Crdt::InnerCounter do
|
5
|
+
let(:parent){ double 'parent' }
|
6
|
+
let(:counter_name){ 'counter name' }
|
7
|
+
subject do
|
8
|
+
described_class.new(parent, 0).tap do |c|
|
9
|
+
c.name = counter_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include_examples 'Counter CRDT'
|
14
|
+
|
15
|
+
it 'sends increments to the parent' do
|
16
|
+
expect(parent).to receive(:increment).
|
17
|
+
with(counter_name, 1)
|
18
|
+
|
19
|
+
subject.increment
|
20
|
+
end
|
21
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative 'shared_examples'
|
3
|
-
|
4
|
-
describe Riak::Crdt::InnerSet do
|
5
|
-
let(:parent){ double 'parent' }
|
6
|
-
let(:set_name){ 'set name' }
|
7
|
-
subject do
|
8
|
-
described_class.new(parent, []).tap do |s|
|
9
|
-
s.name = set_name
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
include_examples 'Set CRDT'
|
14
|
-
|
15
|
-
it 'sends additions to the parent' do
|
16
|
-
expect(parent).to receive(:operate) do |name, op|
|
17
|
-
expect(name).to eq set_name
|
18
|
-
expect(op.type).to eq :set
|
19
|
-
expect(op.value).to eq add: 'el'
|
20
|
-
end
|
21
|
-
|
22
|
-
subject.add 'el'
|
23
|
-
|
24
|
-
expect(parent).to receive(:operate) do |name, op|
|
25
|
-
expect(name).to eq set_name
|
26
|
-
expect(op.type).to eq :set
|
27
|
-
expect(op.value).to eq remove: 'el2'
|
28
|
-
end
|
29
|
-
allow(parent).to receive(:context?).and_return(true)
|
30
|
-
|
31
|
-
subject.remove 'el2'
|
32
|
-
end
|
33
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples'
|
3
|
+
|
4
|
+
describe Riak::Crdt::InnerSet do
|
5
|
+
let(:parent){ double 'parent' }
|
6
|
+
let(:set_name){ 'set name' }
|
7
|
+
subject do
|
8
|
+
described_class.new(parent, []).tap do |s|
|
9
|
+
s.name = set_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
include_examples 'Set CRDT'
|
14
|
+
|
15
|
+
it 'sends additions to the parent' do
|
16
|
+
expect(parent).to receive(:operate) do |name, op|
|
17
|
+
expect(name).to eq set_name
|
18
|
+
expect(op.type).to eq :set
|
19
|
+
expect(op.value).to eq add: 'el'
|
20
|
+
end
|
21
|
+
|
22
|
+
subject.add 'el'
|
23
|
+
|
24
|
+
expect(parent).to receive(:operate) do |name, op|
|
25
|
+
expect(name).to eq set_name
|
26
|
+
expect(op.type).to eq :set
|
27
|
+
expect(op.value).to eq remove: 'el2'
|
28
|
+
end
|
29
|
+
allow(parent).to receive(:context?).and_return(true)
|
30
|
+
|
31
|
+
subject.remove 'el2'
|
32
|
+
end
|
33
|
+
end
|
data/spec/riak/crdt/set_spec.rb
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative 'shared_examples'
|
3
|
-
|
4
|
-
describe Riak::Crdt::Set do
|
5
|
-
let(:bucket) do
|
6
|
-
double('bucket').tap do |b|
|
7
|
-
allow(b).to receive(:name).and_return('bucket')
|
8
|
-
allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true)
|
9
|
-
allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'initializes with bucket, key, and optional bucket-type' do
|
14
|
-
expect{described_class.new bucket, 'key', 'optional bucket type'}.
|
15
|
-
to_not raise_error
|
16
|
-
end
|
17
|
-
|
18
|
-
subject{ described_class.new bucket, 'key' }
|
19
|
-
|
20
|
-
describe 'with a client' do
|
21
|
-
let(:response){ double 'response', key: nil }
|
22
|
-
let(:operator){ double 'operator' }
|
23
|
-
let(:loader){ double 'loader', get_loader_for_value: nil }
|
24
|
-
let(:backend){ double 'backend' }
|
25
|
-
let(:client){ double 'client' }
|
26
|
-
|
27
|
-
before(:each) do
|
28
|
-
allow(bucket).to receive(:client).and_return(client)
|
29
|
-
allow(client).to receive(:backend).and_yield(backend)
|
30
|
-
allow(backend).to receive(:crdt_operator).and_return(operator)
|
31
|
-
allow(backend).to receive(:crdt_loader).and_return(loader)
|
32
|
-
end
|
33
|
-
|
34
|
-
include_examples 'Set CRDT'
|
35
|
-
|
36
|
-
it 'batches properly' do
|
37
|
-
expect(operator).
|
38
|
-
to receive(:operate) { |bucket, key, type, operations|
|
39
|
-
|
40
|
-
expect(bucket).to eq bucket
|
41
|
-
expect(key).to eq 'key'
|
42
|
-
expect(type).to eq subject.bucket_type
|
43
|
-
|
44
|
-
expect(operations).to be_a Riak::Crdt::Operation::Update
|
45
|
-
expect(operations.value).to eq({
|
46
|
-
add: %w{alpha bravo},
|
47
|
-
remove: %w{foxtrot}
|
48
|
-
})
|
49
|
-
}.
|
50
|
-
and_return(response)
|
51
|
-
|
52
|
-
subject.instance_variable_set :@context, 'placeholder'
|
53
|
-
|
54
|
-
subject.batch do |s|
|
55
|
-
s.add 'alpha'
|
56
|
-
s.add 'bravo'
|
57
|
-
s.remove 'foxtrot'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'shared_examples'
|
3
|
+
|
4
|
+
describe Riak::Crdt::Set do
|
5
|
+
let(:bucket) do
|
6
|
+
double('bucket').tap do |b|
|
7
|
+
allow(b).to receive(:name).and_return('bucket')
|
8
|
+
allow(b).to receive(:is_a?).with(Riak::Bucket).and_return(true)
|
9
|
+
allow(b).to receive(:is_a?).with(Riak::BucketTyped::Bucket).and_return(false)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'initializes with bucket, key, and optional bucket-type' do
|
14
|
+
expect{described_class.new bucket, 'key', 'optional bucket type'}.
|
15
|
+
to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
subject{ described_class.new bucket, 'key' }
|
19
|
+
|
20
|
+
describe 'with a client' do
|
21
|
+
let(:response){ double 'response', key: nil }
|
22
|
+
let(:operator){ double 'operator' }
|
23
|
+
let(:loader){ double 'loader', get_loader_for_value: nil }
|
24
|
+
let(:backend){ double 'backend' }
|
25
|
+
let(:client){ double 'client' }
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
allow(bucket).to receive(:client).and_return(client)
|
29
|
+
allow(client).to receive(:backend).and_yield(backend)
|
30
|
+
allow(backend).to receive(:crdt_operator).and_return(operator)
|
31
|
+
allow(backend).to receive(:crdt_loader).and_return(loader)
|
32
|
+
end
|
33
|
+
|
34
|
+
include_examples 'Set CRDT'
|
35
|
+
|
36
|
+
it 'batches properly' do
|
37
|
+
expect(operator).
|
38
|
+
to receive(:operate) { |bucket, key, type, operations|
|
39
|
+
|
40
|
+
expect(bucket).to eq bucket
|
41
|
+
expect(key).to eq 'key'
|
42
|
+
expect(type).to eq subject.bucket_type
|
43
|
+
|
44
|
+
expect(operations).to be_a Riak::Crdt::Operation::Update
|
45
|
+
expect(operations.value).to eq({
|
46
|
+
add: %w{alpha bravo},
|
47
|
+
remove: %w{foxtrot}
|
48
|
+
})
|
49
|
+
}.
|
50
|
+
and_return(response)
|
51
|
+
|
52
|
+
subject.instance_variable_set :@context, 'placeholder'
|
53
|
+
|
54
|
+
subject.batch do |s|
|
55
|
+
s.add 'alpha'
|
56
|
+
s.add 'bravo'
|
57
|
+
s.remove 'foxtrot'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|