riak-client-noenc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +42 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +17 -0
  6. data/Guardfile +20 -0
  7. data/LICENSE.md +16 -0
  8. data/README.markdown +640 -0
  9. data/RELEASE_NOTES.md +392 -0
  10. data/Rakefile +119 -0
  11. data/lib/riak.rb +22 -0
  12. data/lib/riak/bucket.rb +297 -0
  13. data/lib/riak/bucket_properties.rb +74 -0
  14. data/lib/riak/bucket_type.rb +77 -0
  15. data/lib/riak/bucket_typed/bucket.rb +121 -0
  16. data/lib/riak/client.rb +433 -0
  17. data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
  18. data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -0
  19. data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -0
  20. data/lib/riak/client/beefcake/crdt/set_loader.rb +18 -0
  21. data/lib/riak/client/beefcake/crdt_loader.rb +84 -0
  22. data/lib/riak/client/beefcake/crdt_operator.rb +223 -0
  23. data/lib/riak/client/beefcake/footer +4 -0
  24. data/lib/riak/client/beefcake/header +6 -0
  25. data/lib/riak/client/beefcake/message_codes.rb +89 -0
  26. data/lib/riak/client/beefcake/message_overlay.rb +87 -0
  27. data/lib/riak/client/beefcake/messages.rb +772 -0
  28. data/lib/riak/client/beefcake/object_methods.rb +112 -0
  29. data/lib/riak/client/beefcake/protocol.rb +105 -0
  30. data/lib/riak/client/beefcake/socket.rb +260 -0
  31. data/lib/riak/client/beefcake_protobuffs_backend.rb +538 -0
  32. data/lib/riak/client/decaying.rb +36 -0
  33. data/lib/riak/client/feature_detection.rb +120 -0
  34. data/lib/riak/client/instrumentation.rb +19 -0
  35. data/lib/riak/client/node.rb +49 -0
  36. data/lib/riak/client/protobuffs_backend.rb +143 -0
  37. data/lib/riak/client/search.rb +27 -0
  38. data/lib/riak/client/yokozuna.rb +52 -0
  39. data/lib/riak/conflict.rb +13 -0
  40. data/lib/riak/core_ext.rb +7 -0
  41. data/lib/riak/core_ext/blank.rb +53 -0
  42. data/lib/riak/core_ext/deep_dup.rb +13 -0
  43. data/lib/riak/core_ext/extract_options.rb +7 -0
  44. data/lib/riak/core_ext/json.rb +15 -0
  45. data/lib/riak/core_ext/slice.rb +18 -0
  46. data/lib/riak/core_ext/stringify_keys.rb +10 -0
  47. data/lib/riak/core_ext/symbolize_keys.rb +10 -0
  48. data/lib/riak/core_ext/to_param.rb +31 -0
  49. data/lib/riak/counter.rb +101 -0
  50. data/lib/riak/crdt.rb +21 -0
  51. data/lib/riak/crdt/base.rb +183 -0
  52. data/lib/riak/crdt/batch_counter.rb +19 -0
  53. data/lib/riak/crdt/batch_map.rb +41 -0
  54. data/lib/riak/crdt/counter.rb +82 -0
  55. data/lib/riak/crdt/inner_counter.rb +81 -0
  56. data/lib/riak/crdt/inner_flag.rb +42 -0
  57. data/lib/riak/crdt/inner_map.rb +75 -0
  58. data/lib/riak/crdt/inner_register.rb +26 -0
  59. data/lib/riak/crdt/inner_set.rb +102 -0
  60. data/lib/riak/crdt/map.rb +121 -0
  61. data/lib/riak/crdt/operation.rb +19 -0
  62. data/lib/riak/crdt/set.rb +166 -0
  63. data/lib/riak/crdt/typed_collection.rb +181 -0
  64. data/lib/riak/encoding.rb +6 -0
  65. data/lib/riak/errors/backend_creation.rb +9 -0
  66. data/lib/riak/errors/base.rb +9 -0
  67. data/lib/riak/errors/connection_error.rb +50 -0
  68. data/lib/riak/errors/crdt_error.rb +38 -0
  69. data/lib/riak/errors/failed_request.rb +58 -0
  70. data/lib/riak/errors/protobuffs_error.rb +11 -0
  71. data/lib/riak/errors/search_error.rb +35 -0
  72. data/lib/riak/i18n.rb +7 -0
  73. data/lib/riak/index_collection.rb +71 -0
  74. data/lib/riak/instrumentation.rb +6 -0
  75. data/lib/riak/json.rb +52 -0
  76. data/lib/riak/link.rb +96 -0
  77. data/lib/riak/list_buckets.rb +28 -0
  78. data/lib/riak/locale/en.yml +107 -0
  79. data/lib/riak/locale/fr.yml +51 -0
  80. data/lib/riak/map_reduce.rb +295 -0
  81. data/lib/riak/map_reduce/filter_builder.rb +103 -0
  82. data/lib/riak/map_reduce/phase.rb +98 -0
  83. data/lib/riak/map_reduce/results.rb +49 -0
  84. data/lib/riak/map_reduce_error.rb +7 -0
  85. data/lib/riak/multiget.rb +122 -0
  86. data/lib/riak/preflist_item.rb +7 -0
  87. data/lib/riak/rcontent.rb +173 -0
  88. data/lib/riak/robject.rb +222 -0
  89. data/lib/riak/search.rb +11 -0
  90. data/lib/riak/search/index.rb +87 -0
  91. data/lib/riak/search/query.rb +141 -0
  92. data/lib/riak/search/result_collection.rb +144 -0
  93. data/lib/riak/search/result_document.rb +129 -0
  94. data/lib/riak/search/schema.rb +65 -0
  95. data/lib/riak/secondary_index.rb +81 -0
  96. data/lib/riak/serializers.rb +73 -0
  97. data/lib/riak/stamp.rb +77 -0
  98. data/lib/riak/util/escape.rb +80 -0
  99. data/lib/riak/util/tcp_socket_extensions.rb +58 -0
  100. data/lib/riak/util/translation.rb +18 -0
  101. data/lib/riak/version.rb +3 -0
  102. data/lib/riak/walk_spec.rb +145 -0
  103. data/spec/failover/failover.rb +59 -0
  104. data/spec/fixtures/bitcask.txt +25 -0
  105. data/spec/fixtures/cat.jpg +0 -0
  106. data/spec/fixtures/multipart-basic-conflict.txt +15 -0
  107. data/spec/fixtures/multipart-blank.txt +7 -0
  108. data/spec/fixtures/multipart-mapreduce.txt +10 -0
  109. data/spec/fixtures/multipart-with-body.txt +16 -0
  110. data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
  111. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
  112. data/spec/fixtures/server.cert.crt +15 -0
  113. data/spec/fixtures/server.cert.key +15 -0
  114. data/spec/fixtures/test.pem +1 -0
  115. data/spec/fixtures/yz_schema_template.xml +18 -0
  116. data/spec/integration/riak/bucket_types_spec.rb +270 -0
  117. data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
  118. data/spec/integration/riak/counters_spec.rb +36 -0
  119. data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
  120. data/spec/integration/riak/crdt_search_spec.rb +176 -0
  121. data/spec/integration/riak/crdt_spec.rb +250 -0
  122. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  123. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  124. data/spec/integration/riak/preflist_spec.rb +31 -0
  125. data/spec/integration/riak/properties_spec.rb +69 -0
  126. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +33 -0
  127. data/spec/integration/riak/protobuffs_backends_spec.rb +40 -0
  128. data/spec/integration/riak/search_spec.rb +104 -0
  129. data/spec/integration/riak/secondary_index_spec.rb +72 -0
  130. data/spec/integration/riak/security_spec.rb +100 -0
  131. data/spec/integration/riak/threading_spec.rb +150 -0
  132. data/spec/integration/yokozuna/index_spec.rb +61 -0
  133. data/spec/integration/yokozuna/queries_spec.rb +115 -0
  134. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  135. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
  136. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  137. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
  138. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  139. data/spec/riak/beefcake_protobuffs_backend_spec.rb +162 -0
  140. data/spec/riak/bucket_properties_spec.rb +135 -0
  141. data/spec/riak/bucket_spec.rb +275 -0
  142. data/spec/riak/bucket_type_spec.rb +50 -0
  143. data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
  144. data/spec/riak/client_spec.rb +246 -0
  145. data/spec/riak/core_ext/to_param_spec.rb +15 -0
  146. data/spec/riak/counter_spec.rb +122 -0
  147. data/spec/riak/crdt/counter_spec.rb +55 -0
  148. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  149. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  150. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  151. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  152. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  153. data/spec/riak/crdt/map_spec.rb +78 -0
  154. data/spec/riak/crdt/set_spec.rb +61 -0
  155. data/spec/riak/crdt/shared_examples.rb +74 -0
  156. data/spec/riak/crdt/typed_collection_spec.rb +225 -0
  157. data/spec/riak/escape_spec.rb +72 -0
  158. data/spec/riak/feature_detection_spec.rb +77 -0
  159. data/spec/riak/index_collection_spec.rb +53 -0
  160. data/spec/riak/instrumentation_spec.rb +124 -0
  161. data/spec/riak/link_spec.rb +85 -0
  162. data/spec/riak/list_buckets_spec.rb +41 -0
  163. data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
  164. data/spec/riak/map_reduce/phase_spec.rb +142 -0
  165. data/spec/riak/map_reduce_spec.rb +434 -0
  166. data/spec/riak/multiget_spec.rb +81 -0
  167. data/spec/riak/node_spec.rb +26 -0
  168. data/spec/riak/robject_spec.rb +496 -0
  169. data/spec/riak/search/index_spec.rb +72 -0
  170. data/spec/riak/search/query_spec.rb +88 -0
  171. data/spec/riak/search/result_collection_spec.rb +89 -0
  172. data/spec/riak/search/result_document_spec.rb +106 -0
  173. data/spec/riak/search/schema_spec.rb +63 -0
  174. data/spec/riak/search_spec.rb +107 -0
  175. data/spec/riak/secondary_index_spec.rb +225 -0
  176. data/spec/riak/serializers_spec.rb +121 -0
  177. data/spec/riak/stamp_spec.rb +54 -0
  178. data/spec/riak/walk_spec_spec.rb +203 -0
  179. data/spec/spec_helper.rb +66 -0
  180. data/spec/support/certs/README.md +13 -0
  181. data/spec/support/certs/ca.crt +21 -0
  182. data/spec/support/certs/client.crl +13 -0
  183. data/spec/support/certs/client.crt +94 -0
  184. data/spec/support/certs/client.csr +18 -0
  185. data/spec/support/certs/client.key +27 -0
  186. data/spec/support/certs/empty_ca.crt +21 -0
  187. data/spec/support/certs/server.crl +13 -0
  188. data/spec/support/certs/server.crt +94 -0
  189. data/spec/support/certs/server.key +27 -0
  190. data/spec/support/crdt_search_config.rb +112 -0
  191. data/spec/support/crdt_search_fixtures.rb +42 -0
  192. data/spec/support/integration_setup.rb +10 -0
  193. data/spec/support/search_config.rb +83 -0
  194. data/spec/support/search_corpus_setup.rb +39 -0
  195. data/spec/support/test_client.rb +46 -0
  196. data/spec/support/test_client.yml.example +10 -0
  197. data/spec/support/unified_backend_examples.rb +380 -0
  198. data/spec/support/version_filter.rb +12 -0
  199. data/spec/support/wait_until.rb +20 -0
  200. metadata +511 -0
