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.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.markdown +211 -66
  6. data/RELEASE_NOTES.md +22 -47
  7. data/Rakefile +45 -0
  8. data/lib/riak.rb +1 -1
  9. data/lib/riak/bucket.rb +2 -2
  10. data/lib/riak/client.rb +22 -195
  11. data/lib/riak/client/beefcake/crdt_loader.rb +127 -0
  12. data/lib/riak/client/beefcake/crdt_operator.rb +222 -0
  13. data/lib/riak/client/beefcake/footer +4 -0
  14. data/lib/riak/client/beefcake/header +6 -0
  15. data/lib/riak/client/beefcake/message_codes.rb +29 -0
  16. data/lib/riak/client/beefcake/message_overlay.rb +61 -0
  17. data/lib/riak/client/beefcake/messages.rb +733 -371
  18. data/lib/riak/client/beefcake/object_methods.rb +1 -1
  19. data/lib/riak/client/beefcake/protocol.rb +105 -0
  20. data/lib/riak/client/beefcake/socket.rb +243 -0
  21. data/lib/riak/client/beefcake_protobuffs_backend.rb +262 -122
  22. data/lib/riak/client/node.rb +4 -75
  23. data/lib/riak/client/protobuffs_backend.rb +6 -14
  24. data/lib/riak/client/search.rb +0 -64
  25. data/lib/riak/client/yokozuna.rb +52 -0
  26. data/lib/riak/counter.rb +1 -1
  27. data/lib/riak/crdt.rb +21 -0
  28. data/lib/riak/crdt/base.rb +97 -0
  29. data/lib/riak/crdt/batch_counter.rb +19 -0
  30. data/lib/riak/crdt/batch_map.rb +41 -0
  31. data/lib/riak/crdt/counter.rb +71 -0
  32. data/lib/riak/crdt/inner_counter.rb +74 -0
  33. data/lib/riak/crdt/inner_flag.rb +42 -0
  34. data/lib/riak/crdt/inner_map.rb +53 -0
  35. data/lib/riak/crdt/inner_register.rb +26 -0
  36. data/lib/riak/crdt/inner_set.rb +95 -0
  37. data/lib/riak/crdt/map.rb +88 -0
  38. data/lib/riak/crdt/operation.rb +19 -0
  39. data/lib/riak/crdt/set.rb +156 -0
  40. data/lib/riak/crdt/typed_collection.rb +131 -0
  41. data/lib/riak/errors/base.rb +9 -0
  42. data/lib/riak/errors/connection_error.rb +44 -0
  43. data/lib/riak/errors/crdt_error.rb +18 -0
  44. data/lib/riak/errors/failed_request.rb +56 -0
  45. data/lib/riak/errors/protobuffs_error.rb +11 -0
  46. data/lib/riak/i18n.rb +2 -0
  47. data/lib/riak/json.rb +1 -1
  48. data/lib/riak/locale/en.yml +26 -1
  49. data/lib/riak/locale/fr.yml +0 -1
  50. data/lib/riak/map_reduce.rb +1 -1
  51. data/lib/riak/map_reduce/results.rb +1 -1
  52. data/lib/riak/multiget.rb +1 -2
  53. data/lib/riak/rcontent.rb +8 -3
  54. data/lib/riak/robject.rb +2 -8
  55. data/lib/riak/secondary_index.rb +4 -4
  56. data/lib/riak/serializers.rb +1 -1
  57. data/lib/riak/util/escape.rb +3 -5
  58. data/lib/riak/version.rb +1 -1
  59. data/lib/riak/walk_spec.rb +7 -3
  60. data/riak-client.gemspec +10 -8
  61. data/spec/fixtures/bitcask.txt +25 -0
  62. data/spec/integration/riak/bucket_types_spec.rb +61 -0
  63. data/spec/integration/riak/counters_spec.rb +17 -32
  64. data/spec/integration/riak/crdt_spec.rb +181 -0
  65. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  66. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  67. data/spec/integration/riak/protobuffs_backends_spec.rb +9 -26
  68. data/spec/integration/riak/security_spec.rb +94 -0
  69. data/spec/integration/riak/threading_spec.rb +24 -67
  70. data/spec/integration/yokozuna/index_spec.rb +61 -0
  71. data/spec/integration/yokozuna/queries_spec.rb +116 -0
  72. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  73. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  74. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +4 -4
  75. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  76. data/spec/riak/beefcake_protobuffs_backend/socket_spec.rb +151 -0
  77. data/spec/riak/beefcake_protobuffs_backend_spec.rb +68 -106
  78. data/spec/riak/bucket_spec.rb +81 -77
  79. data/spec/riak/client_spec.rb +43 -340
  80. data/spec/riak/core_ext/to_param_spec.rb +2 -2
  81. data/spec/riak/counter_spec.rb +20 -20
  82. data/spec/riak/crdt/counter_spec.rb +52 -0
  83. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  84. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  85. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  86. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  87. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  88. data/spec/riak/crdt/map_spec.rb +77 -0
  89. data/spec/riak/crdt/set_spec.rb +58 -0
  90. data/spec/riak/crdt/shared_examples.rb +74 -0
  91. data/spec/riak/crdt/typed_collection_spec.rb +231 -0
  92. data/spec/riak/escape_spec.rb +33 -37
  93. data/spec/riak/feature_detection_spec.rb +45 -45
  94. data/spec/riak/index_collection_spec.rb +12 -12
  95. data/spec/riak/link_spec.rb +34 -34
  96. data/spec/riak/list_buckets_spec.rb +7 -7
  97. data/spec/riak/map_reduce/filter_builder_spec.rb +6 -6
  98. data/spec/riak/map_reduce/phase_spec.rb +35 -35
  99. data/spec/riak/map_reduce_spec.rb +89 -87
  100. data/spec/riak/multiget_spec.rb +20 -15
  101. data/spec/riak/node_spec.rb +5 -152
  102. data/spec/riak/robject_spec.rb +95 -108
  103. data/spec/riak/search_spec.rb +17 -139
  104. data/spec/riak/secondary_index_spec.rb +49 -49
  105. data/spec/riak/serializers_spec.rb +9 -9
  106. data/spec/riak/stamp_spec.rb +9 -9
  107. data/spec/riak/walk_spec_spec.rb +46 -46
  108. data/spec/spec_helper.rb +14 -22
  109. data/spec/support/certs/README.md +13 -0
  110. data/spec/support/certs/ca.crt +22 -0
  111. data/spec/support/certs/client.crt +95 -0
  112. data/spec/support/certs/client.key +27 -0
  113. data/spec/support/certs/empty_ca.crt +21 -0
  114. data/spec/support/certs/server.crl +13 -0
  115. data/spec/support/certs/server.crt +95 -0
  116. data/spec/support/certs/server.key +27 -0
  117. data/spec/support/integration_setup.rb +1 -1
  118. data/spec/support/search_corpus_setup.rb +29 -8
  119. data/spec/support/test_client.rb +46 -0
  120. data/spec/support/test_client.yml.example +10 -0
  121. data/spec/support/unified_backend_examples.rb +104 -83
  122. data/spec/support/version_filter.rb +2 -2
  123. data/spec/support/wait_until.rb +14 -0
  124. metadata +134 -132
  125. data/erl_src/riak_kv_test014_backend.beam +0 -0
  126. data/erl_src/riak_kv_test014_backend.erl +0 -189
  127. data/erl_src/riak_kv_test_backend.beam +0 -0
  128. data/erl_src/riak_kv_test_backend.erl +0 -731
  129. data/erl_src/riak_search_test_backend.beam +0 -0
  130. data/erl_src/riak_search_test_backend.erl +0 -175
  131. data/lib/riak/client/excon_backend.rb +0 -172
  132. data/lib/riak/client/http_backend.rb +0 -413
  133. data/lib/riak/client/http_backend/bucket_streamer.rb +0 -15
  134. data/lib/riak/client/http_backend/chunked_json_streamer.rb +0 -42
  135. data/lib/riak/client/http_backend/configuration.rb +0 -227
  136. data/lib/riak/client/http_backend/key_streamer.rb +0 -15
  137. data/lib/riak/client/http_backend/object_methods.rb +0 -114
  138. data/lib/riak/client/http_backend/request_headers.rb +0 -34
  139. data/lib/riak/client/http_backend/transport_methods.rb +0 -201
  140. data/lib/riak/client/instrumentation.rb +0 -25
  141. data/lib/riak/client/net_http_backend.rb +0 -82
  142. data/lib/riak/cluster.rb +0 -151
  143. data/lib/riak/failed_request.rb +0 -81
  144. data/lib/riak/instrumentation.rb +0 -6
  145. data/lib/riak/node.rb +0 -40
  146. data/lib/riak/node/configuration.rb +0 -304
  147. data/lib/riak/node/console.rb +0 -133
  148. data/lib/riak/node/control.rb +0 -207
  149. data/lib/riak/node/defaults.rb +0 -85
  150. data/lib/riak/node/generation.rb +0 -127
  151. data/lib/riak/node/log.rb +0 -34
  152. data/lib/riak/node/version.rb +0 -29
  153. data/lib/riak/search.rb +0 -3
  154. data/lib/riak/test_server.rb +0 -89
  155. data/lib/riak/util/headers.rb +0 -32
  156. data/lib/riak/util/multipart.rb +0 -52
  157. data/lib/riak/util/multipart/stream_parser.rb +0 -62
  158. data/spec/fixtures/munchausen.txt +0 -1033
  159. data/spec/integration/riak/cluster_spec.rb +0 -88
  160. data/spec/integration/riak/http_backends_spec.rb +0 -180
  161. data/spec/integration/riak/node_spec.rb +0 -170
  162. data/spec/integration/riak/test_server_spec.rb +0 -57
  163. data/spec/riak/excon_backend_spec.rb +0 -102
  164. data/spec/riak/headers_spec.rb +0 -21
  165. data/spec/riak/http_backend/configuration_spec.rb +0 -273
  166. data/spec/riak/http_backend/object_methods_spec.rb +0 -243
  167. data/spec/riak/http_backend/transport_methods_spec.rb +0 -97
  168. data/spec/riak/http_backend_spec.rb +0 -367
  169. data/spec/riak/instrumentation_spec.rb +0 -167
  170. data/spec/riak/multipart_spec.rb +0 -23
  171. data/spec/riak/net_http_backend_spec.rb +0 -15
  172. data/spec/riak/stream_parser_spec.rb +0 -53
  173. data/spec/support/drb_mock_server.rb +0 -39
  174. data/spec/support/http_backend_implementation_examples.rb +0 -253
  175. data/spec/support/mock_server.rb +0 -81
  176. data/spec/support/mocks.rb +0 -4
  177. data/spec/support/riak_test.rb +0 -77
  178. data/spec/support/sometimes.rb +0 -46
  179. data/spec/support/test_server.rb +0 -61
  180. data/spec/support/test_server.yml.example +0 -14
