riak-client 2.1.0 → 2.2.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Guardfile +15 -9
  4. data/README.markdown +118 -9
  5. data/lib/riak/bucket.rb +16 -1
  6. data/lib/riak/bucket_properties.rb +67 -0
  7. data/lib/riak/bucket_type.rb +48 -0
  8. data/lib/riak/bucket_typed/bucket.rb +113 -0
  9. data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
  10. data/lib/riak/client/beefcake/message_overlay.rb +42 -20
  11. data/lib/riak/client/beefcake/object_methods.rb +1 -1
  12. data/lib/riak/client/beefcake/socket.rb +6 -6
  13. data/lib/riak/client/beefcake_protobuffs_backend.rb +44 -60
  14. data/lib/riak/client/protobuffs_backend.rb +8 -8
  15. data/lib/riak/client.rb +7 -2
  16. data/lib/riak/crdt/base.rb +29 -1
  17. data/lib/riak/crdt/counter.rb +7 -3
  18. data/lib/riak/crdt/inner_flag.rb +1 -1
  19. data/lib/riak/crdt/map.rb +7 -3
  20. data/lib/riak/crdt/set.rb +7 -4
  21. data/lib/riak/errors/failed_request.rb +2 -0
  22. data/lib/riak/errors/search_error.rb +29 -0
  23. data/lib/riak/locale/en.yml +7 -0
  24. data/lib/riak/map_reduce.rb +70 -6
  25. data/lib/riak/robject.rb +19 -3
  26. data/lib/riak/search/index.rb +73 -0
  27. data/lib/riak/search/query.rb +133 -0
  28. data/lib/riak/search/result_collection.rb +91 -0
  29. data/lib/riak/search/result_document.rb +59 -0
  30. data/lib/riak/search/schema.rb +65 -0
  31. data/lib/riak/search.rb +10 -0
  32. data/lib/riak/secondary_index.rb +6 -0
  33. data/lib/riak/version.rb +1 -1
  34. data/spec/fixtures/yz_schema_template.xml +18 -0
  35. data/spec/integration/riak/bucket_types_spec.rb +218 -39
  36. data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
  37. data/spec/integration/riak/crdt_spec.rb +30 -2
  38. data/spec/integration/riak/properties_spec.rb +69 -0
  39. data/spec/integration/riak/search_spec.rb +104 -0
  40. data/spec/integration/riak/secondary_index_spec.rb +18 -0
  41. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
  42. data/spec/riak/bucket_properties_spec.rb +114 -0
  43. data/spec/riak/bucket_type_spec.rb +34 -0
  44. data/spec/riak/bucket_typed/bucket.rb +43 -0
  45. data/spec/riak/client_spec.rb +16 -8
  46. data/spec/riak/crdt/counter_spec.rb +2 -1
  47. data/spec/riak/crdt/map_spec.rb +2 -1
  48. data/spec/riak/crdt/set_spec.rb +2 -1
  49. data/spec/riak/map_reduce_spec.rb +169 -124
  50. data/spec/riak/search/index_spec.rb +62 -0
  51. data/spec/riak/search/query_spec.rb +88 -0
  52. data/spec/riak/search/result_collection_spec.rb +87 -0
  53. data/spec/riak/search/result_document_spec.rb +63 -0
  54. data/spec/riak/search/schema_spec.rb +63 -0
  55. data/spec/spec_helper.rb +2 -1
  56. data/spec/support/search_config.rb +81 -0
  57. data/spec/support/test_client.yml +14 -7
  58. metadata +44 -5
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require 'riak/search/result_collection'
3
+
4
+ describe Riak::Search::ResultCollection do
5
+ let(:client) do
6
+ instance_double('Riak::Client').tap do |c|
7
+ allow(c).to receive(:bucket_type).
8
+ with(bucket_type_name).
9
+ and_return(bucket_type)
10
+ end
11
+ end
12
+
13
+ let(:bucket_type) do
14
+ instance_double('Riak::BucketType').tap do |bt|
15
+ allow(bt).to receive(:bucket).
16
+ with(bucket_name).
17
+ and_return(bucket)
18
+ end
19
+ end
20
+
21
+ let(:bucket) do
22
+ instance_double('Riak::BucketTyped::Bucket')
23
+ end
24
+
25
+ let(:backend) do
26
+ instance_double('Riak::Client::BeefcakeProtobuffsBackend').tap do |be|
27
+ allow(client).to receive(:backend).and_yield(be)
28
+ end
29
+ end
30
+
31
+ let(:results_hash) do
32
+ {
33
+ "max_score"=>0.7729485034942627,
34
+ "num_found"=>3,
35
+ "docs"=>[
36
+ {"score"=>"7.72948500000000038312e-01",
37
+ "_yz_rb"=>"search_test-1419261439-ew70sak2qr",
38
+ "_yz_rt"=>"yokozuna",
39
+ "_yz_rk"=>"bitcask-10"},
40
+ {"score"=>"2.35808490000000009479e-01",
41
+ "_yz_rb"=>"search_test-1419261439-ew70sak2qr",
42
+ "_yz_rt"=>"yokozuna",
43
+ "_yz_rk"=>"bitcask-9"},
44
+ {"score"=>"6.73738599999999937529e-02",
45
+ "_yz_rb"=>"search_test-1419261439-ew70sak2qr",
46
+ "_yz_rt"=>"yokozuna",
47
+ "_yz_rk"=>"bitcask-4"}
48
+ ]
49
+ }
50
+ end
51
+
52
+ let(:bucket_name){ 'search_test-1419261439-ew70sak2qr' }
53
+ let(:bucket_type_name){ 'yokozuna' }
54
+ let(:first_key){ 'bitcask-10' }
55
+ let(:first_result) do
56
+ instance_double('Riak::RObject').tap do |o|
57
+ allow(o).to receive(:key).and_return(first_key)
58
+ end
59
+ end
60
+
61
+ let(:fetch_first_expectation) do
62
+ expect(bucket).to receive(:get).with(first_key).and_return(first_result)
63
+ end
64
+
65
+ subject{ described_class.new client, results_hash }
66
+
67
+ it 'is creatable with a search results hash' do
68
+ expect{ described_class.new client, results_hash }.to_not raise_error
69
+ end
70
+
71
+ it 'exposes the raw search results hash' do
72
+ expect(subject.raw).to eq results_hash
73
+ end
74
+
75
+ it 'exposes the max score and entry scores' do
76
+ expect(subject.max_score).to eq results_hash['max_score']
77
+ expect(subject.docs.first.score).to eq Float(
78
+ results_hash['docs'].
79
+ first['score'])
80
+ end
81
+
82
+ it 'fetches individual documents on demand' do
83
+ fetch_first_expectation
84
+
85
+ expect(subject.first).to eq first_result
86
+ end
87
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'riak/search/result_document'
3
+
4
+ describe Riak::Search::ResultDocument do
5
+ let(:key){ 'bitcask-10' }
6
+ let(:bucket_name){ 'search_test' }
7
+ let(:bucket_type_name){ 'yokozuna' }
8
+ let(:score){ 43.21 }
9
+ let(:other_field){ 'banana' }
10
+
11
+ let(:client) do
12
+ instance_double('Riak::Client').tap do |c|
13
+ allow(c).to receive(:bucket_type).
14
+ with(bucket_type_name).
15
+ and_return(bucket_type)
16
+ end
17
+ end
18
+
19
+ let(:bucket_type) do
20
+ instance_double('Riak::BucketType').tap do |bt|
21
+ allow(bt).to receive(:bucket).
22
+ with(bucket_name).
23
+ and_return(bucket)
24
+ end
25
+ end
26
+
27
+ let(:bucket) do
28
+ instance_double('Riak::BucketTyped::Bucket').tap do |b|
29
+ allow(b).to receive(:get).
30
+ with(key).
31
+ and_return(robject)
32
+ end
33
+ end
34
+
35
+ let(:robject){ instance_double 'Riak::RObject' }
36
+
37
+ let(:raw) do
38
+ {
39
+ "score"=>score,
40
+ "_yz_rb"=>bucket_name,
41
+ "_yz_rt"=>bucket_type_name,
42
+ "_yz_rk"=>key,
43
+ 'other_field'=>other_field
44
+ }
45
+ end
46
+
47
+ subject{ described_class.new client, raw }
48
+
49
+ it 'has key, bucket, bucket type, and score accessors' do
50
+ expect(subject.key).to eq key
51
+ expect(subject.bucket).to eq bucket
52
+ expect(subject.bucket_type).to eq bucket_type
53
+ expect(subject.score).to eq score
54
+ end
55
+
56
+ it 'makes other yz fields aavailable' do
57
+ expect(subject[:other_field]).to eq other_field
58
+ end
59
+
60
+ it 'fetches the robject it identifies' do
61
+ expect(subject.robject).to eq robject
62
+ end
63
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'riak/search/schema'
3
+
4
+ describe Riak::Search::Schema do
5
+ let(:schema_name){ 'schema_name' }
6
+ let(:schema_content){ '<xml />' }
7
+
8
+ let(:schema_exists_expectation) do
9
+ expect(backend).to receive(:get_search_schema).
10
+ with(schema_name).
11
+ and_return(schema_exists_response)
12
+ end
13
+
14
+ let(:schema_exists_response) do
15
+ resp = instance_double 'Riak::Client::BeefcakeProtobuffsBackend::RpbYokozunaSchema'
16
+ allow(resp).to receive(:name).and_return(schema_name)
17
+ allow(resp).to receive(:content).and_return(schema_content)
18
+
19
+ resp
20
+ end
21
+
22
+ let(:client){ instance_double 'Riak::Client' }
23
+ let(:backend) do
24
+ be = instance_double 'Riak::Client::BeefcakeProtobuffsBackend'
25
+ allow(client).to receive(:backend).and_yield be
26
+ be
27
+ end
28
+
29
+ subject { described_class.new client, schema_name }
30
+
31
+ it 'creates schema objects with a client and schema name' do
32
+ expect{ described_class.new client, schema_name }.to_not raise_error
33
+ end
34
+
35
+ it 'tests for schema existence' do
36
+ schema_exists_expectation
37
+ expect(subject).to be_exists
38
+ end
39
+
40
+ it 'permits schema creation' do
41
+ expect(backend).to receive(:get_search_schema).
42
+ with(schema_name).
43
+ and_return(nil)
44
+
45
+ expect(backend).to receive(:create_search_schema).
46
+ with(schema_name, schema_content).
47
+ and_return(true)
48
+
49
+ expect{ subject.create! schema_content }.to_not raise_error
50
+ end
51
+
52
+ it 'raises an error when creating a schema that already exists' do
53
+ schema_exists_expectation
54
+
55
+ expect{ subject.create! schema_content }.to raise_error(Riak::SearchError::SchemaExistsError)
56
+ end
57
+
58
+ it 'returns data about the schema' do
59
+ schema_exists_expectation
60
+
61
+ expect(subject.content).to eq schema_content
62
+ end
63
+ end
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,8 @@ Riak.disable_list_keys_warnings = true
19
19
  wait_until
