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
@@ -0,0 +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 "should allow 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 "should allow 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 "should have an index list" do
30
+ expect(@client.list_search_indexes.size).to be >= 1
31
+ end
32
+
33
+ it "should associate 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 "should index 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
@@ -0,0 +1,116 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+ require 'riak'
4
+
5
+ describe "Yokozuna queries", test_client: true, integration: true do
6
+ before :all do
7
+ @client = test_client
8
+ end
9
+
10
+ context "with a schema and indexes" do
11
+ before :all do
12
+ @bucket = random_bucket 'yz-spec'
13
+ @index = @bucket.name
14
+
15
+ expect(@client.create_search_index(@index)).to eq(true)
16
+ wait_until{ !@client.get_search_index(@index).nil? }
17
+ @client.set_bucket_props(@bucket, {:search_index => @index}, 'yokozuna')
18
+
19
+ wait_until do
20
+ props = @client.get_bucket_props(@bucket, type: 'yokozuna')
21
+ props['search_index'] == @index
22
+ end
23
+
24
+ @o1 = build_json_obj(@bucket, "cat", {"cat_s"=>"Lela"})
25
+ @o2 = build_json_obj(@bucket, "docs", {"dog_ss"=>["Einstein", "Olive"]})
26
+ build_json_obj(@bucket, "Z", {"username_s"=>"Z", "name_s"=>"ryan", "age_i"=>30})
27
+ build_json_obj(@bucket, "R", {"username_s"=>"R", "name_s"=>"eric", "age_i"=>34})
28
+ build_json_obj(@bucket, "F", {"username_s"=>"F", "name_s"=>"bryan fink", "age_i"=>32})
29
+ build_json_obj(@bucket, "H", {"username_s"=>"H", "name_s"=>"brett", "age_i"=>14})
30
+
31
+ wait_until { @client.search(@index, "username_s:Z")['docs'].length > 0 }
32
+ end
33
+
34
+ it "should produce results on single term queries" do
35
+ resp = @client.search(@index, "username_s:Z")
36
+ expect(resp).to include('docs')
37
+ expect(resp['docs'].size).to eq(1)
38
+ end
39
+
40
+ it "should produce results on multiple term queries" do
41
+ resp = @client.search(@index, "username_s:(F OR H)")
42
+ expect(resp).to include('docs')
43
+ expect(resp['docs'].size).to eq(2)
44
+ end
45
+
46
+ it "should produce results on queries with boolean logic" do
47
+ resp = @client.search(@index, "username_s:Z AND name_s:ryan")
48
+ expect(resp).to include('docs')
49
+ expect(resp['docs'].size).to eq(1)
50
+ end
51
+
52
+ it "should produce results on range queries" do
53
+ resp = @client.search(@index, "age_i:[30 TO 33]")
54
+ expect(resp).to include('docs')
55
+ expect(resp['docs'].size).to eq(2)
56
+ end
57
+
58
+ it "should produce results on phrase queries" do
59
+ resp = @client.search(@index, 'name_s:"bryan fink"')
60
+ expect(resp).to include('docs')
61
+ expect(resp['docs'].size).to eq(1)
62
+ end
63
+
64
+ it "should produce results on wildcard queries" do
65
+ resp = @client.search(@index, "name_s:*ryan*")
66
+ expect(resp).to include('docs')
67
+ expect(resp['docs'].size).to eq(2)
68
+ end
69
+
70
+ it "should produce results on regexp queries" do
71
+ resp = @client.search(@index, "name_s:/br.*/")
72
+ expect(resp).to include('docs')
73
+ expect(resp['docs'].size).to eq(2)
74
+ end
75
+
76
+ # TODO: run this when pb utf8 works
77
+ it "should support utf8" do
78
+ build_json_obj(@bucket, "ja", {"text_ja"=>"私はハイビスカスを食べるのが 大好き"})
79
+ # sleep 1.1 # pause for index commit to trigger
80
+ # resp = @client.search(@index, "text_ja:大好き")
81
+ # resp.should include('docs')
82
+ # resp['docs'].size.should == 1
83
+ end
84
+
85
+ context "using parameters" do
86
+ it "should search one row" do
87
+ resp = @client.search(@index, "*:*", {:rows => 1})
88
+ expect(resp).to include('docs')
89
+ expect(resp['docs'].size).to eq(1)
90
+ end
91
+
92
+ it "should search with df" do
93
+ resp = @client.search(@index, "Olive", {:rows => 1, :df => 'dog_ss'})
94
+ expect(resp).to include('docs')
95
+ expect(resp['docs'].size).to eq(1)
96
+ resp['docs'].first['dog_ss']
97
+ end
98
+
99
+ it "should produce top result on sort" do
100
+ resp = @client.search(@index, "username_s:*", {:sort => "age_i asc"})
101
+ expect(resp).to include('docs')
102
+ expect(resp['docs'].first['age_i'].to_i).to eq(14)
103
+ end
104
+
105
+ end
106
+ end
107
+
108
+ # populate objects
109
+ def build_json_obj(bucket, key, data)
110
+ object = bucket.get_or_new(key)
111
+ object.raw_data = data.to_json
112
+ object.content_type = 'application/json'
113
+ object.store type: 'yokozuna'
114
+ object
115
+ end
116
+ end
@@ -0,0 +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 'should allow 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 'should have 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
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+ Riak::Client::BeefcakeProtobuffsBackend.configured?
3
+
4
+ describe Riak::Client::BeefcakeProtobuffsBackend::CrdtOperator do
5
+
6
+ let(:backend_class){ Riak::Client::BeefcakeProtobuffsBackend }
7
+ let(:backend){ double 'beefcake protobuffs backend' }
8
+ subject { described_class.new backend }
9
+
10
+
11
+ describe 'operating on a counter' do
12
+ let(:increment){ 5 }
13
+ let(:operation) do
14
+ Riak::Crdt::Operation::Update.new.tap do |op|
15
+ op.type = :counter
16
+ op.value = increment
17
+ end
18
+ end
19
+
20
+ it 'should serialize a counter operation into protobuffs' do
21
+ result = subject.serialize operation
22
+
23
+ expect(result).to be_a backend_class::DtOp
24
+ expect(result.counter_op).to be_a backend_class::CounterOp
25
+ expect(result.counter_op.increment).to eq increment
26
+ end
27
+
28
+ it 'should serialize multiple counter operations into protobuffs' do
29
+ result = subject.serialize [operation, operation]
30
+
31
+ expect{result.encode}.to_not raise_error
32
+
33
+ expect(result).to be_a backend_class::DtOp
34
+ expect(result.counter_op).to be_a backend_class::CounterOp
35
+ expect(result.counter_op.increment).to eq (increment * 2)
36
+ end
37
+ end
38
+
39
+ describe 'operating on a set' do
40
+ let(:added_element){ 'added_element' }
41
+ let(:removed_element){ 'removed_element' }
42
+ let(:operation) do
43
+ Riak::Crdt::Operation::Update.new.tap do |op|
44
+ op.type = :set
45
+ op.value = {
46
+ add: [added_element],
47
+ remove: [removed_element]
48
+ }
49
+ end
50
+ end
51
+
52
+ it 'should serialize a set operation into protobuffs' do
53
+ result = subject.serialize operation
54
+
55
+ expect{result.encode}.to_not raise_error
56
+
57
+ expect(result).to be_a backend_class::DtOp
58
+ expect(result.set_op).to be_a backend_class::SetOp
59
+ expect(result.set_op.adds).to eq [added_element]
60
+ expect(result.set_op.removes).to eq [removed_element]
61
+ end
62
+ end
63
+
64
+ describe 'operating on a map' do
65
+ it 'should serialize inner counter operations' do
66
+ counter_op = Riak::Crdt::Operation::Update.new.tap do |op|
67
+ op.name = 'inner_counter'
68
+ op.type = :counter
69
+ op.value = 12345
70
+ end
71
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
72
+ op.type = :map
73
+ op.value = counter_op
74
+ end
75
+
76
+ result = subject.serialize map_op
77
+
78
+ expect{result.encode}.to_not raise_error
79
+
80
+ expect(result).to be_a backend_class::DtOp
81
+ expect(result.map_op).to be_a backend_class::MapOp
82
+ map_update = result.map_op.updates.first
83
+ expect(map_update).to be_a backend_class::MapUpdate
84
+ expect(map_update.counter_op).to be_a backend_class::CounterOp
85
+ expect(map_update.counter_op.increment).to eq 12345
86
+ end
87
+
88
+ it 'should serialize inner flag operations' do
89
+ flag_op = Riak::Crdt::Operation::Update.new.tap do |op|
90
+ op.name = 'inner_flag'
91
+ op.type = :flag
92
+ op.value = true
93
+ end
94
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
95
+ op.type = :map
96
+ op.value = flag_op
97
+ end
98
+
99
+ result = subject.serialize map_op
100
+
101
+ expect{result.encode}.to_not raise_error
102
+
103
+ expect(result).to be_a backend_class::DtOp
104
+ expect(result.map_op).to be_a backend_class::MapOp
105
+ map_update = result.map_op.updates.first
106
+ expect(map_update).to be_a backend_class::MapUpdate
107
+ expect(map_update.flag_op).to eq backend_class::MapUpdate::FlagOp::ENABLE
108
+
109
+ flag_op = Riak::Crdt::Operation::Update.new.tap do |op|
110
+ op.name = 'inner_flag'
111
+ op.type = :flag
112
+ op.value = false
113
+ end
114
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
115
+ op.type = :map
116
+ op.value = flag_op
117
+ end
118
+
119
+ result = subject.serialize map_op
120
+
121
+ expect{result.encode}.to_not raise_error
122
+
123
+ expect(result).to be_a backend_class::DtOp
124
+ expect(result.map_op).to be_a backend_class::MapOp
125
+ map_update = result.map_op.updates.first
126
+ expect(map_update).to be_a backend_class::MapUpdate
127
+ expect(map_update.flag_op).to eq backend_class::MapUpdate::FlagOp::DISABLE
128
+ end
129
+
130
+ it 'should serialize inner register operations' do
131
+ register_op = Riak::Crdt::Operation::Update.new.tap do |op|
132
+ op.name = 'inner_register'
133
+ op.type = :register
134
+ op.value = 'hello'
135
+ end
136
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
137
+ op.type = :map
138
+ op.value = register_op
139
+ end
140
+
141
+ result = subject.serialize map_op
142
+
143
+ expect{result.encode}.to_not raise_error
144
+
145
+ expect(result).to be_a backend_class::DtOp
146
+ expect(result.map_op).to be_a backend_class::MapOp
147
+ map_update = result.map_op.updates.first
148
+ expect(map_update).to be_a backend_class::MapUpdate
149
+ expect(map_update.register_op).to eq 'hello'
150
+
151
+ delete_op = Riak::Crdt::Operation::Delete.new.tap do |op|
152
+ op.name = 'inner_register'
153
+ op.type = :register
154
+ end
155
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
156
+ op.type = :map
157
+ op.value = delete_op
158
+ end
159
+
160
+ result = subject.serialize map_op
161
+
162
+ expect{ result.encode }.to_not raise_error
163
+
164
+ expect(result).to be_a backend_class::DtOp
165
+ expect(result.map_op).to be_a backend_class::MapOp
166
+ map_delete = result.map_op.removes.first
167
+ expect(map_delete).to be_a backend_class::MapField
168
+ expect(map_delete.name).to eq 'inner_register'
169
+ expect(map_delete.type).to eq backend_class::MapField::MapFieldType::REGISTER
170
+ end
171
+
172
+ it 'should serialize inner set operations' do
173
+ set_op = Riak::Crdt::Operation::Update.new.tap do |op|
174
+ op.name = 'inner_set'
175
+ op.type = :set
176
+ op.value = {add: 'added_member'}
177
+ end
178
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
179
+ op.type = :map
180
+ op.value = set_op
181
+ end
182
+
183
+ result = subject.serialize map_op
184
+
185
+ expect{result.encode}.to_not raise_error
186
+
187
+ expect(result).to be_a backend_class::DtOp
188
+ expect(result.map_op).to be_a backend_class::MapOp
189
+ map_update = result.map_op.updates.first
190
+ expect(map_update).to be_a backend_class::MapUpdate
191
+ expect(map_update.set_op.adds).to eq 'added_member'
192
+ end
193
+
194
+ it 'should serialize inner map operations' do
195
+ register_op = Riak::Crdt::Operation::Update.new.tap do |op|
196
+ op.name = 'inner_inner_register'
197
+ op.type = :register
198
+ op.value = 'inner_register_value'
199
+ end
200
+ inner_map_op = Riak::Crdt::Operation::Update.new.tap do |op|
201
+ op.name = 'inner_map'
202
+ op.type = :map
203
+ op.value = register_op
204
+ end
205
+ map_op = Riak::Crdt::Operation::Update.new.tap do |op|
206
+ op.type = :map
207
+ op.value = inner_map_op
208
+ end
209
+
210
+ result = subject.serialize map_op
211
+
212
+ expect{result.encode}.to_not raise_error
213
+
214
+ expect(result).to be_a backend_class::DtOp
215
+ expect(result.map_op).to be_a backend_class::MapOp
216
+ map_update = result.map_op.updates.first
217
+ expect(map_update).to be_a backend_class::MapUpdate
218
+ expect(map_update.map_op).to be_a backend_class::MapOp
219
+ expect(map_update.map_op.updates.first.register_op).to eq 'inner_register_value'
220
+ end
221
+ end
222
+ end