@@ -3,13 +3,13 @@ describe Riak do
3
3
  require 'riak/core_ext/to_param'
4
4
 
5
5
  it "should do param conversion correctly" do
6
- { :name => 'David', :nationality => 'Danish' }.to_param.should == "name=David&nationality=Danish"
6
+ expect({ :name => 'David', :nationality => 'Danish' }.to_param).to eq("name=David&nationality=Danish")
7
7
  end
8
8
 
9
9
  # Based on the activesupport implementation.
10
10
  # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_param.rb
11
11
  it "should do param conversion correctly with a namespace" do
12
- { :name => 'David', :nationality => 'Danish' }.to_param('user').should == "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
12
+ expect({ :name => 'David', :nationality => 'Danish' }.to_param('user')).to eq("user%5Bname%5D=David&user%5Bnationality%5D=Danish")
13
13
  end
14
14
 
15
15
  end
@@ -5,21 +5,21 @@ describe Riak::Counter do
5
5
  before :each do
6
6
  @bucket = Riak::Bucket.allocate
7
7
  @key = 'key'
8
- @bucket.stub allow_mult: true
9
- @bucket.stub(client: mock('client'))
10
- @bucket.stub('is_a?' => true)
8
+ allow(@bucket).to receive(:allow_mult).and_return(true)
9
+ allow(@bucket).to receive(:client).and_return(double('client'))
10
+ allow(@bucket).to receive('is_a?').and_return(true)
11
11
  end