20
20
  search_corpus_setup
21
21
  unified_backend_examples
22
- test_client].each do |file|
22
+ test_client
23
+ search_config].each do |file|
23
24
  require File.join("support", file)
24
25
  end
25
26
 
@@ -0,0 +1,81 @@
1
+ module SearchConfig
2
+ include TestClient
3
+
4
+ def search_bucket
5
+ return @search_bucket if defined? @search_bucket
6
+ type = test_client.bucket_type 'yokozuna'
7
+ @search_bucket = type.bucket "search_config-#{random_key}"
8
+ end
9
+
10
+ def index_name
11
+ @index_name ||= search_bucket.name
12
+ end
13
+
14
+ def create_index
15
+ return if defined? @index_exists
16
+
17
+ test_client.create_search_index index_name
18
+
19
+ wait_until do
20
+ test_client.get_search_index index_name
21
+ end
22
+
23
+ @index_exists = true
24
+ end
25
+
26
+ def configure_bucket
27
+ return if defined? @bucket_configured
28
+
29
+ create_index
30
+
31
+ test_client.set_bucket_props(search_bucket,
32
+ { search_index: index_name },
33
+ 'yokozuna')
34
+
35
+ wait_until do
36
+ props = test_client.get_bucket_props search_bucket, type: 'yokozuna'
37
+ props['search_index'] == index_name
38
+ end
39
+
40
+ @bucket_configred = true
41
+ end
42
+
43
+ def load_corpus
44
+ return if defined? @corpus_loaded
45
+
46
+ configure_bucket
47
+
48
+ old_encoding = Encoding.default_external
49
+ Encoding.default_external = Encoding::UTF_8
50
+
51
+ IO.foreach('spec/fixtures/bitcask.txt').with_index do |para, idx|
52
+ next if para =~ /^\s*$|introduction|chapter/ui
53
+
54
+ Riak::RObject.new(search_bucket, "bitcask-#{idx}") do |obj|
55
+ obj.content_type = 'text/plain'
56
+ obj.raw_data = para
57
+ obj.store
58
+ end
59
+ end
60
+
61
+ Encoding.default_external = old_encoding
62
+
63
+ wait_until do
64
+ results = @client.search(index_name,
65
+ 'contain your entire keyspace',
66
+ df: 'text')
67
+
68
+ results['docs'].length > 0
69
+ end
70
+
71
+ @corpus_loaded = true
72
+ end
73
+
74
+ def schema_xml(schema_name)
75
+ File.read('spec/fixtures/yz_schema_template.xml').sub('SCHEMA_NAME', schema_name)
76
+ end
77
+ end
78
+
79
+ RSpec.configure do |config|
80
+ config.include SearchConfig, search_config: true
81
+ end
@@ -1,7 +1,14 @@
1
- # protip: don't run more than one node, tests are sensitive to quorums
2
- nodes:
3
- - {host: 'localhost', pb_port: 17017}
4
- authentication:
5
- user: 'user'
6
- password: 'password'
7
- ca_file: /Users/bkerley/Documents/riak-ruby-client/spec/support/certs/ca.crt
1
+ # This file is used for configuring test_client used by
2
+ # many of the integration tests.
3
+ #
4
+ # Simply set the arguments you'd normally pass to
5
+ # Riak::Client.new in the file.
6
+ #
7
+ # Don't run multiple nodes, integration tests include
8
+ # quorum checks that may result in race conditions.
9
+
10
+ pb_port: 17017
11
+ # authentication:
12
+ # user: user
13
+ # password: password
14
+ # ca_file: /Users/bkerley/Documents/riak-ruby-client/spec/support/certs/ca.crt
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riak-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Cribbs
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-03 00:00:00.000000000 Z
12
+ date: 2015-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -186,7 +186,11 @@ files:
186
186
  - Rakefile
