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
+
3
+ describe 'Secondary indexes', test_client: true, integration: true do
4
+ let(:bucket){ random_bucket '2i-integration' }
5
+ before do
6
+ 50.times do |i|
7
+ bucket.new(i.to_s).tap do |obj|
8
+ obj.indexes["index_int"] << i
9
+ obj.indexes["index_bin"] << i.to_s
10
+ obj.data = [i]
11
+ obj.store
12
+ end
13
+ end
14
+ end
15
+
16
+ it "finds keys for an equality query" do
17
+ expect(bucket.get_index('index_int', 20)).to eq(["20"])
18
+ end
19
+
20
+ it "finds keys for a range query" do
21
+ expect(bucket.get_index('index_int', 19..21)).to match_array(%w(19 20 21))
22
+ end
23
+
24
+ it "returns an empty array for a query that does not match any keys" do
25
+ expect(bucket.get_index('index_int', 10000)).to eq([])
26
+ end
27
+
28
+ it "returns terms" do
29
+ results = nil
30
+ expect do
31
+ results = bucket.get_index('index_int',
32
+ 19..21,
33
+ return_terms: true)
34
+ end.to_not raise_error
35
+
36
+ expect(results).to be_a Array
37
+ expect(results.with_terms).to be_a Hash
38
+ end
39
+
40
+ it "returns terms matching a term_regex" do
41
+ results = nil
42
+ expect do
43
+ results = bucket.get_index('index_bin',
44
+ '19'..'21',
45
+ return_terms: true,
46
+ term_regex: '20')
47
+ end.to_not raise_error
48
+
49
+ terms = results.with_terms
50
+
51
+ expect(terms['20']).to be
52
+ expect(terms['19']).to be_empty
53
+ end
54
+
55
+ describe "with symbolized index names" do
56
+ it "stores and queries indexes correctly" do
57
+ obj = bucket.new random_key
58
+ obj.indexes[:coat_pattern_bin] << "tuxedo"
59
+ obj.data = "tuxedo"
60
+
61
+ expect{ obj.store }.to_not raise_error
62
+
63
+ results = nil
64
+ expect do
65
+ results = bucket.get_index(:coat_pattern_bin,
66
+ 'tuxedo')
67
+ end.to_not raise_error
68
+
69
+ expect(results.first).to eq obj.key
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'riak'
3
+ require 'riak/errors/connection_error'
4
+ require 'cert_validator/errors'
5
+
6
+ describe 'Secure Protobuffs', test_client: true, integration: true do
7
+ let(:config){ test_client_configuration.dup }
8
+ describe 'without security enabled on Riak', no_security: true do
9
+ it 'connects normally without authentication configured' do
10
+ expect(test_client.security?).to_not be
11
+
12
+ expect{test_client.ping}.to_not raise_error
13
+ end
14
+
15
+ it 'refuses to connect with authentication configured' do
16
+ with_auth_config = config.dup
17
+ with_auth_config[:authentication] = { user: 'user', password: 'password' }
18
+
19
+ secure_client = Riak::Client.new with_auth_config
20
+
21
+ expect{ secure_client.ping }.to raise_error(Riak::TlsError)
22
+ end
23
+ end
24
+
25
+ describe 'with security enabled on Riak', yes_security: true do
26
+ it 'connects normally with authentication configured' do
27
+ secure_client = Riak::Client.new config
28
+
29
+ expect(secure_client.security?).to be
30
+
31
+ expect{secure_client.ping}.to_not raise_error
32
+ end
33
+
34
+ it 'refuses to connect without authentication configured' do
35
+ no_auth_config = config.dup
36
+ no_auth_config.delete :authentication
37
+
38
+ plaintext_client = Riak::Client.new no_auth_config
39
+
40
+ expect{ plaintext_client.ping }.
41
+ to(raise_error(Riak::ProtobuffsFailedRequest,
42
+ /security is enabled/i))
43
+ end
44
+
45
+ it "refuses to connect if the server cert isn't recognized" do
46
+ broken_auth_config = config.dup
47
+ broken_auth_config[:authentication] = broken_auth_config[:authentication].dup
48
+ # this CA has never ever been used to sign a key
49
+ broken_auth_config[:authentication][:ca_file] =
50
+ File.join('support', 'certs', 'empty_ca.crt')
51
+
52
+ bugged_crypto_client = Riak::Client.new broken_auth_config
53
+
54
+ expect{ bugged_crypto_client.ping }.
55
+ to(raise_error(OpenSSL::SSL::SSLError,
56
+ /certificate verify failed/i))
57
+ end
58
+
59
+ it "refuses to connect if the server cert is revoked" do
60
+ revoked_auth_config = config.dup
61
+ revoked_auth_config[:authentication] = revoked_auth_config[:authentication].dup
62
+
63
+ revoked_auth_config[:authentication][:crl_file] =
64
+ File.expand_path(File.join('..',
65
+ '..',
66
+ '..',
67
+ 'support',
68
+ 'certs',
69
+ 'server.crl'),
70
+ __FILE__)
71
+ revoked_auth_config[:authentication][:crl] = true
72
+
73
+ revoked_auth_client = Riak::Client.new revoked_auth_config
74
+
75
+ expect{ revoked_auth_client.ping }.
76
+ to(raise_error(Riak::TlsError,
77
+ /revoked/i))
78
+ end
79
+ end
80
+
81
+ describe 'with client certificate security enabled on Riak', yes_security: true do
82
+ it 'connects normally with authentication configured' do
83
+ client_cert_config = config.dup
84
+ client_cert_config[:authentication] =
85
+ client_cert_config[:authentication].dup
86
+
87
+ client_cert_config[:authentication][:client_ca] = client_cert_config[:authentication]['ca_file']
88
+
89
+ client_cert_config[:authentication][:cert] = 'spec/support/certs/client.crt'
90
+ client_cert_config[:authentication][:key] = 'spec/support/certs/client.key'
91
+
92
+ client_cert_config[:authentication][:user] = 'certuser'
93
+ client_cert_config[:authentication][:password] = ''
94
+
95
+ cert_client = Riak::Client.new client_cert_config
96
+
97
+ expect{ cert_client.ping }.to_not raise_error
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Multithreaded client", :test_client => true do
4
+ class Synchronizer
5
+ def initialize(n)
6
+ @mutex = Mutex.new
7
+ @n = n
8
+ @waiting = Set.new
9
+ end
10
+
11
+ def sync
12
+ stop = false
13
+ @mutex.synchronize do
14
+ @waiting << Thread.current
15
+
16
+ if @waiting.size >= @n
17
+ # All threads are waiting.
18
+ @waiting.each do |t|
19
+ t.run
20
+ end
21
+ else
22
+ stop = true
23
+ end
24
+ end
25
+
26
+ if stop
27
+ Thread.stop
28
+ end
29
+ end
30
+ end
31
+
32
+ def threads(n, opts = {})
33
+ if opts[:synchronize]
34
+ s1 = Synchronizer.new n
35
+ s2 = Synchronizer.new n
36
+ end
37
+
38
+ threads = (0...n).map do |i|
39
+ Thread.new do
40
+ if opts[:synchronize]
41
+ s1.sync
42
+ end
43
+
44
+ yield i
45
+
46
+ if opts[:synchronize]
47
+ s2.sync
48
+ end
49
+ end
50
+ end
51
+
52
+ threads.each do |t|
53
+ t.join
54
+ end
55
+ end
56
+
57
+ [
58
+ {:protobuffs_backend => :Beefcake}
59
+ ].each do |opts|
60
+ describe opts.inspect do
61
+ before do
62
+ @bucket = random_bucket 'threading'
63
+ end
64
+
65
+ it 'gets in parallel' do
66
+ data = "the gun is good"
67
+ ro = @bucket.new('test')
68
+ ro.content_type = "application/json"
69
+ ro.data = [data]
70
+ ro.store
71
+
72
+ threads 10, :synchronize => true do
73
+ x = @bucket['test']
74
+ expect(x.content_type).to eq("application/json")
75
+ expect(x.data).to eq([data])
76
+ end
77
+ end
78
+
79
+ it 'puts in parallel' do
80
+ data = "the tabernacle is indestructible and everlasting"
81
+
82
+ n = 10
83
+ threads n, :synchronize => true do |i|
84
+ x = @bucket.new("test-#{i}")
85
+ x.content_type = "application/json"
86
+ x.data = ["#{data}-#{i}"]
87
+ x.store
88
+ end
89
+
90
+ (0...n).each do |i|
91
+ read = @bucket["test-#{i}"]
92
+ expect(read.content_type).to eq("application/json")
93
+ expect(read.data).to eq(["#{data}-#{i}"])
94
+ end
95
+ end
96
+
97
+ # This is a 1.0+ spec because putting with the same client ID
98
+ # will not create siblings on 0.14 in the same way. This will
99
+ # also likely fail for nodes with vnode_vclocks = false.
100
+ it 'puts conflicts in parallel' do
101
+ @bucket.allow_mult = true
102
+ expect(@bucket.allow_mult).to eq(true)
103
+
104
+ init = @bucket.new('test')
105
+ init.content_type = "application/json"
106
+ init.data = ''
107
+ init.store
108
+
109
+ # Create conflicting writes
110
+ n = 10
111
+ s = Synchronizer.new n
112
+ threads n, :synchronize => true do |i|
113
+ x = @bucket["test"]
114
+ s.sync
115
+ x.data = [i]
116
+ x.store
117
+ end
118
+
119
+ read = @bucket["test"]
120
+ expect(read.conflict?).to eq(true)
121
+ expect(read.siblings.map do |sibling|
122
+ sibling.data.first
123
+ end.to_set).to eq((0...n).to_set)
124
+ end
125
+
126
+ it 'lists-keys and gets in parallel', :slow => true do
127
+ count = 100
128
+ threads = 2
129
+
130
+ # Create items
131
+ count.times do |i|
132
+ o = @bucket.new("#{i}")
133
+ o.content_type = 'application/json'
134
+ o.data = [i]
135
+ o.store
136
+ end
137
+
138
+ threads(threads) do
139
+ set = Set.new
140
+ @bucket.keys do |stream|
141
+ stream.each do |key|
142
+ set.merge @bucket[key].data
143
+ end
144
+ end
145
+ expect(set).to eq((0...count).to_set)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'riak'
3
+
4
+ describe "Yokozuna", test_client: true, integration: true do
5
+ before(:all) do
6
+ @client = test_client
7
+
8
+ @index = 'yz_spec-' + random_key
9
+ @schema = 'yz_spec-' + random_key
10
+ end
11
+
12
+ context "without any indexes" do
13
+ it "allows index creation" do
14
+ expect(@client.create_search_index(@index, "_yz_default", 3)).to eq(true)
15
+ end
16
+ end
17
+
18
+ context "with an index" do
19
+ before :all do
20
+ expect(@client.create_search_index(@index)).to eq(true)
21
+ wait_until{ !@client.get_search_index(@index).nil? }
22
+ end
23
+
24
+ it "allows index inspection" do
25
+ expect(@client.get_search_index(@index).name).to eq(@index)
26
+ expect{ @client.get_search_index("herp_derp") }.to raise_error(Riak::ProtobuffsFailedRequest)
27
+ end
28
+
29
+ it "has an index list" do
30
+ expect(@client.list_search_indexes.size).to be >= 1
31
+ end
32
+
33
+ it "associates a bucket with an index" do
34
+ @bucket = Riak::Bucket.new(@client, @index)
35
+ @bucket.props = {'search_index' => @index}
36
+ @bucket = @client.bucket(@index)
37
+ expect(@bucket.props).to include('search_index' => @index)
38
+ end
39
+
40
+ context "associated with a bucket" do
41
+ before :all do
42
+ @bucket = Riak::Bucket.new(@client, @index)
43
+ @bucket.props = {'search_index' => @index}
44
+ @bucket = @client.bucket(@index)
45
+ expect(@bucket.props).to include('search_index' => @index)
46
+ end
47
+
48
+ it "indexes on object writes" do
49
+ object = @bucket.get_or_new("cat")
50
+ object.raw_data = {"cat_s"=>"Lela"}.to_json
51
+ object.content_type = 'application/json'
52
+ object.store
53
+ sleep 1.1 # pause for index commit to trigger
54
+
55
+ resp = @client.search(@index, "cat_s:Lela")
56
+ expect(resp).to include('docs')
57
+ expect(resp['docs'].size).to eq(1)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,115 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+ require 'riak'
4
+
5
+ describe "Yokozuna queries", test_client: true, integration: true do
6
+ before :all do
7
+ @client = test_client
8
+ end
9
+
10
+ context "with a schema and indexes" do
11
+ before :all do
12
+ @bucket = random_bucket 'yz-spec'
13
+ @index = @bucket.name
14
+
15
+ expect(@client.create_search_index(@index)).to eq(true)
16
+ wait_until{ !@client.get_search_index(@index).nil? }
17
+ @client.set_bucket_props(@bucket, {:search_index => @index}, 'yokozuna')
18
+
19
+ wait_until do
20
+ props = @client.get_bucket_props(@bucket, type: 'yokozuna')
21
+ props['search_index'] == @index
22
+ end
23
+
24
+ @o1 = build_json_obj(@bucket, "cat", {"cat_s"=>"Lela"})
25
+ @o2 = build_json_obj(@bucket, "docs", {"dog_ss"=>%w(Einstein Olive)})
26
+ build_json_obj(@bucket, "Z", {"username_s"=>"Z", "name_s"=>"ryan", "age_i"=>30})
27
+ build_json_obj(@bucket, "R", {"username_s"=>"R", "name_s"=>"eric", "age_i"=>34})
28
+ build_json_obj(@bucket, "F", {"username_s"=>"F", "name_s"=>"bryan fink", "age_i"=>32})
29
+ build_json_obj(@bucket, "H", {"username_s"=>"H", "name_s"=>"brett", "age_i"=>14})
30
+
31
+ wait_until { @client.search(@index, "username_s:Z")['docs'].length > 0 }
32
+ end
33
+
34
+ it "produces results on single term queries" do
35
+ resp = @client.search(@index, "username_s:Z")
36
+ expect(resp).to include('docs')
37
+ expect(resp['docs'].size).to eq(1)
38
+ end
39
+
40
+ it "produces results on multiple term queries" do
41
+ resp = @client.search(@index, "username_s:(F OR H)")
42
+ expect(resp).to include('docs')
43
+ expect(resp['docs'].size).to eq(2)
44
+ end
45
+
46
+ it "produces results on queries with boolean logic" do
47
+ resp = @client.search(@index, "username_s:Z AND name_s:ryan")
48
+ expect(resp).to include('docs')
49
+ expect(resp['docs'].size).to eq(1)
50
+ end
51
+
52
+ it "produces results on range queries" do
53
+ resp = @client.search(@index, "age_i:[30 TO 33]")
54
+ expect(resp).to include('docs')
55
+ expect(resp['docs'].size).to eq(2)
56
+ end
57
+
58
+ it "produces results on phrase queries" do
59
+ resp = @client.search(@index, 'name_s:"bryan fink"')
60
+ expect(resp).to include('docs')
61
+ expect(resp['docs'].size).to eq(1)
62
+ end
63
+
64
+ it "produces results on wildcard queries" do
65
+ resp = @client.search(@index, "name_s:*ryan*")
66
+ expect(resp).to include('docs')
67
+ expect(resp['docs'].size).to eq(2)
68
+ end
69
+
70
+ it "produces results on regexp queries" do
71
+ resp = @client.search(@index, "name_s:/br.*/")
72
+ expect(resp).to include('docs')
73
+ expect(resp['docs'].size).to eq(2)
74
+ end
75
+
76
+ it "supports utf8" do
77
+ build_json_obj(@bucket, "ja", {"text_ja"=>"私はハイビスカスを食べるのが 大好き"})
78
+ sleep 1.1 # pause for index commit to trigger
79
+ resp = @client.search(@index, "text_ja:大好き")
80
+ expect(resp).to include('docs')
81
+ expect(resp['docs'].size).to eq 1
82
+ end
83
+
84
+ context "using parameters" do
85
+ it "searches one row" do
86
+ resp = @client.search(@index, "*:*", {:rows => 1})
87
+ expect(resp).to include('docs')
88
+ expect(resp['docs'].size).to eq(1)
89
+ end
90
+
91
+ it "searches with df" do
92
+ resp = @client.search(@index, "Olive", {:rows => 1, :df => 'dog_ss'})
93
+ expect(resp).to include('docs')
94
+ expect(resp['docs'].size).to eq(1)
95
+ resp['docs'].first['dog_ss']
96
+ end
97
+
98
+ it "produces top result on sort" do
99
+ resp = @client.search(@index, "username_s:*", {:sort => "age_i asc"})
100
+ expect(resp).to include('docs')
101
+ expect(resp['docs'].first['age_i'].to_i).to eq(14)
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+ # populate objects
108
+ def build_json_obj(bucket, key, data)
109
+ object = bucket.get_or_new(key)
110
+ object.raw_data = data.to_json
111
+ object.content_type = 'application/json'
112
+ object.store type: 'yokozuna'
113
+ object
114
+ end
115
+ end