spec/integration/riak/crdt_spec.rb in riak-client-2.4.1 vs spec/integration/riak/crdt_spec.rb in riak-client-2.5.0
- old
+ new
@@ -1,7 +1,8 @@
require 'spec_helper'
require 'riak'
+require 'riak/errors/failed_request'
describe "CRDTs", integration: true, test_client: true do
let(:bucket) { random_bucket }
describe 'Riak-assigned names' do
@@ -80,10 +81,11 @@
it { is_expected.to eq subject }
it { is_expected.to eq same }
it { is_expected.to eq similar }
end
end
+
describe 'sets' do
subject { Riak::Crdt::Set.new bucket, random_key }
it 'allows straightforward set ops' do
@@ -255,8 +257,76 @@
it "doesn't error on an unset flag" do
expect{ subject.flags['unset'] }.to_not raise_error
expect(subject.flags['other_unset']).to_not be
end
+ end
+ end
+
+ describe 'HLLs', hll: true do
+ before(:each) do
+ begin
+ hlls = test_client.bucket_type Riak::Crdt::DEFAULT_BUCKET_TYPES[:hll]
+ hlls.properties
+ rescue Riak::ProtobuffsErrorResponse
+ skip('HyperLogLog bucket-type not found or active.')
+ end
+ end
+
+ subject { Riak::Crdt::HyperLogLog.new bucket, random_key }
+
+ it 'allows straightforward HLL ops' do
+ addition = random_key
+
+ subject.add addition
+
+ expect(subject.value).to be_a(Integer)
+ expect(subject.value).to eq 1
+ end
+
+ it 'asks for and accepts a returned body by default' do
+ other = Riak::Crdt::HyperLogLog.new subject.bucket, subject.key
+
+ other.add 'coffee'
+
+ expect(other.value).to be_a(Integer)
+ expect(other.value).to eq 1
+
+ expect(subject.value).to eq 1
+
+ subject.add 'tea'
+
+ expect(subject.value).to be_a(Integer)
+ expect(subject.value).to eq 2
+
+ other.reload
+ expect(other.value).to eq 2
+
+ other.add 'juice'
+
+ expect(other.value).to be_a(Integer)
+ expect(other.value).to eq 3
+
+ # repeat input to verify the HLL value doesn't increment
+ other.add 'juice'
+
+ expect(other.value).to be_a(Integer)
+ expect(other.value).to eq 3
+
+ expect(subject.dirty?).to_not be
+ end
+
+ it 'allows batched HLL ops' do
+ subject.add 'zero'
+ subject.reload
+
+ subject.batch do |s|
+ s.add 'first'
+ s.add 'second'
+ s.add 'second'
+ end
+
+ expect(subject.value).to be_a(Integer)
+ expect(subject.value).to eq 3
end
end
end