12
12
 
13
13
  it "should set the bucket and key" do
14
14
  ctr = Riak::Counter.new @bucket, @key
15
- ctr.bucket.should == @bucket
16
- ctr.key.should == @key
15
+ expect(ctr.bucket).to eq(@bucket)
16
+ expect(ctr.key).to eq(@key)
17
17
  end
18
18
 
19
19
  it "should require allow_mult" do
20
20
  @bad_bucket = Riak::Bucket.allocate
21
- @bad_bucket.stub allow_mult: false
22
- @bad_bucket.stub(client: mock('client'))
21
+ allow(@bad_bucket).to receive(:allow_mult).and_return(false)
22
+ allow(@bad_bucket).to receive(:client).and_return(double('client'))
23
23
 
24
24
  expect{ctr = Riak::Counter.new @bad_bucket, @key}.to raise_error(ArgumentError)
25
25
 
@@ -28,20 +28,20 @@ describe Riak::Counter do
28
28
 
29
29
  describe "incrementing and decrementing" do
30
30
  before :each do
31
- @backend = mock 'backend'
31
+ @backend = double 'backend'
32
32
 
33
- @client = mock 'client'
34
- @client.stub(:backend).and_yield @backend
33
+ @client = double 'client'
34
+ allow(@client).to receive(:backend).and_yield @backend
35
35
 
