riak-client-noenc 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +42 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Guardfile +20 -0
- data/LICENSE.md +16 -0
- data/README.markdown +640 -0
- data/RELEASE_NOTES.md +392 -0
- data/Rakefile +119 -0
- data/lib/riak.rb +22 -0
- data/lib/riak/bucket.rb +297 -0
- data/lib/riak/bucket_properties.rb +74 -0
- data/lib/riak/bucket_type.rb +77 -0
- data/lib/riak/bucket_typed/bucket.rb +121 -0
- data/lib/riak/client.rb +433 -0
- data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
- data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -0
- data/lib/riak/client/beefcake/crdt/set_loader.rb +18 -0
- data/lib/riak/client/beefcake/crdt_loader.rb +84 -0
- data/lib/riak/client/beefcake/crdt_operator.rb +223 -0
- data/lib/riak/client/beefcake/footer +4 -0
- data/lib/riak/client/beefcake/header +6 -0
- data/lib/riak/client/beefcake/message_codes.rb +89 -0
- data/lib/riak/client/beefcake/message_overlay.rb +87 -0
- data/lib/riak/client/beefcake/messages.rb +772 -0
- data/lib/riak/client/beefcake/object_methods.rb +112 -0
- data/lib/riak/client/beefcake/protocol.rb +105 -0
- data/lib/riak/client/beefcake/socket.rb +260 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +538 -0
- data/lib/riak/client/decaying.rb +36 -0
- data/lib/riak/client/feature_detection.rb +120 -0
- data/lib/riak/client/instrumentation.rb +19 -0
- data/lib/riak/client/node.rb +49 -0
- data/lib/riak/client/protobuffs_backend.rb +143 -0
- data/lib/riak/client/search.rb +27 -0
- data/lib/riak/client/yokozuna.rb +52 -0
- data/lib/riak/conflict.rb +13 -0
- data/lib/riak/core_ext.rb +7 -0
- data/lib/riak/core_ext/blank.rb +53 -0
- data/lib/riak/core_ext/deep_dup.rb +13 -0
- data/lib/riak/core_ext/extract_options.rb +7 -0
- data/lib/riak/core_ext/json.rb +15 -0
- data/lib/riak/core_ext/slice.rb +18 -0
- data/lib/riak/core_ext/stringify_keys.rb +10 -0
- data/lib/riak/core_ext/symbolize_keys.rb +10 -0
- data/lib/riak/core_ext/to_param.rb +31 -0
- data/lib/riak/counter.rb +101 -0
- data/lib/riak/crdt.rb +21 -0
- data/lib/riak/crdt/base.rb +183 -0
- data/lib/riak/crdt/batch_counter.rb +19 -0
- data/lib/riak/crdt/batch_map.rb +41 -0
- data/lib/riak/crdt/counter.rb +82 -0
- data/lib/riak/crdt/inner_counter.rb +81 -0
- data/lib/riak/crdt/inner_flag.rb +42 -0
- data/lib/riak/crdt/inner_map.rb +75 -0
- data/lib/riak/crdt/inner_register.rb +26 -0
- data/lib/riak/crdt/inner_set.rb +102 -0
- data/lib/riak/crdt/map.rb +121 -0
- data/lib/riak/crdt/operation.rb +19 -0
- data/lib/riak/crdt/set.rb +166 -0
- data/lib/riak/crdt/typed_collection.rb +181 -0
- data/lib/riak/encoding.rb +6 -0
- data/lib/riak/errors/backend_creation.rb +9 -0
- data/lib/riak/errors/base.rb +9 -0
- data/lib/riak/errors/connection_error.rb +50 -0
- data/lib/riak/errors/crdt_error.rb +38 -0
- data/lib/riak/errors/failed_request.rb +58 -0
- data/lib/riak/errors/protobuffs_error.rb +11 -0
- data/lib/riak/errors/search_error.rb +35 -0
- data/lib/riak/i18n.rb +7 -0
- data/lib/riak/index_collection.rb +71 -0
- data/lib/riak/instrumentation.rb +6 -0
- data/lib/riak/json.rb +52 -0
- data/lib/riak/link.rb +96 -0
- data/lib/riak/list_buckets.rb +28 -0
- data/lib/riak/locale/en.yml +107 -0
- data/lib/riak/locale/fr.yml +51 -0
- data/lib/riak/map_reduce.rb +295 -0
- data/lib/riak/map_reduce/filter_builder.rb +103 -0
- data/lib/riak/map_reduce/phase.rb +98 -0
- data/lib/riak/map_reduce/results.rb +49 -0
- data/lib/riak/map_reduce_error.rb +7 -0
- data/lib/riak/multiget.rb +122 -0
- data/lib/riak/preflist_item.rb +7 -0
- data/lib/riak/rcontent.rb +173 -0
- data/lib/riak/robject.rb +222 -0
- data/lib/riak/search.rb +11 -0
- data/lib/riak/search/index.rb +87 -0
- data/lib/riak/search/query.rb +141 -0
- data/lib/riak/search/result_collection.rb +144 -0
- data/lib/riak/search/result_document.rb +129 -0
- data/lib/riak/search/schema.rb +65 -0
- data/lib/riak/secondary_index.rb +81 -0
- data/lib/riak/serializers.rb +73 -0
- data/lib/riak/stamp.rb +77 -0
- data/lib/riak/util/escape.rb +80 -0
- data/lib/riak/util/tcp_socket_extensions.rb +58 -0
- data/lib/riak/util/translation.rb +18 -0
- data/lib/riak/version.rb +3 -0
- data/lib/riak/walk_spec.rb +145 -0
- data/spec/failover/failover.rb +59 -0
- data/spec/fixtures/bitcask.txt +25 -0
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-basic-conflict.txt +15 -0
- data/spec/fixtures/multipart-blank.txt +7 -0
- data/spec/fixtures/multipart-mapreduce.txt +10 -0
- data/spec/fixtures/multipart-with-body.txt +16 -0
- data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
- data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
- data/spec/fixtures/server.cert.crt +15 -0
- data/spec/fixtures/server.cert.key +15 -0
- data/spec/fixtures/test.pem +1 -0
- data/spec/fixtures/yz_schema_template.xml +18 -0
- data/spec/integration/riak/bucket_types_spec.rb +270 -0
- data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
- data/spec/integration/riak/counters_spec.rb +36 -0
- data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
- data/spec/integration/riak/crdt_search_spec.rb +176 -0
- data/spec/integration/riak/crdt_spec.rb +250 -0
- data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
- data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
- data/spec/integration/riak/preflist_spec.rb +31 -0
- data/spec/integration/riak/properties_spec.rb +69 -0
- data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +33 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +40 -0
- data/spec/integration/riak/search_spec.rb +104 -0
- data/spec/integration/riak/secondary_index_spec.rb +72 -0
- data/spec/integration/riak/security_spec.rb +100 -0
- data/spec/integration/riak/threading_spec.rb +150 -0
- data/spec/integration/yokozuna/index_spec.rb +61 -0
- data/spec/integration/yokozuna/queries_spec.rb +115 -0
- data/spec/integration/yokozuna/schema_spec.rb +49 -0
- data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
- data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
- data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
- data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +162 -0
- data/spec/riak/bucket_properties_spec.rb +135 -0
- data/spec/riak/bucket_spec.rb +275 -0
- data/spec/riak/bucket_type_spec.rb +50 -0
- data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
- data/spec/riak/client_spec.rb +246 -0
- data/spec/riak/core_ext/to_param_spec.rb +15 -0
- data/spec/riak/counter_spec.rb +122 -0
- data/spec/riak/crdt/counter_spec.rb +55 -0
- data/spec/riak/crdt/inner_counter_spec.rb +21 -0
- data/spec/riak/crdt/inner_flag_spec.rb +39 -0
- data/spec/riak/crdt/inner_map_spec.rb +47 -0
- data/spec/riak/crdt/inner_register_spec.rb +40 -0
- data/spec/riak/crdt/inner_set_spec.rb +33 -0
- data/spec/riak/crdt/map_spec.rb +78 -0
- data/spec/riak/crdt/set_spec.rb +61 -0
- data/spec/riak/crdt/shared_examples.rb +74 -0
- data/spec/riak/crdt/typed_collection_spec.rb +225 -0
- data/spec/riak/escape_spec.rb +72 -0
- data/spec/riak/feature_detection_spec.rb +77 -0
- data/spec/riak/index_collection_spec.rb +53 -0
- data/spec/riak/instrumentation_spec.rb +124 -0
- data/spec/riak/link_spec.rb +85 -0
- data/spec/riak/list_buckets_spec.rb +41 -0
- data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
- data/spec/riak/map_reduce/phase_spec.rb +142 -0
- data/spec/riak/map_reduce_spec.rb +434 -0
- data/spec/riak/multiget_spec.rb +81 -0
- data/spec/riak/node_spec.rb +26 -0
- data/spec/riak/robject_spec.rb +496 -0
- data/spec/riak/search/index_spec.rb +72 -0
- data/spec/riak/search/query_spec.rb +88 -0
- data/spec/riak/search/result_collection_spec.rb +89 -0
- data/spec/riak/search/result_document_spec.rb +106 -0
- data/spec/riak/search/schema_spec.rb +63 -0
- data/spec/riak/search_spec.rb +107 -0
- data/spec/riak/secondary_index_spec.rb +225 -0
- data/spec/riak/serializers_spec.rb +121 -0
- data/spec/riak/stamp_spec.rb +54 -0
- data/spec/riak/walk_spec_spec.rb +203 -0
- data/spec/spec_helper.rb +66 -0
- data/spec/support/certs/README.md +13 -0
- data/spec/support/certs/ca.crt +21 -0
- data/spec/support/certs/client.crl +13 -0
- data/spec/support/certs/client.crt +94 -0
- data/spec/support/certs/client.csr +18 -0
- data/spec/support/certs/client.key +27 -0
- data/spec/support/certs/empty_ca.crt +21 -0
- data/spec/support/certs/server.crl +13 -0
- data/spec/support/certs/server.crt +94 -0
- data/spec/support/certs/server.key +27 -0
- data/spec/support/crdt_search_config.rb +112 -0
- data/spec/support/crdt_search_fixtures.rb +42 -0
- data/spec/support/integration_setup.rb +10 -0
- data/spec/support/search_config.rb +83 -0
- data/spec/support/search_corpus_setup.rb +39 -0
- data/spec/support/test_client.rb +46 -0
- data/spec/support/test_client.yml.example +10 -0
- data/spec/support/unified_backend_examples.rb +380 -0
- data/spec/support/version_filter.rb +12 -0
- data/spec/support/wait_until.rb +20 -0
- metadata +511 -0
@@ -0,0 +1,72 @@
|
|
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
|
@@ -0,0 +1,88 @@
|
|
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
|
@@ -0,0 +1,89 @@
|
|
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
|
@@ -0,0 +1,106 @@
|
|
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
|
@@ -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
|
@@ -0,0 +1,107 @@
|
|
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 bucket name and query" do
|
89
|
+
@mr.search("foo", "bar OR baz")
|
90
|
+
expect(@mr.inputs).to eq({:module => "riak_search", :function => "mapred_search", :arg => ["foo", "bar OR baz"]})
|
91
|
+
end
|
92
|
+
|
93
|
+
it "accepts a Riak::Bucket and query" do
|
94
|
+
@mr.search(Riak::Bucket.new(@client, "foo"), "bar OR baz")
|
95
|
+
expect(@mr.inputs).to eq({:module => "riak_search", :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":"riak_search"')
|
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
|