187
187
  - lib/riak.rb
188
188
  - lib/riak/bucket.rb
189
+ - lib/riak/bucket_properties.rb
190
+ - lib/riak/bucket_type.rb
191
+ - lib/riak/bucket_typed/bucket.rb
189
192
  - lib/riak/client.rb
193
+ - lib/riak/client/beefcake/bucket_properties_operator.rb
190
194
  - lib/riak/client/beefcake/crdt/counter_loader.rb
191
195
  - lib/riak/client/beefcake/crdt/map_loader.rb
192
196
  - lib/riak/client/beefcake/crdt/set_loader.rb
@@ -240,6 +244,7 @@ files:
240
244
  - lib/riak/errors/crdt_error.rb
241
245
  - lib/riak/errors/failed_request.rb
242
246
  - lib/riak/errors/protobuffs_error.rb
247
+ - lib/riak/errors/search_error.rb
243
248
  - lib/riak/i18n.rb
244
249
  - lib/riak/index_collection.rb
245
250
  - lib/riak/instrumentation.rb
@@ -256,6 +261,12 @@ files:
256
261
  - lib/riak/multiget.rb
257
262
  - lib/riak/rcontent.rb
258
263
  - lib/riak/robject.rb
264
+ - lib/riak/search.rb
265
+ - lib/riak/search/index.rb
266
+ - lib/riak/search/query.rb
267
+ - lib/riak/search/result_collection.rb
268
+ - lib/riak/search/result_document.rb
269
+ - lib/riak/search/schema.rb
259
270
  - lib/riak/secondary_index.rb