36
36
  @bucket = Riak::Bucket.allocate
37
- @bucket.stub allow_mult: true
38
- @bucket.stub client: @client
37
+ allow(@bucket).to receive(:allow_mult).and_return(true)
38
+ allow(@bucket).to receive(:client).and_return(@client)
39
39
 
40
40
  @key = 'key'
41
41
 
42
42
  @ctr = Riak::Counter.new @bucket, @key
43
43
 
44
- @increment_expectation = proc{|n| @backend.should_receive(:post_counter).with(@bucket, @key, n, {})}
44
+ @increment_expectation = proc{|n| expect(@backend).to receive(:post_counter).with(@bucket, @key, n, {})}
45
45
  end
46
46
 
47
47
  it "should increment by 1 by default" do
@@ -90,21 +90,21 @@ describe Riak::Counter do
90
90
  {pb_port: "100#{n}7"}
91
91
  end
92
92
 
93
- @fake_pool = mock 'pool'
94
- @backend = mock 'backend'
93
+ @fake_pool = double 'pool'
94
+ @backend = double 'backend'
95
95
 
96
- @client = Riak::Client.new nodes: @nodes, protocol: 'pbc'
96
+ @client = Riak::Client.new nodes: @nodes
97
97
  @client.instance_variable_set :@protobuffs_pool, @fake_pool
98
98
 
99
- @fake_pool.stub(:take).and_yield(@backend)
99
+ allow(@fake_pool).to receive(:take).and_yield(@backend)
100
100
 
101
101
  @bucket = Riak::Bucket.allocate
102
- @bucket.stub allow_mult: true
103
- @bucket.stub client: @client
102
+ allow(@bucket).to receive(:allow_mult).and_return(true)
103
+ allow(@bucket).to receive(:client).and_return(@client)
104
104
 
105
105
  @key = 'key'
106
106
 
107
- @expect_post = @backend.should_receive(:post_counter).with(@bucket, @key, 1, {})
107
+ @expect_post = expect(@backend).to receive(:post_counter).with(@bucket, @key, 1, {})
108
108
 
109
109
  @ctr = Riak::Counter.new @bucket, @key
