riak-client 2.5.0 → 2.6.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/RELNOTES.md +3 -0
- data/lib/riak/bucket.rb +1 -1
- data/lib/riak/client.rb +14 -7
- data/lib/riak/client/beefcake/messages.rb +13 -0
- data/lib/riak/multi.rb +101 -0
- data/lib/riak/multiexist.rb +14 -0
- data/lib/riak/multiget.rb +7 -107
- data/lib/riak/version.rb +1 -1
- metadata +12 -234
- data/.document +0 -5
- data/.gitignore +0 -44
- data/.rspec +0 -2
- data/Gemfile +0 -17
- data/Guardfile +0 -20
- data/Rakefile +0 -124
- data/riak-client.gemspec +0 -71
- data/spec/failover/failover.rb +0 -59
- data/spec/fixtures/bitcask.txt +0 -25
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-basic-conflict.txt +0 -15
- data/spec/fixtures/multipart-blank.txt +0 -7
- data/spec/fixtures/multipart-mapreduce.txt +0 -10
- data/spec/fixtures/multipart-with-body.txt +0 -16
- data/spec/fixtures/multipart-with-marked-tombstones.txt +0 -17
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +0 -16
- data/spec/fixtures/server.cert.crt +0 -15
- data/spec/fixtures/server.cert.key +0 -15
- data/spec/fixtures/test.pem +0 -1
- data/spec/fixtures/yz_schema_template.xml +0 -18
- data/spec/integration/riak/bucket_types_spec.rb +0 -308
- data/spec/integration/riak/conflict_resolution_spec.rb +0 -96
- data/spec/integration/riak/counters_spec.rb +0 -36
- data/spec/integration/riak/crdt/configuration_spec.rb +0 -38
- data/spec/integration/riak/crdt_search_spec.rb +0 -176
- data/spec/integration/riak/crdt_spec.rb +0 -332
- data/spec/integration/riak/crdt_validation/map_spec.rb +0 -63
- data/spec/integration/riak/crdt_validation/set_spec.rb +0 -122
- data/spec/integration/riak/encodings/crdt_spec.rb +0 -122
- data/spec/integration/riak/encodings/kv_spec.rb +0 -87
- data/spec/integration/riak/encodings/yz_spec.rb +0 -142
- data/spec/integration/riak/preflist_spec.rb +0 -43
- data/spec/integration/riak/properties_spec.rb +0 -69
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +0 -33
- data/spec/integration/riak/protobuffs/timeouts_spec.rb +0 -178
- data/spec/integration/riak/protobuffs_backends_spec.rb +0 -40
- data/spec/integration/riak/search_spec.rb +0 -104
- data/spec/integration/riak/secondary_index_spec.rb +0 -72
- data/spec/integration/riak/security_spec.rb +0 -105
- data/spec/integration/riak/threading_spec.rb +0 -154
- data/spec/integration/riak/time_series_spec.rb +0 -212
- data/spec/integration/yokozuna/index_spec.rb +0 -61
- data/spec/integration/yokozuna/queries_spec.rb +0 -115
- data/spec/integration/yokozuna/schema_spec.rb +0 -49
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +0 -247
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +0 -244
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +0 -53
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +0 -189
- data/spec/riak/beefcake_protobuffs_backend/ts_cell_codec_spec.rb +0 -124
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +0 -162
- data/spec/riak/bucket_properties_spec.rb +0 -135
- data/spec/riak/bucket_spec.rb +0 -275
- data/spec/riak/bucket_type_spec.rb +0 -50
- data/spec/riak/bucket_typed/bucket_spec.rb +0 -78
- data/spec/riak/client_spec.rb +0 -304
- data/spec/riak/core_ext/to_param_spec.rb +0 -15
- data/spec/riak/counter_spec.rb +0 -122
- data/spec/riak/crdt/counter_spec.rb +0 -55
- data/spec/riak/crdt/hyper_log_log_spec.rb +0 -56
- data/spec/riak/crdt/inner_counter_spec.rb +0 -21
- data/spec/riak/crdt/inner_flag_spec.rb +0 -39
- data/spec/riak/crdt/inner_map_spec.rb +0 -47
- data/spec/riak/crdt/inner_register_spec.rb +0 -40
- data/spec/riak/crdt/inner_set_spec.rb +0 -33
- data/spec/riak/crdt/map_spec.rb +0 -78
- data/spec/riak/crdt/set_spec.rb +0 -61
- data/spec/riak/crdt/shared_examples.rb +0 -88
- data/spec/riak/crdt/typed_collection_spec.rb +0 -225
- data/spec/riak/escape_spec.rb +0 -72
- data/spec/riak/feature_detection_spec.rb +0 -77
- data/spec/riak/index_collection_spec.rb +0 -53
- data/spec/riak/instrumentation_spec.rb +0 -124
- data/spec/riak/link_spec.rb +0 -85
- data/spec/riak/list_buckets_spec.rb +0 -41
- data/spec/riak/map_reduce/filter_builder_spec.rb +0 -32
- data/spec/riak/map_reduce/phase_spec.rb +0 -142
- data/spec/riak/map_reduce_spec.rb +0 -434
- data/spec/riak/multiget_spec.rb +0 -81
- data/spec/riak/node_spec.rb +0 -26
- data/spec/riak/robject_spec.rb +0 -542
- data/spec/riak/search/index_spec.rb +0 -72
- data/spec/riak/search/query_spec.rb +0 -88
- data/spec/riak/search/result_collection_spec.rb +0 -89
- data/spec/riak/search/result_document_spec.rb +0 -106
- data/spec/riak/search/schema_spec.rb +0 -63
- data/spec/riak/search_spec.rb +0 -107
- data/spec/riak/secondary_index_spec.rb +0 -225
- data/spec/riak/serializers_spec.rb +0 -121
- data/spec/riak/stamp_spec.rb +0 -54
- data/spec/riak/time_series/deletion_spec.rb +0 -33
- data/spec/riak/time_series/listing_spec.rb +0 -51
- data/spec/riak/time_series/submission_spec.rb +0 -35
- data/spec/riak/util/gzip_spec.rb +0 -49
- data/spec/riak/walk_spec_spec.rb +0 -203
- data/spec/spec_helper.rb +0 -67
- data/spec/support/certs/README.md +0 -13
- data/spec/support/certs/ca.crt +0 -21
- data/spec/support/certs/client.crl +0 -13
- data/spec/support/certs/client.crt +0 -94
- data/spec/support/certs/client.csr +0 -18
- data/spec/support/certs/client.key +0 -27
- data/spec/support/certs/empty_ca.crt +0 -21
- data/spec/support/certs/server.crl +0 -13
- data/spec/support/certs/server.crt +0 -94
- data/spec/support/certs/server.key +0 -27
- data/spec/support/crdt_search_config.rb +0 -112
- data/spec/support/crdt_search_fixtures.rb +0 -42
- data/spec/support/integration_setup.rb +0 -10
- data/spec/support/search_config.rb +0 -83
- data/spec/support/search_corpus_setup.rb +0 -39
- data/spec/support/test_client.rb +0 -52
- data/spec/support/test_client.yml.example +0 -10
- data/spec/support/unified_backend_examples.rb +0 -402
- data/spec/support/version_filter.rb +0 -12
- data/spec/support/wait_until.rb +0 -20
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'riak/search/index'
|
3
|
-
|
4
|
-
describe Riak::Search::Index do
|
5
|
-
let(:index_name){ 'index_name' }
|
6
|
-
let(:schema_name){ 'schema_name' }
|
7
|
-
|
8
|
-
let(:index_exists_expectation) do
|
9
|
-
expect(backend).to receive(:get_search_index).
|
10
|
-
with(index_name).
|
11
|
-
and_return(index_exists_response)
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:index_exists_response) do
|
15
|
-
instance_double(
|
16
|
-
'Riak::Client::BeefcakeProtobuffsBackend::RpbYokozunaIndexGetResp',
|
17
|
-
index: [{ name: index_name, schema: schema_name, n_val: 3 }]
|
18
|
-
)
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:client){ instance_double 'Riak::Client' }
|
22
|
-
let(:backend) do
|
23
|
-
be = instance_double 'Riak::Client::BeefcakeProtobuffsBackend'
|
24
|
-
allow(client).to receive(:backend).and_yield(be)
|
25
|
-
be
|
26
|
-
end
|
27
|
-
|
28
|
-
subject { described_class.new client, index_name }
|
29
|
-
|
30
|
-
it 'creates index objects with a client and index name' do
|
31
|
-
expect{ described_class.new client, index_name }.to_not raise_error
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'tests for index existence' do
|
35
|
-
index_exists_expectation
|
36
|
-
expect(subject).to be_exists
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'permits index creation' do
|
40
|
-
expect(backend).to receive(:get_search_index).
|
41
|
-
with(index_name).
|
42
|
-
and_raise(Riak::ProtobuffsFailedRequest.new(:not_found, 'not found'))
|
43
|
-
|
44
|
-
expect(backend).to receive(:create_search_index).
|
45
|
-
with(index_name, nil, nil, nil)
|
46
|
-
|
47
|
-
expect{ subject.create! }.to_not raise_error
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'raises an error when creating an index that already exists' do
|
51
|
-
index_exists_expectation
|
52
|
-
|
53
|
-
expect{ subject.create! }.
|
54
|
-
to raise_error(Riak::SearchError::IndexExistsError)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "spawns a query" do
|
58
|
-
t = "some query term"
|
59
|
-
expect(subject).to receive(:exists?).and_return(true)
|
60
|
-
expect(query = subject.query(t)).to be_a Riak::Search::Query
|
61
|
-
expect(query.term).to eq t
|
62
|
-
expect(query.index).to eq subject
|
63
|
-
expect(query.client).to eq subject.client
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'returns data about the index' do
|
67
|
-
index_exists_expectation
|
68
|
-
|
69
|
-
expect(subject.n_val).to eq 3
|
70
|
-
expect(subject.schema).to eq schema_name
|
71
|
-
end
|
72
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'riak/search/query'
|
3
|
-
|
4
|
-
describe Riak::Search::Query do
|
5
|
-
let(:client) do
|
6
|
-
instance_double('Riak::Client').tap do |c|
|
7
|
-
allow(c).to receive(:backend).and_yield(backend)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
let(:index) do
|
11
|
-
instance_double(
|
12
|
-
'Riak::Search::Index',
|
13
|
-
name: index_name,
|
14
|
-
'exists?' => true).tap do |i|
|
15
|
-
allow(i).to receive(:is_a?).with(String).and_return(false)
|
16
|
-
allow(i).to receive(:is_a?).with(Riak::Search::Index).and_return(true)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
let(:backend){ instance_double 'Riak::Client::BeefcakeProtobuffsBackend' }
|
20
|
-
|
21
|
-
let(:index_name){ 'yokozuna' }
|
22
|
-
let(:term){ 'bitcask' }
|
23
|
-
|
24
|
-
let(:raw_results) do
|
25
|
-
{
|
26
|
-
"max_score"=>0.7729485034942627,
|
27
|
-
"num_found"=>3,
|
28
|
-
"docs"=>[
|
29
|
-
{"score"=>"7.72948500000000038312e-01",
|
30
|
-
"_yz_rb"=>"search_test-1419261439-ew70sak2qr",
|
31
|
-
"_yz_rt"=>"yokozuna",
|
32
|
-
"_yz_rk"=>"bitcask-10"},
|
33
|
-
{"score"=>"2.35808490000000009479e-01",
|
34
|
-
"_yz_rb"=>"search_test-1419261439-ew70sak2qr",
|
35
|
-
"_yz_rt"=>"yokozuna",
|
36
|
-
"_yz_rk"=>"bitcask-9"},
|
37
|
-
{"score"=>"6.73738599999999937529e-02",
|
38
|
-
"_yz_rb"=>"search_test-1419261439-ew70sak2qr",
|
39
|
-
"_yz_rt"=>"yokozuna",
|
40
|
-
"_yz_rk"=>"bitcask-4"}
|
41
|
-
]
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
subject { described_class.new client, index, term }
|
46
|
-
|
47
|
-
it 'creates query objects with a client, index, and query string' do
|
48
|
-
expect{ described_class.new client, index, term }.to_not raise_error
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'creates query objects with a client, index name, and query string' do
|
52
|
-
class_double('Riak::Search::Index', new: index).as_stubbed_const
|
53
|
-
allow(index).to receive(:is_a?).with(Riak::Search::Index).and_return(true)
|
54
|
-
|
55
|
-
expect{ described_class.new client, index_name, term }.to_not raise_error
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'errors when querying with a non-existent index' do
|
59
|
-
expect(index).to receive(:exists?).and_return(false)
|
60
|
-
expect{ described_class.new client, index, term }.to raise_error(Riak::SearchError::IndexNonExistError)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'allows specifying other query options on creation' do
|
64
|
-
expect(backend).to receive(:search).
|
65
|
-
with(index_name, term, hash_including(rows: 5)).
|
66
|
-
and_return(raw_results)
|
67
|
-
|
68
|
-
q = described_class.new client, index, term, rows: 5
|
69
|
-
expect{ q.results }.to_not raise_error
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'allows specifying query options with accessors' do
|
73
|
-
expect(backend).to receive(:search).
|
74
|
-
with(index_name, term, hash_including(rows: 5)).
|
75
|
-
and_return(raw_results)
|
76
|
-
|
77
|
-
subject.rows = 5
|
78
|
-
expect{ subject.results }.to_not raise_error
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'returns a ResultCollection' do
|
82
|
-
expect(backend).to receive(:search).
|
83
|
-
with(index_name, term, instance_of(Hash)).
|
84
|
-
and_return(raw_results)
|
85
|
-
|
86
|
-
expect(subject.results).to be_a Riak::Search::ResultCollection
|
87
|
-
end
|
88
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'riak/search/result_collection'
|
3
|
-
|
4
|
-
describe Riak::Search::ResultCollection, crdt_search_fixtures: true 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
|
-
map_raw
|
49
|
-
]
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
let(:bucket_name){ 'search_test-1419261439-ew70sak2qr' }
|
54
|
-
let(:bucket_type_name){ 'yokozuna' }
|
55
|
-
let(:first_key){ 'bitcask-10' }
|
56
|
-
let(:first_result) do
|
57
|
-
instance_double('Riak::RObject').tap do |o|
|
58
|
-
allow(o).to receive(:key).and_return(first_key)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
let(:fetch_first_expectation) do
|
63
|
-
expect(bucket).to receive(:get).with(first_key).and_return(first_result)
|
64
|
-
end
|
65
|
-
|
66
|
-
subject{ described_class.new client, results_hash }
|
67
|
-
|
68
|
-
it 'is creatable with a search results hash' do
|
69
|
-
expect{ described_class.new client, results_hash }.to_not raise_error
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'exposes the raw search results hash' do
|
73
|
-
expect(subject.raw).to eq results_hash
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'exposes the max score and entry scores' do
|
77
|
-
expect(subject.max_score).to eq results_hash['max_score']
|
78
|
-
expect(subject.docs.first.score).to eq Float(
|
79
|
-
results_hash['docs'].
|
80
|
-
first['score'])
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'fetches individual documents on demand' do
|
84
|
-
fetch_first_expectation
|
85
|
-
allow(bucket_type).to receive(:data_type_class).and_return nil
|
86
|
-
|
87
|
-
expect(subject.first).to eq first_result
|
88
|
-
end
|
89
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'riak/search/result_document'
|
3
|
-
|
4
|
-
describe Riak::Search::ResultDocument, crdt_search_fixtures: true 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
|
-
allow(c).to receive(:bucket_type).
|
17
|
-
with(maps_type_name).
|
18
|
-
and_return(maps_bucket_type)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:bucket_type) do
|
23
|
-
instance_double('Riak::BucketType').tap do |bt|
|
24
|
-
allow(bt).to receive(:bucket).
|
25
|
-
with(bucket_name).
|
26
|
-
and_return(bucket)
|
27
|
-
allow(bt).to receive(:data_type_class).
|
28
|
-
and_return(nil)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
let(:bucket) do
|
33
|
-
instance_double('Riak::BucketTyped::Bucket').tap do |b|
|
34
|
-
allow(b).to receive(:get).
|
35
|
-
with(key).
|
36
|
-
and_return(robject)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
let(:robject){ instance_double 'Riak::RObject' }
|
41
|
-
|
42
|
-
let(:raw) do
|
43
|
-
{
|
44
|
-
"score"=>score,
|
45
|
-
"_yz_rb"=>bucket_name,
|
46
|
-
"_yz_rt"=>bucket_type_name,
|
47
|
-
"_yz_rk"=>key,
|
48
|
-
'other_field'=>other_field
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
subject{ described_class.new client, raw }
|
53
|
-
|
54
|
-
it 'has key, bucket, bucket type, and score accessors' do
|
55
|
-
expect(subject.key).to eq key
|
56
|
-
expect(subject.bucket).to eq bucket
|
57
|
-
expect(subject.bucket_type).to eq bucket_type
|
58
|
-
expect(subject.score).to eq score
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'makes other yz fields available' do
|
62
|
-
expect(subject[:other_field]).to eq other_field
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'identifying a key-value object' do
|
66
|
-
it 'fetches the robject it identifies' do
|
67
|
-
expect(subject.robject).to eq robject
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'returns the data type class the document is' do
|
71
|
-
expect(subject.type_class).to eq Riak::RObject
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'refuses to return a CRDT' do
|
75
|
-
expect{ subject.crdt }.to raise_error Riak::CrdtError::NotACrdt
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'identifying a CRDT map object' do
|
80
|
-
subject { map_results }
|
81
|
-
|
82
|
-
it 'returns the data type class the document is' do
|
83
|
-
expect(subject.type_class).to eq Riak::Crdt::Map
|
84
|
-
end
|
85
|
-
|
86
|
-
let(:fake_map){ instance_double 'Riak::Crdt::Map' }
|
87
|
-
|
88
|
-
it 'fetches the map it identifies' do
|
89
|
-
expect(Riak::Crdt::Map).
|
90
|
-
to receive(:new).
|
91
|
-
with(map_bucket, 'map-key', maps_bucket_type).
|
92
|
-
and_return(fake_map).
|
93
|
-
twice
|
94
|
-
|
95
|
-
expect(subject.map).to eq fake_map
|
96
|
-
expect(subject.crdt).to eq fake_map
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'refuses to fetch a counter or set' do
|
100
|
-
expect{ subject.counter }.
|
101
|
-
to raise_error Riak::CrdtError::UnexpectedDataType
|
102
|
-
expect{ subject.set }.
|
103
|
-
to raise_error Riak::CrdtError::UnexpectedDataType
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,63 +0,0 @@
|
|
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/riak/search_spec.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rexml/document'
|
3
|
-
|
4
|
-
describe "Search features" do
|
5
|
-
describe Riak::Client do
|
6
|
-
before :each do
|
7
|
-
@client = Riak::Client.new
|
8
|
-
@pb = double(Riak::Client::BeefcakeProtobuffsBackend)
|
9
|
-
allow(@client).to receive(:backend).and_yield(@pb)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "searching" do
|
13
|
-
it "searches the default index" do
|
14
|
-
expect(@pb).to receive(:search).with(nil, "foo", {}).and_return({})
|
15
|
-
@client.search("foo")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "searches the default index with additional options" do
|
19
|
-
expect(@pb).to receive(:search).with(nil, 'foo', 'rows' => 30).and_return({})
|
20
|
-
@client.search("foo", 'rows' => 30)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "searches the specified index" do
|
24
|
-
expect(@pb).to receive(:search).with('search', 'foo', {}).and_return({})
|
25
|
-
@client.search("search", "foo")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe Riak::Bucket do
|
31
|
-
before :each do
|
32
|
-
@client = Riak::Client.new
|
33
|
-
@bucket = Riak::Bucket.new(@client, "foo")
|
34
|
-
end
|
35
|
-
|
36
|
-
def load_without_index_hook
|
37
|
-
@bucket.instance_variable_set(:@props, {"precommit" => [], "search" => false})
|
38
|
-
end
|
39
|
-
|
40
|
-
def load_with_index_hook
|
41
|
-
@bucket.instance_variable_set(:@props, {"precommit" => [{"mod" => "riak_search_kv_hook", "fun" => "precommit"}], "search" => true})
|
42
|
-
end
|
43
|
-
|
44
|
-
it "detects whether the indexing hook is installed" do
|
45
|
-
load_without_index_hook
|
46
|
-
expect(@bucket.is_indexed?).to be_falsey
|
47
|
-
|
48
|
-
load_with_index_hook
|
49
|
-
expect(@bucket.is_indexed?).to be_truthy
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "enabling indexing" do
|
53
|
-
it "adds the index hook when not present" do
|
54
|
-
load_without_index_hook
|
55
|
-
expect(@bucket).to receive(:props=).with({"precommit" => [Riak::Bucket::SEARCH_PRECOMMIT_HOOK], "search" => true})
|
56
|
-
@bucket.enable_index!
|
57
|
-
end
|
58
|
-
|
59
|
-
it "doesn't modify the precommit when the hook is present" do
|
60
|
-
load_with_index_hook
|
61
|
-
expect(@bucket).not_to receive(:props=)
|
62
|
-
@bucket.enable_index!
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "disabling indexing" do
|
67
|
-
it "removes the index hook when present" do
|
68
|
-
load_with_index_hook
|
69
|
-
expect(@bucket).to receive(:props=).with({"precommit" => [], "search" => false})
|
70
|
-
@bucket.disable_index!
|
71
|
-
end
|
72
|
-
|
73
|
-
it "doesn't modify the precommit when the hook is missing" do
|
74
|
-
load_without_index_hook
|
75
|
-
expect(@bucket).not_to receive(:props=)
|
76
|
-
@bucket.disable_index!
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe Riak::MapReduce do
|
82
|
-
before :each do
|
83
|
-
@client = Riak::Client.new
|
84
|
-
@mr = Riak::MapReduce.new(@client)
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "using a search query as inputs" do
|
88
|
-
it "accepts a index name and query" do
|
89
|
-
@mr.search("foo", "bar OR baz")
|
90
|
-
expect(@mr.inputs).to eq({:module => "yokozuna", :function => "mapred_search", :arg => ["foo", "bar OR baz"]})
|
91
|
-
end
|
92
|
-
|
93
|
-
it "accepts a Riak::Search::Index and query" do
|
94
|
-
@mr.search(Riak::Search::Index.new(@client, "foo"), "bar OR baz")
|
95
|
-
expect(@mr.inputs).to eq({:module => "yokozuna", :function => "mapred_search", :arg => ["foo", "bar OR baz"]})
|
96
|
-
end
|
97
|
-
|
98
|
-
it "emits the Erlang function and arguments" do
|
99
|
-
@mr.search("foo", "bar OR baz")
|
100
|
-
expect(@mr.to_json).to include('"inputs":{')
|
101
|
-
expect(@mr.to_json).to include('"module":"yokozuna"')
|
102
|
-
expect(@mr.to_json).to include('"function":"mapred_search"')
|
103
|
-
expect(@mr.to_json).to include('"arg":["foo","bar OR baz"]')
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|