260
271
  - lib/riak/serializers.rb
261
272
  - lib/riak/stamp.rb
@@ -277,24 +288,32 @@ files:
277
288
  - spec/fixtures/server.cert.crt
278
289
  - spec/fixtures/server.cert.key
279
290
  - spec/fixtures/test.pem
291
+ - spec/fixtures/yz_schema_template.xml
280
292
  - spec/integration/riak/bucket_types_spec.rb
293
+ - spec/integration/riak/conflict_resolution_spec.rb
281
294
  - spec/integration/riak/counters_spec.rb
282
295
  - spec/integration/riak/crdt_spec.rb
283
296
  - spec/integration/riak/crdt_validation/map_spec.rb
284
297
  - spec/integration/riak/crdt_validation/set_spec.rb
298
+ - spec/integration/riak/properties_spec.rb
285
299
  - spec/integration/riak/protobuffs/interrupted_request_spec.rb
286
300
  - spec/integration/riak/protobuffs_backends_spec.rb
301
+ - spec/integration/riak/search_spec.rb
287
302
  - spec/integration/riak/secondary_index_spec.rb
288
303
  - spec/integration/riak/security_spec.rb
289
304
  - spec/integration/riak/threading_spec.rb
290
305
  - spec/integration/yokozuna/index_spec.rb