110
110
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require_relative 'shared_examples'
3
+
4
+ describe Riak::Crdt::Counter 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?).and_return(true)
9
+ end
10
+ end
11
+ it 'should be initialized with bucket, key, and optional bucket-type' do
12
+ expect{ described_class.new bucket, 'key' }.to_not raise_error
13
+ expect{ described_class.new bucket, 'key', 'type' }.to_not raise_error
14
+ end
15
+
16
+ subject{ described_class.new bucket, 'key' }
17
+
18
+ describe 'with a client' do
19
+ let(:response){ double 'response', key: nil }
20
+ let(:operator){ double 'operator' }
21
+ let(:backend){ double 'backend' }
22
+ let(:client){ double 'client' }
23
+
24
+ before(:each) do
25
+ allow(bucket).to receive(:client).and_return(client)
26
+ allow(client).to receive(:backend).and_yield(backend)
27
+ allow(backend).to receive(:crdt_operator).and_return(operator)
28
+ end
29
+
30
+ include_examples 'Counter CRDT'
31
+
32
+ it 'should batch properly' do
33
+ expect(operator).
34
+ to receive(:operate) { |bucket, key, type, operations|
35
+ expect(bucket).to eq bucket
36
+ expect(key).to eq 'key'
37
+ expect(type).to eq subject.bucket_type
38
+
39
+ expect(operations).to be_a Riak::Crdt::Operation::Update
40
+ expect(operations.value).to eq 5
41
+ }.
42
+ and_return(response)
43
+
44
+ subject.batch do |s|
45
+ s.increment 4 # 4
46
+ s.decrement 2 # 2
47
+ s.increment 4 # 6
48
+ s.decrement # 5
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +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 'should send increments to the parent' do
16
+ expect(parent).to receive(:increment).
17
+ with(counter_name, 1)
18
+
19
+ subject.increment
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Riak::Crdt::InnerFlag do
4
+ let(:parent){ double 'parent' }
5
+ describe 'a truthy flag' do
6
+ subject { described_class.new parent, true }
7
+
8
+ it 'should feel truthy' do
9
+ expect(subject).to be
10
+ end
11
+ end
12
+
13
+ describe 'a falsey flag' do
14
+ subject { described_class.new parent, false }
15
+
16
+ it 'should feel falsey' do
17
+ expect(subject).to_not be
18
+ end
19
+ end
20
+
21
+ describe 'updating' do
22
+ let(:new_value){ false }
23
+
24
+ it 'should ask the class for an update operation' do
25
+ operation = described_class.update(new_value)
26
+
27
+ expect(operation.value).to eq new_value
28
+ expect(operation.type).to eq :flag
29
+ end
30
+ end
31
+
32
+ describe 'deleting' do
33
+ it 'should ask the class for a delete operation' do
34
+ operation = described_class.delete
35
+
36
+ expect(operation.type).to eq :flag
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require_relative 'shared_examples'
3
+
4
+ describe Riak::Crdt::InnerMap do
5
+ let(:parent){ double 'parent' }
6
+ subject{ described_class.new parent, {} }
7
+
8
+ include_examples 'Map CRDT'
9
+
10
+ let(:populated_contents) do
11
+ {
12
+ counters: {alpha: 0},
13
+ flags: {bravo: true},
14
+ maps: {},
15
+ registers: {delta: 'the expendables' },
16
+ sets: {echo: %w{stallone statham li lundgren}}
17
+ }
18
+ end
19
+
20
+ it 'should be initializable with a nested hash of maps' do
21
+ expect{described_class.new parent, populated_contents}.
22
+ to_not raise_error
23
+ end
24
+
25
+ describe 'deleting the inner map' do
26
+ it 'should ask the class for a delete operation' do
27
+ operation = described_class.delete
28
+
29
+ expect(operation.type).to eq :map
30
+ end
31
+ end
32
+
33
+ describe 'receiving an operation' do
34
+ let(:inner_operation){ double 'inner operation' }
35
+ it 'should wrap the operation in an update operation and pass it to the parent' do
36
+ subject.name = 'name'
37
+
38
+ expect(parent).to receive(:operate) do |name, op|
39
+ expect(name).to eq 'name'
40
+ expect(op.type).to eq :map
41
+ expect(op.value).to eq inner_operation
42
+ end
43
+
44
+ subject.operate inner_operation
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Riak::Crdt::InnerRegister do
4
+ let(:parent){ double 'parent' }
5
+ subject { described_class.new parent, "espressos" }
6
+
7
+ it 'should feel like a string' do
8
+ expect(subject).to match 'espressos'
9
+ expect{ subject.gsub('s', 'x') }.to_not raise_error
10
+ expect(subject.gsub('s', 'x')).to eq 'exprexxox'
11
+ end
12
+
13
+ describe 'immutability' do
14
+ it 'should be frozen' do
15
+ expect(subject.frozen?).to be
16
+ end
17
+ it "shouldn't be gsub!-able" do
18
+ # "gsub!-able" is awful, open to suggestions
19
+ expect{ subject.gsub!('s', 'x') }.to raise_error
20
+ end
21
+ end
22
+
23
+ describe 'updating' do
24
+ let(:new_value){ 'new value' }
25
+ it "should ask the class for an update operation" do
26
+ operation = described_class.update(new_value)
27
+
28
+ expect(operation.value).to eq new_value
29
+ expect(operation.type).to eq :register
30
+ end
31
+ end
32
+
33
+ describe 'deleting' do
34
+ it 'should ask the class for a delete operation' do
35
+ operation = described_class.delete
36
+
37
+ expect(operation.type).to eq :register
38
+ end
39
+ end
40
+ end
@@ -0,0 +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 'should send 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
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require_relative 'shared_examples'
3
+
4
+ describe Riak::Crdt::Map 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?).and_return(true)
9
+ allow(b).to receive(:client).and_return(client)
10
+ end
11
+ end
12
+ let(:operator){ double 'operator' }
13
+ let(:loader){ double 'loader' }
14
+ let(:backend){ double 'backend' }
15
+ let(:client){ double 'client' }
16
+ let(:key){ 'map' }
17
+
18
+ before(:each) do
19
+ allow(client).to receive(:backend).and_yield(backend)
20
+ allow(backend).to receive(:crdt_operator).and_return(operator)
21
+ allow(backend).to receive(:crdt_loader).and_return(loader)
22
+ allow(loader).to receive(:load).and_return({})
23
+ allow(loader).to receive(:context).and_return('context')
24
+ end
25
+
26
+ subject{ described_class.new bucket, key }
27
+
28
+ include_examples 'Map CRDT'
29
+
30
+ describe 'batch mode' do
31
+ it 'should queue up operations' do
32
+ expect(operator).
33
+ to receive(:operate) do |bucket, key_arg, type, operations|
34
+
35
+ expect(bucket).to eq bucket
36
+ expect(key_arg).to eq key
37
+ expect(type).to eq subject.bucket_type
38
+
39
+ expect(operations.length).to eq 2
40
+
41
+ expect(operations.first).to be_a Riak::Crdt::Operation::Update
42
+
43
+ expect(operations.first.value).to be_a Riak::Crdt::Operation::Update
44
+ end
45
+
46
+ subject.batch do |s|
47
+ s.registers['hello'] = 'hello'
48
+ s.maps['goodbye'].flags['okay'] = true
49
+ end
50
+ end
51
+ end
52
+
53
+ describe 'immediate mode' do
54
+ it 'should submit member operations immediately' do
55
+ expect(operator).
56
+ to receive(:operate) do |bucket, key_arg, type, operations|
57
+
58
+ expect(bucket).to eq bucket
59
+ expect(key_arg).to eq key
60
+ expect(type).to eq subject.bucket_type
61
+
62
+ expect(operations.length).to eq 1
63
+
64
+ expect(operations.first).to be_a Riak::Crdt::Operation::Update
65
+
66
+ inner_op = operations.first.value
67
+
68
+ expect(inner_op).to be_a Riak::Crdt::Operation::Update
69
+ expect(inner_op.name).to eq 'hasta'
70
+ expect(inner_op.type).to eq :register
71
+ expect(inner_op.value).to eq 'la vista'
72
+ end
73
+
74
+ subject.registers['hasta'] = 'la vista' # baby
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,58 @@
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?).and_return(true)
9
+ end
10
+ end
11
+
12
+ it 'should be initialized with bucket, key, and optional bucket-type' do
13
+ expect{described_class.new bucket, 'key', 'optional bucket type'}.
14
+ to_not raise_error
15
+ end
16
+
17
+ subject{ described_class.new bucket, 'key' }
18
+
19
+ describe 'with a client' do
20
+ let(:response){ double 'response', key: nil }
21
+ let(:operator){ double 'operator' }
22
+ let(:backend){ double 'backend' }
23
+ let(:client){ double 'client' }
24
+
25
+ before(:each) do
26
+ allow(bucket).to receive(:client).and_return(client)
27
+ allow(client).to receive(:backend).and_yield(backend)
28
+ allow(backend).to receive(:crdt_operator).and_return(operator)
29
+ end
30
+
31
+ include_examples 'Set CRDT'
32
+
33
+ it 'should batch properly' do
34
+ expect(operator).
35
+ to receive(:operate) { |bucket, key, type, operations|
36
+
37
+ expect(bucket).to eq bucket
38
+ expect(key).to eq 'key'
39
+ expect(type).to eq subject.bucket_type
40
+
41
+ expect(operations).to be_a Riak::Crdt::Operation::Update
42
+ expect(operations.value).to eq({
43
+ add: %w{alpha bravo},
44
+ remove: %w{foxtrot}
45
+ })
46
+ }.
47
+ and_return(response)
48
+
49
+ subject.instance_variable_set :@context, 'placeholder'
50
+
51
+ subject.batch do |s|
52
+ s.add 'alpha'
53
+ s.add 'bravo'
54
+ s.remove 'foxtrot'
55
+ end
56
+ end
57
+ end
58
+ end