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,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