riak-client 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/RELNOTES.md +3 -0
  4. data/lib/riak/bucket.rb +1 -1
  5. data/lib/riak/client.rb +14 -7
  6. data/lib/riak/client/beefcake/messages.rb +13 -0
  7. data/lib/riak/multi.rb +101 -0
  8. data/lib/riak/multiexist.rb +14 -0
  9. data/lib/riak/multiget.rb +7 -107
  10. data/lib/riak/version.rb +1 -1
  11. metadata +12 -234
  12. data/.document +0 -5
  13. data/.gitignore +0 -44
  14. data/.rspec +0 -2
  15. data/Gemfile +0 -17
  16. data/Guardfile +0 -20
  17. data/Rakefile +0 -124
  18. data/riak-client.gemspec +0 -71
  19. data/spec/failover/failover.rb +0 -59
  20. data/spec/fixtures/bitcask.txt +0 -25
  21. data/spec/fixtures/cat.jpg +0 -0
  22. data/spec/fixtures/multipart-basic-conflict.txt +0 -15
  23. data/spec/fixtures/multipart-blank.txt +0 -7
  24. data/spec/fixtures/multipart-mapreduce.txt +0 -10
  25. data/spec/fixtures/multipart-with-body.txt +0 -16
  26. data/spec/fixtures/multipart-with-marked-tombstones.txt +0 -17
  27. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +0 -16
  28. data/spec/fixtures/server.cert.crt +0 -15
  29. data/spec/fixtures/server.cert.key +0 -15
  30. data/spec/fixtures/test.pem +0 -1
  31. data/spec/fixtures/yz_schema_template.xml +0 -18
  32. data/spec/integration/riak/bucket_types_spec.rb +0 -308
  33. data/spec/integration/riak/conflict_resolution_spec.rb +0 -96
  34. data/spec/integration/riak/counters_spec.rb +0 -36
  35. data/spec/integration/riak/crdt/configuration_spec.rb +0 -38
  36. data/spec/integration/riak/crdt_search_spec.rb +0 -176
  37. data/spec/integration/riak/crdt_spec.rb +0 -332
  38. data/spec/integration/riak/crdt_validation/map_spec.rb +0 -63
  39. data/spec/integration/riak/crdt_validation/set_spec.rb +0 -122
  40. data/spec/integration/riak/encodings/crdt_spec.rb +0 -122
  41. data/spec/integration/riak/encodings/kv_spec.rb +0 -87
  42. data/spec/integration/riak/encodings/yz_spec.rb +0 -142
  43. data/spec/integration/riak/preflist_spec.rb +0 -43
  44. data/spec/integration/riak/properties_spec.rb +0 -69
  45. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +0 -33
  46. data/spec/integration/riak/protobuffs/timeouts_spec.rb +0 -178
  47. data/spec/integration/riak/protobuffs_backends_spec.rb +0 -40
  48. data/spec/integration/riak/search_spec.rb +0 -104
  49. data/spec/integration/riak/secondary_index_spec.rb +0 -72
  50. data/spec/integration/riak/security_spec.rb +0 -105
  51. data/spec/integration/riak/threading_spec.rb +0 -154
  52. data/spec/integration/riak/time_series_spec.rb +0 -212
  53. data/spec/integration/yokozuna/index_spec.rb +0 -61
  54. data/spec/integration/yokozuna/queries_spec.rb +0 -115
  55. data/spec/integration/yokozuna/schema_spec.rb +0 -49
  56. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +0 -247
  57. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +0 -244
  58. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +0 -53
  59. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +0 -189
  60. data/spec/riak/beefcake_protobuffs_backend/ts_cell_codec_spec.rb +0 -124
  61. data/spec/riak/beefcake_protobuffs_backend_spec.rb +0 -162
  62. data/spec/riak/bucket_properties_spec.rb +0 -135
  63. data/spec/riak/bucket_spec.rb +0 -275
  64. data/spec/riak/bucket_type_spec.rb +0 -50
  65. data/spec/riak/bucket_typed/bucket_spec.rb +0 -78
  66. data/spec/riak/client_spec.rb +0 -304
  67. data/spec/riak/core_ext/to_param_spec.rb +0 -15
  68. data/spec/riak/counter_spec.rb +0 -122
  69. data/spec/riak/crdt/counter_spec.rb +0 -55
  70. data/spec/riak/crdt/hyper_log_log_spec.rb +0 -56
  71. data/spec/riak/crdt/inner_counter_spec.rb +0 -21
  72. data/spec/riak/crdt/inner_flag_spec.rb +0 -39
  73. data/spec/riak/crdt/inner_map_spec.rb +0 -47
  74. data/spec/riak/crdt/inner_register_spec.rb +0 -40
  75. data/spec/riak/crdt/inner_set_spec.rb +0 -33
  76. data/spec/riak/crdt/map_spec.rb +0 -78
  77. data/spec/riak/crdt/set_spec.rb +0 -61
  78. data/spec/riak/crdt/shared_examples.rb +0 -88
  79. data/spec/riak/crdt/typed_collection_spec.rb +0 -225
  80. data/spec/riak/escape_spec.rb +0 -72
  81. data/spec/riak/feature_detection_spec.rb +0 -77
  82. data/spec/riak/index_collection_spec.rb +0 -53
  83. data/spec/riak/instrumentation_spec.rb +0 -124
  84. data/spec/riak/link_spec.rb +0 -85
  85. data/spec/riak/list_buckets_spec.rb +0 -41
  86. data/spec/riak/map_reduce/filter_builder_spec.rb +0 -32
  87. data/spec/riak/map_reduce/phase_spec.rb +0 -142
  88. data/spec/riak/map_reduce_spec.rb +0 -434
  89. data/spec/riak/multiget_spec.rb +0 -81
  90. data/spec/riak/node_spec.rb +0 -26
  91. data/spec/riak/robject_spec.rb +0 -542
  92. data/spec/riak/search/index_spec.rb +0 -72
  93. data/spec/riak/search/query_spec.rb +0 -88
  94. data/spec/riak/search/result_collection_spec.rb +0 -89
  95. data/spec/riak/search/result_document_spec.rb +0 -106
  96. data/spec/riak/search/schema_spec.rb +0 -63
  97. data/spec/riak/search_spec.rb +0 -107
  98. data/spec/riak/secondary_index_spec.rb +0 -225
  99. data/spec/riak/serializers_spec.rb +0 -121
  100. data/spec/riak/stamp_spec.rb +0 -54
  101. data/spec/riak/time_series/deletion_spec.rb +0 -33
  102. data/spec/riak/time_series/listing_spec.rb +0 -51
  103. data/spec/riak/time_series/submission_spec.rb +0 -35
  104. data/spec/riak/util/gzip_spec.rb +0 -49
  105. data/spec/riak/walk_spec_spec.rb +0 -203
  106. data/spec/spec_helper.rb +0 -67
  107. data/spec/support/certs/README.md +0 -13
  108. data/spec/support/certs/ca.crt +0 -21
  109. data/spec/support/certs/client.crl +0 -13
  110. data/spec/support/certs/client.crt +0 -94
  111. data/spec/support/certs/client.csr +0 -18
  112. data/spec/support/certs/client.key +0 -27
  113. data/spec/support/certs/empty_ca.crt +0 -21
  114. data/spec/support/certs/server.crl +0 -13
  115. data/spec/support/certs/server.crt +0 -94
  116. data/spec/support/certs/server.key +0 -27
  117. data/spec/support/crdt_search_config.rb +0 -112
  118. data/spec/support/crdt_search_fixtures.rb +0 -42
  119. data/spec/support/integration_setup.rb +0 -10
  120. data/spec/support/search_config.rb +0 -83
  121. data/spec/support/search_corpus_setup.rb +0 -39
  122. data/spec/support/test_client.rb +0 -52
  123. data/spec/support/test_client.yml.example +0 -10
  124. data/spec/support/unified_backend_examples.rb +0 -402
  125. data/spec/support/version_filter.rb +0 -12
  126. data/spec/support/wait_until.rb +0 -20
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
- require 'bigdecimal'
3
- require 'time'
4
-
5
- Riak::Client::BeefcakeProtobuffsBackend.configured?
6
-
7
- describe Riak::Client::BeefcakeProtobuffsBackend::TsCellCodec do
8
- describe 'symmetric serialization' do
9
- it { is_expected.to symmetric_serialize("hello", varchar_value: "hello")}
10
- it { is_expected.to symmetric_serialize(5, sint64_value: 5)}
11
- it { is_expected.to symmetric_serialize(123.45, double_value: 123.45) }
12
- it do
13
- subject.convert_timestamp = true
14
- is_expected.to symmetric_serialize(Time.parse("June 23, 2015 at 9:46:28 EDT"),
15
- timestamp_value: 1_435_067_188_000)
16
- end
17
- # GH-274
18
- it do
19
- subject.convert_timestamp = true
20
- ts = 1_459_444_070_103
21
- t = Time.at(1_459_444_070, 103_000)
22
- is_expected.to symmetric_serialize(t, timestamp_value: ts)
23
- end
24
- it { is_expected.to symmetric_serialize(true, boolean_value: true) }
25
- it { is_expected.to symmetric_serialize(false, boolean_value: false) }
26
- it { is_expected.to symmetric_serialize(nil, {}) }
27
- end
28
-
29
- describe 'serializing values' do
30
- it do
31
- is_expected.to serialize(BigDecimal.new("0.1"), double_value: 0.1)
32
- end
33
-
34
- it 'refuses to serialize big numbers' do
35
- expect{ subject.cell_for 2**64 }.
36
- to raise_error Riak::TimeSeriesError::SerializeBigIntegerError
37
- end
38
-
39
- it 'refuses to serialize complex numbers' do
40
- expect{ subject.cell_for(Complex(1, 1)) }.
41
- to raise_error Riak::TimeSeriesError::SerializeComplexNumberError
42
- end
43
-
44
- it 'refuses to serialize rational numbers' do
45
- expect{ subject.cell_for(Rational(1, 1)) }.
46
- to raise_error Riak::TimeSeriesError::SerializeRationalNumberError
47
- end
48
- end
49
-
50
- # deserialization is handled by the symmetric cases above
51
- # describe 'deserializing values'
52
-
53
- describe 'with a collection' do
54
- let(:not_serialized){ ['hi', 5, 12.34] }
55
- let(:serialized) do
56
- [
57
- Riak::Client::BeefcakeProtobuffsBackend::TsCell.new(varchar_value: 'hi'),
58
- Riak::Client::BeefcakeProtobuffsBackend::TsCell.new(sint64_value: 5),
59
- Riak::Client::BeefcakeProtobuffsBackend::TsCell.new(double_value: 12.34)
60
- ]
61
- end
62
-
63
- it 'serializes' do
64
- expect(subject.cells_for(not_serialized)).to eq serialized
65
- end
66
-
67
- it 'deserializes' do
68
- expect(subject.scalars_for(serialized)).to eq not_serialized
69
- end
70
- end
71
-
72
- RSpec::Matchers.define :symmetric_serialize do |scalar, cell_options|
73
- match do |codec|
74
- expect(codec).to(
75
- serialize(scalar, cell_options)
76
- .and(deserialize(scalar, cell_options)))
77
- end
78
-
79
- failure_message do |codec|
80
- cell = Riak::Client::BeefcakeProtobuffsBackend::TsCell.new cell_options
81
- deserialized = codec.scalar_for cell
82
- "expected #{scalar} => #{cell_options} => #{scalar}, got #{scalar} => #{cell.to_hash} => #{deserialized}"
83
- end
84
-
85
- description do
86
- "serialize #{scalar.class} #{scalar.inspect} to and from TsCell #{cell_options}"
87
- end
88
- end
89
-
90
- RSpec::Matchers.define :serialize do |measure, options|
91
- match do |actual|
92
- serialized = actual.cell_for(measure)
93
- serialized.to_hash == options
94
- end
95
-
96
- failure_message do |actual|
97
- serialized = actual.cell_for(measure)
98
- "expected #{options}, got #{serialized.to_hash}"
99
- end
100
-
101
- description do
102
- "serialize #{measure.class} #{measure.inspect} to TsCell #{options}"
103
- end
104
- end
105
-
106
- RSpec::Matchers.define :deserialize do |expected, options|
107
-
108
- cell = Riak::Client::BeefcakeProtobuffsBackend::TsCell.new options
109
-
110
- match do |codec|
111
- deserialized = codec.scalar_for cell
112
- deserialized == expected
113
- end
114
-
115
- failure_message do |codec|
116
- deserialized = codec.scalar_for cell
117
- "expected TsCell #{options.inspect} to deserialize to #{expected.class} #{expected.inspect}"
118
- end
119
-
120
- description do
121
- "deserialize TsCell #{options} to #{expected.class} #{expected.inspect}"
122
- end
123
- end
124
- end
@@ -1,162 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Client::BeefcakeProtobuffsBackend do
4
- before(:all) { expect(described_class).to be_configured }
5
- let(:client) { Riak::Client.new }
6
- let(:node) { client.nodes.first }
7
- let(:backend) { Riak::Client::BeefcakeProtobuffsBackend.new(client, node) }
8
- let(:protocol){ double 'protocol' }
9
- before(:each) do
10
- allow(backend).to receive(:get_server_version).and_return("2.0.0")
11
- allow(backend).to receive(:protocol).and_yield(protocol)
12
- end
13
-
14
- context "secondary index" do
15
- before :each do
16
- @socket = double(:socket).as_null_object
17
- allow(TCPSocket).to receive(:new).and_return(@socket)
18
- end
19
-
20
- it 'raises an appropriate error when 2i is not available' do
21
- expect(protocol).to receive(:write)
22
- expect(protocol).to receive(:expect).
23
- and_raise(
24
- Riak::ProtobuffsErrorResponse.
25
- new(Riak::Client::BeefcakeProtobuffsBackend::
26
- RpbErrorResp.
27
- new(errmsg: '{error,{indexes_not_supported,riak_kv_bitcask_backend}}',
28
- errcode: 0)
29
- )
30
- )
31
-
32
- expect{ backend.get_index 'bucket', 'words', 'asdf' }.to raise_error /Secondary indexes aren't supported/
33
- # '
34
- end
35
-
36
- context 'when streaming' do
37
- it "streams when a block is given" do
38
- expect(protocol).to receive(:write) do |msg, req|
39
- expect(msg).to eq(:IndexReq)
40
- expect(req[:stream]).to eq(true)
41
- end
42
- expect(protocol).to receive(:expect).
43
- and_return(Riak::Client::BeefcakeProtobuffsBackend::RpbIndexResp.new keys: %w{'asdf'}, done: true)
44
-
45
- blk = proc{:asdf}
46
-
47
- backend.get_index('bucket', 'words', 'asdf'..'hjkl', &blk)
48
- end
49
-
50
- it "sends batches of results to the block" do
51
- expect(protocol).to receive(:write)
52
-
53
- response_sets = [%w{asdf asdg asdh}, %w{gggg gggh gggi}]
54
- response_messages = response_sets.map do |s|
55
- Riak::Client::BeefcakeProtobuffsBackend::RpbIndexResp.new keys: s
56
- end
57
- response_messages.last.done = true
58
-
59
- expect(protocol).to receive(:expect).and_return(*response_messages)
60
-
61
- block_body = double 'block'
62
- expect(block_body).to receive(:check).with(response_sets.first).once
63
- expect(block_body).to receive(:check).with(response_sets.last).once
64
-
65
- blk = proc {|m| block_body.check m }
66
-
67
- backend.get_index 'bucket', 'words', 'asdf'..'hjkl', &blk
68
- end
69
- end
70
-
71
- it "returns a full batch of results when not streaming" do
72
- expect(protocol).to receive(:write) do |msg, req|
73
- expect(msg).to eq(:IndexReq)
74
- expect(req[:stream]).not_to be
75
- end
76
-
77
- response_message = Riak::Client::BeefcakeProtobuffsBackend::
78
- RpbIndexResp.new(
79
- keys: %w{asdf asdg asdh}
80
- )
81
- expect(protocol).to receive(:expect).
82
- and_return(response_message)
83
-
84
- results = backend.get_index 'bucket', 'words', 'asdf'..'hjkl'
85
- expect(results).to eq(%w{asdf asdg asdh})
86
- end
87
-
88
- it "returns no results when no keys or terms are returned" do
89
- expect(protocol).to receive(:write) do |msg, req|
90
- expect(msg).to eq(:IndexReq)
91
- expect(req[:stream]).not_to be
92
- end
93
-
94
- response_message = Riak::Client::BeefcakeProtobuffsBackend::
95
- RpbIndexResp.new()
96
-
97
- expect(protocol).to receive(:expect).and_return(response_message)
98
-
99
- results = nil
100
- fetch = proc do
101
- results = backend.get_index 'bucket', 'words', 'asdf'
102
- end
103
-
104
- expect(fetch).not_to raise_error
105
- expect(results).to eq([])
106
- end
107
- end
108
-
109
- context "#mapred" do
110
- let(:mapred) { Riak::MapReduce.new(client).add('test').map("function(){}").map("function(){}") }
111
-
112
- it "returns empty sets for previous phases that don't return anything" do
113
- expect(protocol).to receive(:write)
114
-
115
- message = double(:message, :phase => 1, :response => [{}].to_json)
116
- allow(message).to receive(:done).and_return(false, true)
117
-
118
- expect(protocol).to receive(:expect).
119
- twice.
120
- and_return(message)
121
-
122
- expect(backend.mapred(mapred)).to eq([{}])
123
- end
124
- end
125
-
126
- context "preventing stale writes" do
127
- before do
128
- allow(backend).to receive(:decode_response).and_return(nil)
129
- allow(backend).to receive(:get_server_version).and_return("1.0.3")
130
- end
131
-
132
- let(:robject) do
133
- Riak::RObject.new(client['stale'], 'prevent').tap do |obj|
134
- obj.prevent_stale_writes = true
135
- obj.raw_data = "stale"
136
- obj.content_type = "text/plain"
137
- end
138
- end
139
-
140
- it "sets the if_none_match field when the object is new" do
141
- expect(protocol).to receive(:write) do |msg, req|
142
- expect(msg).to eq(:PutReq)
143
- expect(req.if_none_match).to be_truthy
144
- end
145
- expect(protocol).to receive(:expect).
146
- and_return(:empty)
147
-
148
- backend.store_object(robject)
149
- end
150
-
151
- it "sets the if_not_modified field when the object has a vclock" do
152
- robject.vclock = Base64.encode64("foo")
153
- expect(protocol).to receive(:write) do |msg, req|
154
- expect(msg).to eq(:PutReq)
155
- expect(req.if_not_modified).to be_truthy
156
- end
157
- expect(protocol).to receive(:expect).
158
- and_return(:empty)
159
- backend.store_object(robject)
160
- end
161
- end
162
- end
@@ -1,135 +0,0 @@
1
- require 'spec_helper'
2
- require 'riak/bucket_properties'
3
-
4
- describe Riak::BucketProperties do
5
- let(:client){ instance_double 'Riak::Client' }
6
- let(:backend) do
7
- instance_double('Riak::Client::BeefcakeProtobuffsBackend').tap do |be|
8
- allow(client).to receive(:backend).and_yield be
9
- end
10
- end
11
-
12
- let(:props_operator) do
13
- Riak::Client::BeefcakeProtobuffsBackend.configured?
14
- instance_double(
15
- 'Riak::Client::BeefcakeProtobuffsBackend::BucketPropertiesOperator'
16
- ).tap do |po|
17
- allow(backend).to receive(:bucket_properties_operator).
18
- and_return(po)
19
- end
20
- end
21
-
22
- let(:bucket) do
23
- instance_double('Riak::Bucket').tap do |b|
24
- allow(b).to receive(:client).and_return(client)
25
- allow(b).to receive(:needs_type?).and_return(false)
26
- end
27
- end
28
-
29
- let(:typed_bucket) do
30
- instance_double('Riak::BucketTyped::Bucket').tap do |b|
31
- allow(b).to receive(:client).and_return(client)
32
- end
33
- end
34
-
35
- let(:index_name){ 'index_name' }
36
-
37
- let(:index) do
38
- instance_double('Riak::Search::Index').tap do |i|
39
- allow(i).to receive(:name).and_return(index_name)
40
- allow(i).to receive(:is_a?).with(Riak::Search::Index).and_return(true)
41
- end
42
- end
43
-
44
- subject{ described_class.new bucket }
45
-
46
- it 'is initialized with a bucket' do
47
- p = nil
48
- expect{ p = described_class.new bucket }.to_not raise_error
49
- expect(p.client).to eq client
50
- expect(p.bucket).to eq bucket
51
- end
52
-
53
- it 'initialzies correctly with a bucket-typed bucket' do
54
- p = nil
55
- expect{ p = described_class.new typed_bucket }.to_not raise_error
56
- expect(p.client).to eq client
57
- expect(p.bucket).to eq typed_bucket
58
- end
59
-
60
- it 'provides hash-like access to properties' do
61
- expect(props_operator).to receive(:get).
62
- with(bucket).
63
- and_return('allow_mult' => true)
64
-
65
- expect(subject['allow_mult']).to be
66
-
67
- subject['allow_mult'] = false
68
-
69
- expect(props_operator).to receive(:put).
70
- with(bucket, hash_including('allow_mult' => false))
71
-
72
- subject.store
73
- end
74
-
75
- it 'unwraps index objects into names' do
76
- expect(props_operator).to receive(:get).
77
- with(bucket).
78
- and_return('allow_mult' => true)
79
-
80
- expect{ subject['search_index'] = index }.to_not raise_error
81
-
82
- expect(subject['search_index']).to eq index_name
83
- end
84
-
85
- it 'merges properties from hashes' do
86
- expect(props_operator).to receive(:get).
87
- with(bucket).
88
- and_return('allow_mult' => true)
89
-
90
- expect(subject['allow_mult']).to be
91
-
92
- property_hash = { 'allow_mult' => false }
93
- expect{ subject.merge! property_hash }.to_not raise_error
94
-
95
- expect(props_operator).to receive(:put).
96
- with(bucket, hash_including('allow_mult' => false))
97
-
98
- subject.store
99
- end
100
-
101
- it 'merges properties from other bucket properties objects' do
102
- expect(props_operator).to receive(:get).
103
- with(bucket).
104
- and_return('allow_mult' => true)
105
-
106
- expect(subject['allow_mult']).to be
107
-
108
- other_props = described_class.new typed_bucket
109
- other_props.
110
- instance_variable_set :@cached_props, { 'allow_mult' => false}
111
-
112
- expect{ subject.merge! other_props }.to_not raise_error
113
-
114
- expect(props_operator).to receive(:put).
115
- with(bucket, hash_including('allow_mult' => false))
116
-
117
- subject.store
118
- end
119
-
120
- it 'reloads' do
121
- expect(props_operator).to receive(:get).
122
- with(bucket).
123
- and_return('allow_mult' => true)
124
-
125
- expect(subject['allow_mult']).to be
126
-
127
- expect(props_operator).to receive(:get).
128
- with(bucket).
129
- and_return('allow_mult' => false)
130
-
131
- expect{ subject.reload }.to_not raise_error
132
-
133
- expect(subject['allow_mult']).to_not be
134
- end
135
- end
@@ -1,275 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riak::Bucket do
4
- before :each do
5
- @client = Riak::Client.new
6
- @backend = double("Backend")
7
- allow(@client).to receive(:backend).and_yield(@backend)
8
- allow(@client).to receive(:http).and_yield(@backend)
9
- @bucket = Riak::Bucket.new(@client, "foo")
10
- end
11
-
12
- describe "when initializing" do
13
- it "requires a client and a name" do
14
- expect { Riak::Bucket.new }.to raise_error ArgumentError
15
- expect { Riak::Bucket.new(@client) }.to raise_error ArgumentError
16
- expect { Riak::Bucket.new("foo") }.to raise_error ArgumentError
17
- expect { Riak::Bucket.new("foo", @client) }.to raise_error ArgumentError
18
- expect { Riak::Bucket.new(@client, "foo") }.not_to raise_error
19
- expect { Riak::Bucket.new(@client, '') }.to raise_error(ArgumentError)
20
- end
21
-
22
- it "sets the client and name attributes" do
23
- bucket = Riak::Bucket.new(@client, "foo")
24
- expect(bucket.client).to eq(@client)
25
- expect(bucket.name).to eq("foo")
26
- end
27
- end
28
-
29
- describe "accessing keys" do
30
- it "lists the keys" do
31
- expect(@backend).to receive(:list_keys).with(@bucket, {}).and_return(["bar"])
32
- expect(@bucket.keys).to eq(["bar"])
33
- end
34
-
35
- it "allows streaming keys through block" do
36
- expect(@backend).to receive(:list_keys).with(@bucket, {}).and_yield([]).and_yield(["bar"]).and_yield(["baz"])
37
- all_keys = []
38
- @bucket.keys do |list|
39
- all_keys.concat(list)
40
- end
41
- expect(all_keys).to eq(%w(bar baz))
42
- end
43
-
44
- it "fetches a fresh list of keys" do
45
- expect(@backend).to receive(:list_keys).with(@bucket, {}).twice.and_return(["bar"])
46
- 2.times { expect(@bucket.keys).to eq(['bar']) }
47
- end
48
-
49
- it "warns about the expense of list-keys when warnings are not disabled" do
50
- Riak.disable_list_keys_warnings = false
51
- allow(@backend).to receive(:list_keys).and_return(%w{test test2})
52
- expect(@bucket).to receive(:warn)
53
- @bucket.keys
54
- Riak.disable_list_keys_warnings = true
55
- end
56
-
57
- it "allows a specified timeout when listing keys" do
58
- expect(@backend).to receive(:list_keys).with(@bucket, timeout: 1234).and_return(%w{bar})
59
-
60
- keys = @bucket.keys timeout: 1234
61
-
62
- expect(keys).to eq(%w{bar})
63
- end
64
- end
65
-
66
- describe "accessing a counter" do
67
- it "returns a counter object" do
68
- expect(Riak::Counter).to receive(:new).with(@bucket, 'asdf').and_return('example counter')
69
-
70
- new_counter = @bucket.counter 'asdf'
71
-
72
- expect(new_counter).to eq('example counter')
73
- end
74
- end
75
-
76
- describe "setting the bucket properties" do
77
- it "prefetches the properties when they are not present" do
78
- allow(@backend).to receive(:set_bucket_props)
79
- expect(@backend).to receive(:get_bucket_props).with(@bucket, { }).and_return({"name" => "foo"})
80
- @bucket.props = {"precommit" => []}
81
- end
82
-
83
- it "sets the new properties on the bucket" do
84
- @bucket.instance_variable_set(:@props, {}) # Pretend they are there
85
- expect(@backend).to receive(:set_bucket_props).with(@bucket, { :name => "foo" }, nil)
86
- @bucket.props = { :name => "foo" }
87
- end
88
-
89
- it "raises an error if an invalid type is given" do
90
- expect { @bucket.props = "blah" }.to raise_error(ArgumentError)
91
- end
92
- end
93
-
94
- describe "fetching the bucket properties" do
95
- it "fetches properties on first access" do
96
- expect(@bucket.instance_variable_get(:@props)).to be_nil
97
- expect(@backend).to receive(:get_bucket_props).with(@bucket, { }).and_return({"name" => "foo"})
98
- expect(@bucket.props).to eq({"name" => "foo"})
99
- end
100
-
101
- it "memoizes fetched properties" do
102
- expect(@backend).to receive(:get_bucket_props).once.with(@bucket, { }).and_return({"name" => "foo"})
103
- expect(@bucket.props).to eq({"name" => "foo"})
104
- expect(@bucket.props).to eq({"name" => "foo"})
105
- end
106
- end
107
-
108
- describe "clearing the bucket properties" do
109
- it "sends the request and delete the internal properties cache" do
110
- expect(@client).to receive(:clear_bucket_props).with(@bucket).and_return(true)
111
- expect(@bucket.clear_props).to be_truthy
112
- expect(@bucket.instance_variable_get(:@props)).to be_nil
113
- end
114
- end
115
-
116
- describe "fetching an object" do
117
- it "fetches the object via the backend" do
118
- expect(@backend).to receive(:fetch_object).with(@bucket, "db", {}).and_return(nil)
119
- @bucket.get("db")
120
- end
121
-
122
- it "uses the specified R quroum" do
123
- expect(@backend).to receive(:fetch_object).with(@bucket, "db", {:r => 2}).and_return(nil)
124
- @bucket.get("db", :r => 2)
125
- end
126
-
127
- it "disallows fetching an object with a zero-length key" do
128
- ## TODO: This actually tests the Client object, but there is no suite
129
- ## of tests for its generic interface.
130
- expect { @bucket.get('') }.to raise_error(ArgumentError)
131
- end
132
- end
133
-
134
- describe "creating a new blank object" do
135
- it "instantiates the object with the given key, default to JSON" do
136
- obj = @bucket.new('bar')
137
- expect(obj).to be_kind_of(Riak::RObject)
138
- expect(obj.key).to eq('bar')
139
- expect(obj.content_type).to eq('application/json')
140
- end
141
- end
142
-
143
- describe "fetching or creating a new object" do
144
- let(:not_found_error){ Riak::ProtobuffsFailedRequest.new :not_found, 'not found' }
145
- let(:other_error){ Riak::ProtobuffsFailedRequest.new :server_error, 'server error' }
146
-
147
- it "returns the existing object if present" do
148
- @object = double("RObject")
149
- expect(@backend).to receive(:fetch_object).with(@bucket, "db", {}).and_return(@object)
150
- expect(@bucket.get_or_new('db')).to eq(@object)
151
- end
152
-
153
- it "creates a new blank object if the key does not exist" do
154
- expect(@backend).to receive(:fetch_object).and_raise(not_found_error)
155
- obj = @bucket.get_or_new('db')
156
- expect(obj.key).to eq('db')
157
- expect(obj.data).to be_blank
158
- end
159
-
160
- it "bubbles up non-ok non-missing errors" do
161
- expect(@backend).to receive(:fetch_object).and_raise(other_error)
162
- expect { @bucket.get_or_new('db') }.to raise_error(Riak::ProtobuffsFailedRequest)
163
- end
164
-
165
- it "passes the given R quorum parameter to the backend" do
166
- @object = double("RObject")
167
- expect(@backend).to receive(:fetch_object).with(@bucket, "db", {:r => "all"}).and_return(@object)
168
- expect(@bucket.get_or_new('db', :r => "all")).to eq(@object)
169
- end
170
- end
171
-
172
- describe "fetching multiple objects" do
173
- it 'gets each object individually' do
174
- @object1 = double('obj1')
175
- @object2 = double('obj2')
176
- expect(@bucket).to receive(:[]).with('key1').and_return(@object1)
177
- expect(@bucket).to receive(:[]).with('key2').and_return(@object2)
178
-
179
- @results = @bucket.get_many %w{key1 key2}
180
-
181
- expect(@results['key1']).to eq(@object1)
182
- expect(@results['key2']).to eq(@object2)
183
- end
184
- end
185
-
186
- describe "querying an index" do
187
- it "lists the matching keys" do
188
- expect(@backend).
189
- to receive(:get_index).
190
- with(@bucket, "test_bin", "testing", {return_terms: true}).
191
- and_return(Riak::IndexCollection.new_from_json({
192
- 'results' => [
193
- {'testing' => 'asdf'},
194
- {'testing' => 'hjkl'}]
195
- }.to_json))
196
- result = @bucket.get_index("test_bin", "testing", return_terms: true)
197
-
198
- expect(result).to be_a Riak::IndexCollection
199
- expect(result.to_a).to eq(%w{asdf hjkl})
200
- expect(result.with_terms).to eq({'testing' => %w{asdf hjkl}})
201
- end
202
- end
203
-
204
- describe "get/set allow_mult property" do
205
- before :each do
206
- allow(@backend).to receive(:get_bucket_props).and_return({"allow_mult" => false})
207
- end
208
-
209
- it "extracts the allow_mult property" do
210
- expect(@bucket.allow_mult).to be_falsey
211
- end
212
-
213
- it "sets the allow_mult property" do
214
- expect(@bucket).to receive(:props=).with(hash_including('allow_mult' => true))
215
- @bucket.allow_mult = true
216
- end
217
- end
218
-
219
- describe "get/set the N value" do
220
- before :each do
221
- allow(@backend).to receive(:get_bucket_props).and_return({"n_val" => 3})
222
- end
223
-
224
- it "extracts the N value" do
225
- expect(@bucket.n_value).to eq(3)
226
- end
227
-
228
- it "sets the N value" do
229
- expect(@bucket).to receive(:props=).with(hash_including('n_val' => 1))
230
- @bucket.n_value = 1
231
- end
232
- end
233
-
234
- [:r, :w, :dw, :rw].each do |q|
235
- describe "get/set the default #{q} quorum" do
236
- before :each do
237
- allow(@backend).to receive(:get_bucket_props).and_return({"r" => "quorum", "w" => "quorum", "dw" => "quorum", "rw" => "quorum"})
238
- end
239
-
240
- it "extracts the default #{q} quorum" do
241
- expect(@bucket.send(q)).to eq("quorum")
242
- end
243
-
244
- it "sets the #{q} quorum" do
245
- expect(@bucket).to receive(:props=).with(hash_including("#{q}" => 1))
246
- @bucket.send("#{q}=", 1)
247
- end
248
- end
249
- end
250
-
251
- describe "checking whether a key exists" do
252
- it "returns true if the object does exist" do
253
- expect(@backend).to receive(:fetch_object).and_return(double)
254
- expect(@bucket.exists?("foo")).to be_truthy
255
- end
256
-
257
- it "returns false if the object doesn't exist" do
258
- expect(@backend).to receive(:fetch_object).
259
- and_raise(Riak::ProtobuffsFailedRequest.new(:not_found, "not found"))
260
- expect(@bucket.exists?("foo")).to be_falsey
261
- end
262
- end
263
-
264
- describe "deleting an object" do
265
- it "deletes a key from within the bucket" do
266
- expect(@backend).to receive(:delete_object).with(@bucket, "bar", {})
267
- @bucket.delete('bar')
268
- end
269
-
270
- it "uses the specified RW quorum" do
271
- expect(@backend).to receive(:delete_object).with(@bucket, "bar", {:rw => "all"})
272
- @bucket.delete('bar', :rw => "all")
273
- end
274
- end
275
- end