riak-client 2.3.0 → 2.3.1
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/Gemfile +17 -17
- data/Guardfile +20 -20
- data/LICENSE.md +16 -16
- data/README.markdown +1 -1
- data/RELEASE_NOTES.md +9 -0
- data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -18
- data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -64
- data/lib/riak/client/beefcake/footer +4 -4
- data/lib/riak/client/beefcake/header +6 -6
- data/lib/riak/client/beefcake/messages.rb +0 -16
- 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 +21 -21
- 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/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/stamp.rb +77 -77
- 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/threading_spec.rb +150 -150
- data/spec/integration/yokozuna/index_spec.rb +61 -61
- data/spec/integration/yokozuna/schema_spec.rb +49 -49
- data/spec/riak/core_ext/to_param_spec.rb +15 -15
- 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/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/stamp_spec.rb +54 -54
- 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/integration_setup.rb +10 -10
- data/spec/support/test_client.yml.example +9 -9
- metadata +3 -3
@@ -1,61 +1,61 @@
|
|
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 "without any indexes" do
|
13
|
-
it "allows index creation" do
|
14
|
-
expect(@client.create_search_index(@index, "_yz_default", 3)).to eq(true)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with an index" do
|
19
|
-
before :all do
|
20
|
-
expect(@client.create_search_index(@index)).to eq(true)
|
21
|
-
wait_until{ !@client.get_search_index(@index).nil? }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "allows index inspection" do
|
25
|
-
expect(@client.get_search_index(@index).name).to eq(@index)
|
26
|
-
expect{ @client.get_search_index("herp_derp") }.to raise_error(Riak::ProtobuffsFailedRequest)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "has an index list" do
|
30
|
-
expect(@client.list_search_indexes.size).to be >= 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "associates a bucket with an index" do
|
34
|
-
@bucket = Riak::Bucket.new(@client, @index)
|
35
|
-
@bucket.props = {'search_index' => @index}
|
36
|
-
@bucket = @client.bucket(@index)
|
37
|
-
expect(@bucket.props).to include('search_index' => @index)
|
38
|
-
end
|
39
|
-
|
40
|
-
context "associated with a bucket" do
|
41
|
-
before :all do
|
42
|
-
@bucket = Riak::Bucket.new(@client, @index)
|
43
|
-
@bucket.props = {'search_index' => @index}
|
44
|
-
@bucket = @client.bucket(@index)
|
45
|
-
expect(@bucket.props).to include('search_index' => @index)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "indexes on object writes" do
|
49
|
-
object = @bucket.get_or_new("cat")
|
50
|
-
object.raw_data = {"cat_s"=>"Lela"}.to_json
|
51
|
-
object.content_type = 'application/json'
|
52
|
-
object.store
|
53
|
-
sleep 1.1 # pause for index commit to trigger
|
54
|
-
|
55
|
-
resp = @client.search(@index, "cat_s:Lela")
|
56
|
-
expect(resp).to include('docs')
|
57
|
-
expect(resp['docs'].size).to eq(1)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
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 "without any indexes" do
|
13
|
+
it "allows index creation" do
|
14
|
+
expect(@client.create_search_index(@index, "_yz_default", 3)).to eq(true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with an index" do
|
19
|
+
before :all do
|
20
|
+
expect(@client.create_search_index(@index)).to eq(true)
|
21
|
+
wait_until{ !@client.get_search_index(@index).nil? }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "allows index inspection" do
|
25
|
+
expect(@client.get_search_index(@index).name).to eq(@index)
|
26
|
+
expect{ @client.get_search_index("herp_derp") }.to raise_error(Riak::ProtobuffsFailedRequest)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has an index list" do
|
30
|
+
expect(@client.list_search_indexes.size).to be >= 1
|
31
|
+
end
|
32
|
+
|
33
|
+
it "associates a bucket with an index" do
|
34
|
+
@bucket = Riak::Bucket.new(@client, @index)
|
35
|
+
@bucket.props = {'search_index' => @index}
|
36
|
+
@bucket = @client.bucket(@index)
|
37
|
+
expect(@bucket.props).to include('search_index' => @index)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "associated with a bucket" do
|
41
|
+
before :all do
|
42
|
+
@bucket = Riak::Bucket.new(@client, @index)
|
43
|
+
@bucket.props = {'search_index' => @index}
|
44
|
+
@bucket = @client.bucket(@index)
|
45
|
+
expect(@bucket.props).to include('search_index' => @index)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "indexes on object writes" do
|
49
|
+
object = @bucket.get_or_new("cat")
|
50
|
+
object.raw_data = {"cat_s"=>"Lela"}.to_json
|
51
|
+
object.content_type = 'application/json'
|
52
|
+
object.store
|
53
|
+
sleep 1.1 # pause for index commit to trigger
|
54
|
+
|
55
|
+
resp = @client.search(@index, "cat_s:Lela")
|
56
|
+
expect(resp).to include('docs')
|
57
|
+
expect(resp['docs'].size).to eq(1)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -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
|
@@ -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
|
@@ -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
|