291
306
  - spec/integration/yokozuna/queries_spec.rb
292
307
  - spec/integration/yokozuna/schema_spec.rb
308
+ - spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb
293
309
  - spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb
294
310
  - spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb
295
311
  - spec/riak/beefcake_protobuffs_backend/protocol_spec.rb
296
312
  - spec/riak/beefcake_protobuffs_backend_spec.rb
313
+ - spec/riak/bucket_properties_spec.rb
297
314
  - spec/riak/bucket_spec.rb
315
+ - spec/riak/bucket_type_spec.rb
316
+ - spec/riak/bucket_typed/bucket.rb
298
317
  - spec/riak/client_spec.rb
299
318
  - spec/riak/core_ext/to_param_spec.rb
300
319
  - spec/riak/counter_spec.rb
@@ -320,6 +339,11 @@ files:
320
339
  - spec/riak/multiget_spec.rb
321
340
  - spec/riak/node_spec.rb
322
341
  - spec/riak/robject_spec.rb
342
+ - spec/riak/search/index_spec.rb
343
+ - spec/riak/search/query_spec.rb
344
+ - spec/riak/search/result_collection_spec.rb
345
+ - spec/riak/search/result_document_spec.rb
346
+ - spec/riak/search/schema_spec.rb
323
347
  - spec/riak/search_spec.rb
324
348
  - spec/riak/secondary_index_spec.rb
325
349
  - spec/riak/serializers_spec.rb
@@ -337,6 +361,7 @@ files:
337
361
  - spec/support/certs/server.crt
338
362
  - spec/support/certs/server.key