@@ -0,0 +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
@@ -0,0 +1,74 @@
1
+ shared_examples_for "Map CRDT" do
2
+ let(:typed_collection){ Riak::Crdt::TypedCollection }
3
+
4
+ it 'contains counters' do
5
+ expect(subject).to respond_to(:counters)
6
+ expect(subject.counters).to be_an_instance_of typed_collection
7
+ end
8
+
9
+ it 'contains flags' do
10
+ expect(subject).to respond_to(:flags)
11
+ expect(subject.counters).to be_an_instance_of typed_collection
12
+ end
13
+
14
+ it 'contains maps' do
15
+ expect(subject).to respond_to(:maps)
16
+ expect(subject.counters).to be_an_instance_of typed_collection
17
+ end
18
+
19
+ it 'contains registers' do
20
+ expect(subject).to respond_to(:registers)
21
+ expect(subject.counters).to be_an_instance_of typed_collection
22
+ end
23
+
24
+ it 'contains sets' do
25
+ expect(subject).to respond_to(:sets)
26
+ expect(subject.counters).to be_an_instance_of typed_collection
27
+ end
28
+
29
+ it 'accepts operations' do
30
+ expect(subject).to respond_to(:operate)
31
+ end
32
+ end
33
+
34
+ shared_examples_for "Counter CRDT" do
35
+ it 'has a value' do
36
+ expect(subject).to respond_to :value
37
+ end
38
+
39
+ it 'has an increment method' do
40
+ expect(subject).to respond_to :increment
41
+ end
42
+
43
+ it 'has a decrement method' do
44
+ expect(subject).to respond_to :decrement
45
+ end
46
+
47
+ it 'has a batch method' do
48
+ expect(subject).to respond_to :batch
49
+ end
50
+ end
51
+
52
+ shared_examples_for 'Set CRDT' do
53
+ it 'has a value' do
54
+ expect(subject).to respond_to :value
55
+ expect(subject).to respond_to :members
56
+ expect(subject).to respond_to :to_a
57
+ end
58
+
59
+ it 'has an include? method' do
60
+ expect(subject).to respond_to :include?
61
+ end
62
+
63
+ it 'has an empty? method' do
64
+ expect(subject).to respond_to :empty?
65
+ end
66
+
67
+ it 'has an add method' do
68
+ expect(subject).to respond_to :add
69
+ end
70
+
71
+ it 'has a remove method' do
72
+ expect(subject).to respond_to :remove
73
+ end
74
+ end
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ describe Riak::Crdt::TypedCollection do
4
+ let(:parent){ double 'parent' }
5
+ let(:operation){ double 'operation' }
6
+
7
+ describe 'initialization' do
8
+ it "accepts a type, parent, and hash of values" do
9
+ expect{ described_class.new Riak::Crdt::Counter, parent, {} }.to_not raise_error
10
+ end
11
+ end
12
+
13
+ describe 'containing' do
14
+ describe 'registers' do
15
+ let(:register_class){ Riak::Crdt::InnerRegister }
16
+ subject do
17
+ described_class.new register_class, parent, existing: 'existing'
18
+ end
19
+
20
+ it 'exposes them as frozen strings that are really Registers' do
21
+ expect(subject[:existing]).to eq 'existing'
22
+ expect(subject['existing']).to eq 'existing'
23
+ expect(subject[:existing]).to be_an_instance_of register_class
24
+ expect(subject['existing'].frozen?).to be
25
+ expect{subject['existing'].gsub!('e', 'a')}.to raise_error
26
+ end
27
+
28
+ describe 'creating and updating' do
29
+
30
+ let(:new_value){ 'the new value' }
31
+
32
+ it 'asks the register class for an operation' do
33
+ expect(register_class).to receive(:update).
34
+ with(new_value).
35
+ and_return(operation)
36
+
37
+ expect(operation).
38
+ to receive(:name=).
39
+ with('existing')
40
+
41
+ expect(parent).
42
+ to receive(:operate).
43
+ with(operation)
44
+
45
+ subject['existing'] = new_value
46
+ end
47
+ end
48
+
49
+ describe 'removing' do
50
+
51
+ it 'asks the register class for a remove operation' do
52
+ expect(register_class).
53
+ to receive(:delete).
54
+ and_return(operation)
55
+
56
+ expect(operation).
57
+ to receive(:name=).
58
+ with('existing')
59
+
60
+ expect(parent).
61
+ to receive(:operate).
62
+ with(operation)
63
+
64
+ subject.delete 'existing'
65
+ end
66
+ end
67
+ end
68
+ describe 'flags' do
69
+ let(:flag_class){ Riak::Crdt::InnerFlag }
70
+ subject do
71
+ described_class.new flag_class, parent, truthy: true, falsey: false
72
+ end
73
+
74
+ it 'exposes them as booleans' do
75
+ expect(subject[:truthy]).to eq true
76
+ expect(subject['falsey']).to eq false
77
+ end
78
+
79
+ it 'updates them' do
80
+ expect(flag_class).
81
+ to receive(:update).
82
+ with(true).
83
+ and_return(operation)
84
+
85
+ expect(operation).
86
+ to receive(:name=).
87
+ with('become_truthy')
88
+
89
+ expect(parent).
90
+ to receive(:operate).
91
+ with(operation)
92
+
93
+ subject['become_truthy'] = true
94
+ end
95
+
96
+ it 'deletes them' do
97
+ expect(flag_class).
98
+ to receive(:delete).
99
+ and_return(operation)
100
+
101
+ expect(operation).
102
+ to receive(:name=).
103
+ with('become_deleted')
104
+
105
+ expect(parent).
106
+ to receive(:operate).
107
+ with(operation)
108
+
109
+ subject.delete 'become_deleted'
110
+ end
111
+ end
112
+ describe 'counters' do
113
+ let(:counter_class){ Riak::Crdt::InnerCounter }
114
+
115
+ subject{ described_class.new counter_class, parent, zero: 0, one: 1 }
116
+
117
+ it 'exposes existing ones as Counter instances' do
118
+ expect(subject['zero']).to be_an_instance_of counter_class
119
+ expect(subject['zero'].to_i).to eq 0
120
+
121
+ expect(subject['one'].to_i).to eq 1
122
+ end
123
+
124
+ it 'exposes new ones as Counter instances' do
125
+ expect(subject['new_zero']).to be_an_instance_of counter_class
126
+ expect(subject['new_zero'].to_i).to eq 0
127
+ end
128
+
129
+ it 'allows incrementing and decrementing' do
130
+ counter_name = 'counter'
131
+
132
+ expect(parent).to receive(:operate) do |op|
133
+ expect(op.name).to eq counter_name
134
+ expect(op.type).to eq :counter
135
+ expect(op.value).to eq 1
136
+ end
137
+ subject[counter_name].increment
138
+
139
+ expect(parent).to receive(:operate) do |op|
140
+ expect(op.name).to eq counter_name
141
+ expect(op.type).to eq :counter
142
+ expect(op.value).to eq -5
143
+ end
144
+
145
+ subject[counter_name].decrement 5
146
+ end
147
+ end
148
+ describe 'sets' do
149
+ let(:set_class){ Riak::Crdt::InnerSet }
150
+
151
+ subject{ described_class.new set_class, parent, brewers: %w{aeropress clever v60}}
152
+
153
+ it 'exposes existing ones as Set instances' do
154
+ expect(subject['brewers']).to be_an_instance_of set_class
155
+ expect(subject['brewers']).to include 'aeropress'
156
+ end
157
+
158
+ it 'exposes new ones as empty Set instances' do
159
+ expect(subject['filters']).to be_an_instance_of set_class
160
+ expect(subject['filters']).to be_empty
161
+ end
162
+
163
+ it 'allows adding and removing' do
164
+ set_name = 'brewers'
165
+
166
+ expect(parent).to receive(:operate) do |op|
167
+ expect(op.name).to eq set_name
168
+ expect(op.type).to eq :set
169
+ expect(op.value).to eq add: 'frenchpress'
170
+ end
171
+ subject[set_name].add 'frenchpress'
172
+
173
+ expect(parent).to receive(:operate) do |op|
174
+ expect(op.name).to eq set_name
175
+ expect(op.type).to eq :set
176
+ expect(op.value).to eq remove: 'aeropress'
177
+ end
178
+ allow(parent).to receive(:context?).and_return(true)
179
+
180
+ subject[set_name].remove 'aeropress'
181
+ end
182
+ end
183
+
184
+ describe 'maps' do
185
+ let(:map_class){ Riak::Crdt::InnerMap }
186
+
187
+ let(:contents) do {a: {
188
+ counters: {},
189
+ flags: {},
190
+ maps: {},
191
+ registers: {'hello' => 'world'},
192
+ sets: {}
193
+ }}
194
+ end
195
+
196
+ let(:inner_map_name){ 'inner map' }
197
+
198
+ subject do
199
+ described_class.new map_class, parent, contents
200
+ end
201
+
202
+ it 'exposes existing ones as populated Map instances' do
203
+ expect(subject['a']).to be_an_instance_of map_class
204
+ expect(subject['a'].registers['hello']).to eq 'world'
205
+ end
206
+
207
+ it 'exposes new ones as empty Map instances' do
208
+ expect(subject['b']).to be_an_instance_of map_class
209
+ expect(subject['b'].registers['hello']).to be_nil
210
+ end
211
+
212
+ it 'cascades operations to a parent map' do
213
+ expect(operation).
214
+ to receive(:name=).
215
+ with(inner_map_name)
216
+
217
+ expect(parent).
218
+ to receive(:operate).
219
+ with(operation)
220
+
221
+ subject.operate inner_map_name, operation
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,72 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Riak::Util::Escape do
5
+ before :each do
6
+ @object = Object.new
7
+ @object.extend(Riak::Util::Escape)
8
+ end
9
+
10
+ it "uses URI by default for escaping" do
11
+ expect(Riak.escaper).to eq(URI)
12
+ end
13
+
14
+ context "when using CGI for escaping" do
15
+ before { @oldesc, Riak.escaper = Riak.escaper, CGI }
16
+ after { Riak.escaper = @oldesc }
17
+
18
+ it "escapes standard non-safe characters" do
19
+ expect(@object.escape("some string")).to eq("some%20string")
20
+ expect(@object.escape("another^one")).to eq("another%5Eone")
21
+ expect(@object.escape("bracket[one")).to eq("bracket%5Bone")
22
+ end
23
+
24
+ it "escapes slashes" do
25
+ expect(@object.escape("some/inner/path")).to eq("some%2Finner%2Fpath")
26
+ end
27
+
28
+ it "converts the bucket or key to a string before escaping" do
29
+ expect(@object.escape(125)).to eq('125')
30
+ end
31
+
32
+ it "unescapes escaped strings" do
33
+ expect(@object.unescape("some%20string")).to eq("some string")
34
+ expect(@object.unescape("another%5Eone")).to eq("another^one")
35
+ expect(@object.unescape("bracket%5Bone")).to eq("bracket[one")
36
+ expect(@object.unescape("some%2Finner%2Fpath")).to eq("some/inner/path")
37
+ end
38
+ end
39
+
40
+ context "when using URI for escaping" do
41
+ before { @oldesc, Riak.escaper = Riak.escaper, URI }
42
+ after { Riak.escaper = @oldesc }
43
+
44
+ it "escapes standard non-safe characters" do
45
+ expect(@object.escape("some string")).to eq("some%20string")
46
+ expect(@object.escape("another^one")).to eq("another%5Eone")
47
+ expect(@object.escape("--one+two--")).to eq("--one%2Btwo--")
48
+ end
49
+
50
+ it "allows URI-safe characters" do
51
+ expect(@object.escape("bracket[one")).to eq("bracket[one")
52
+ expect(@object.escape("sean@basho")).to eq("sean@basho")
53
+ end
54
+
55
+ it "escapes slashes" do
56
+ expect(@object.escape("some/inner/path")).to eq("some%2Finner%2Fpath")
57
+ end
58
+
59
+ it "converts the bucket or key to a string before escaping" do
60
+ expect(@object.escape(125)).to eq('125')
61
+ end
62
+
63
+ it "unescapes escaped strings" do
64
+ expect(@object.unescape("some%20string")).to eq("some string")
65
+ expect(@object.unescape("another%5Eone")).to eq("another^one")
66
+ expect(@object.unescape("bracket%5Bone")).to eq("bracket[one")
67
+ expect(@object.unescape("some%2Finner%2Fpath")).to eq("some/inner/path")
68
+ expect(@object.unescape("--one%2Btwo--")).to eq("--one+two--")
69
+ expect(@object.unescape("me%40basho.co")).to eq("me@basho.co")
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'riak/client/feature_detection'
3
+
4
+ describe Riak::Client::FeatureDetection do
5
+ let(:klass) {
6
+ Class.new do
7
+ include Riak::Client::FeatureDetection
8
+ end
9
+ }
10
+ subject { klass.new }
11
+
12
+ context "when the get_server_version is unimplemented" do
13
+ it "raises a NotImplementedError" do
14
+ expect { subject.server_version }.to raise_error(NotImplementedError)
15
+ end
16
+ end
17
+
18
+ context "when the Riak version is 0.14.x" do
19
+ before { allow(subject).to receive(:get_server_version).and_return("0.14.2") }
20
+ it { is_expected.not_to be_mapred_phaseless }
21
+ it { is_expected.not_to be_pb_indexes }
22
+ it { is_expected.not_to be_pb_search }
23
+ it { is_expected.not_to be_pb_conditionals }
24
+ it { is_expected.not_to be_quorum_controls }
25
+ it { is_expected.not_to be_tombstone_vclocks }
26
+ it { is_expected.not_to be_pb_head }
27
+ it { is_expected.not_to be_http_props_clearable }
28
+ end
29
+
30
+ context "when the Riak version is 1.0.x" do
31
+ before { allow(subject).to receive(:get_server_version).and_return("1.0.3") }
32
+ it { is_expected.not_to be_mapred_phaseless }
33
+ it { is_expected.not_to be_pb_indexes }
34
+ it { is_expected.not_to be_pb_search }
35
+ it { is_expected.to be_pb_conditionals }
36
+ it { is_expected.to be_quorum_controls }
37
+ it { is_expected.to be_tombstone_vclocks }
38
+ it { is_expected.to be_pb_head }
39
+ it { is_expected.not_to be_http_props_clearable }
40
+ end
41
+
42
+ context "when the Riak version is 1.1.x" do
43
+ before { allow(subject).to receive(:get_server_version).and_return("1.1.4") }
44
+ it { is_expected.to be_mapred_phaseless }
45
+ it { is_expected.not_to be_pb_indexes }
46
+ it { is_expected.not_to be_pb_search }
47
+ it { is_expected.to be_pb_conditionals }
48
+ it { is_expected.to be_quorum_controls }
49
+ it { is_expected.to be_tombstone_vclocks }
50
+ it { is_expected.to be_pb_head }
51
+ it { is_expected.not_to be_http_props_clearable }
52
+ end
53
+
54
+ context "when the Riak version is 1.2.x" do
55
+ before { allow(subject).to receive(:get_server_version).and_return("1.2.1") }
56
+ it { is_expected.to be_mapred_phaseless }
57
+ it { is_expected.to be_pb_indexes }
58
+ it { is_expected.to be_pb_search }
59
+ it { is_expected.to be_pb_conditionals }
60
+ it { is_expected.to be_quorum_controls }
61
+ it { is_expected.to be_tombstone_vclocks }
62
+ it { is_expected.to be_pb_head }
63
+ it { is_expected.not_to be_http_props_clearable }
64
+ end
65
+
66
+ context "when the Riak version is 1.3.x" do
67
+ before { allow(subject).to receive(:get_server_version).and_return("1.3.0") }
68
+ it { is_expected.to be_mapred_phaseless }
69
+ it { is_expected.to be_pb_indexes }
70
+ it { is_expected.to be_pb_search }
71
+ it { is_expected.to be_pb_conditionals }
72
+ it { is_expected.to be_quorum_controls }
73
+ it { is_expected.to be_tombstone_vclocks }
74
+ it { is_expected.to be_pb_head }
75
+ it { is_expected.to be_http_props_clearable }
76
+ end
77
+ end