339
363
  - spec/support/integration_setup.rb
364
+ - spec/support/search_config.rb
340
365
  - spec/support/search_corpus_setup.rb
341
366
  - spec/support/test_client.rb
342
367
  - spec/support/test_client.yml
@@ -359,12 +384,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
359
384
  version: 1.9.3
360
385
  required_rubygems_version: !ruby/object:Gem::Requirement
361
386
  requirements:
362
- - - ">="
387
+ - - ">"
363
388
  - !ruby/object:Gem::Version
364
- version: '0'
389
+ version: 1.3.1
365
390
  requirements: []
366
391
  rubyforge_project:
367
- rubygems_version: 2.2.2
392
+ rubygems_version: 2.4.5
368
393
  signing_key:
369
394
  specification_version: 4
370
395
  summary: riak-client is a rich client for Riak, the distributed database by Basho.
@@ -381,24 +406,32 @@ test_files:
381
406
  - spec/fixtures/server.cert.crt
382
407
  - spec/fixtures/server.cert.key
383
408
  - spec/fixtures/test.pem
409
+ - spec/fixtures/yz_schema_template.xml
384
410
  - spec/integration/riak/bucket_types_spec.rb
411
+ - spec/integration/riak/conflict_resolution_spec.rb
385
412
  - spec/integration/riak/counters_spec.rb
386
413
  - spec/integration/riak/crdt_spec.rb
387
414
  - spec/integration/riak/crdt_validation/map_spec.rb
388
415
  - spec/integration/riak/crdt_validation/set_spec.rb
416
+ - spec/integration/riak/properties_spec.rb
389
417
  - spec/integration/riak/protobuffs/interrupted_request_spec.rb
390
418
  - spec/integration/riak/protobuffs_backends_spec.rb
419
+ - spec/integration/riak/search_spec.rb
391
420
  - spec/integration/riak/secondary_index_spec.rb
392
421
  - spec/integration/riak/security_spec.rb
393
422
  - spec/integration/riak/threading_spec.rb
394
423
  - spec/integration/yokozuna/index_spec.rb
395
424
  - spec/integration/yokozuna/queries_spec.rb
396
425
  - spec/integration/yokozuna/schema_spec.rb
426
+ - spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb
397
427
  - spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb
398
428
  - spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb
399
429
  - spec/riak/beefcake_protobuffs_backend/protocol_spec.rb
400
430
  - spec/riak/beefcake_protobuffs_backend_spec.rb
431
+ - spec/riak/bucket_properties_spec.rb
401
432
  - spec/riak/bucket_spec.rb
433
+ - spec/riak/bucket_type_spec.rb
434
+ - spec/riak/bucket_typed/bucket.rb
402
435
  - spec/riak/client_spec.rb
403
436
  - spec/riak/core_ext/to_param_spec.rb
404
437
  - spec/riak/counter_spec.rb
@@ -424,6 +457,11 @@ test_files:
424
457
  - spec/riak/multiget_spec.rb
425
458
  - spec/riak/node_spec.rb
426
459
  - spec/riak/robject_spec.rb
460
+ - spec/riak/search/index_spec.rb
461
+ - spec/riak/search/query_spec.rb
462
+ - spec/riak/search/result_collection_spec.rb
463
+ - spec/riak/search/result_document_spec.rb
464
+ - spec/riak/search/schema_spec.rb
427
465
  - spec/riak/search_spec.rb
428
466
  - spec/riak/secondary_index_spec.rb
429
467
  - spec/riak/serializers_spec.rb
@@ -441,6 +479,7 @@ test_files:
441
479
  - spec/support/certs/server.crt
442
480
  - spec/support/certs/server.key
443
481
  - spec/support/integration_setup.rb
482
+ - spec/support/search_config.rb
444
483
  - spec/support/search_corpus_setup.rb
445
484
  - spec/support/test_client.rb
446
485
  - spec/support/test_client.yml