Skip to content

Commit

Permalink
chore(specs): reorganize unique lists specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Napolskih committed Oct 17, 2014
1 parent accf293 commit 7521fd8
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 160 deletions.
3 changes: 2 additions & 1 deletion spec/redis_counters/unique_values_lists/fast_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'

describe RedisCounters::UniqueValuesLists::Fast do
it_behaves_like 'unique_values_lists'
it_behaves_like 'unique_values_lists/common'
it_behaves_like 'unique_values_lists/set'
end
3 changes: 2 additions & 1 deletion spec/redis_counters/unique_values_lists/standard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'spec_helper'

describe RedisCounters::UniqueValuesLists::Standard do
it_behaves_like 'unique_values_lists'
it_behaves_like 'unique_values_lists/common'
it_behaves_like 'unique_values_lists/set'

context 'when check partitions list' do
let(:redis) { MockRedis.new }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8
shared_examples_for 'unique_values_lists' do
shared_examples_for 'unique_values_lists/common' do
let(:redis) { MockRedis.new }
let(:values) { rand(10) + 1 }

let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0]
:counter_name => :test_counter,
:value_keys => [:param0]
} }

let(:counter) { described_class.new(redis, options) }
Expand All @@ -19,139 +19,37 @@

context 'when unknown value_key given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1]
:counter_name => :test_counter,
:value_keys => [:param0, :param1]
} }

it { expect { counter.add(:param1 => 1) }.to raise_error KeyError }
end

context 'when unknown cluster_key given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0],
:cluster_keys => [:param1, :param2],
:counter_name => :test_counter,
:value_keys => [:param0],
:cluster_keys => [:param1, :param2],
} }

it { expect { counter.add(:param0 => 1, :param1 => 2) }.to raise_error KeyError }
end

context 'when unknown partition_key given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0],
:partition_keys => [:param1, :param2],
:counter_name => :test_counter,
:value_keys => [:param0],
:partition_keys => [:param1, :param2],
} }

it { expect { counter.add(:param0 => 1, :param1 => 2) }.to raise_error KeyError }
end

context 'when cluster and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:param2],
:partition_keys => [:param3, :param4]
} }

before { values.times { counter.add(:param0 => 1, :param1 => 2, :param2 => :cluster1, :param3 => :part1, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 2, :param1 => 1, :param2 => :cluster1, :param3 => :part1, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 3, :param1 => 2, :param2 => :cluster1, :param3 => :part2, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 4, :param1 => 5, :param2 => :cluster2, :param3 => :part1, :param4 => :part2) } }

it { expect(redis.keys('*')).to have(5).key }

it { expect(redis.exists("test_counter:cluster1:part1:part2")).to be_true }
it { expect(redis.exists("test_counter:cluster1:part2:part2")).to be_true }
it { expect(redis.exists("test_counter:cluster2:part1:part2")).to be_true }

it { expect(redis.smembers("test_counter:cluster1:part1:part2")).to have(2).keys }
it { expect(redis.smembers("test_counter:cluster1:part2:part2")).to have(1).keys }
it { expect(redis.smembers("test_counter:cluster2:part1:part2")).to have(1).keys }

it { expect(redis.smembers("test_counter:cluster1:part1:part2")).to include '1:2' }
it { expect(redis.smembers("test_counter:cluster1:part1:part2")).to include '2:1' }
it { expect(redis.smembers("test_counter:cluster1:part2:part2")).to include '3:2' }
it { expect(redis.smembers("test_counter:cluster2:part1:part2")).to include '4:5' }
end

context 'when cluster and partition keys no given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1]
} }

before { values.times { counter.add(:param0 => 1, :param1 => 2) } }
before { values.times { counter.add(:param0 => 1, :param1 => 2) } }
before { values.times { counter.add(:param0 => 2, :param1 => 1) } }
before { values.times { counter.add(:param0 => 3, :param1 => 2) } }

it { expect(redis.keys('*')).to have(1).key }

it { expect(redis.exists("test_counter")).to be_true }
it { expect(redis.smembers("test_counter")).to have(3).keys }

it { expect(redis.smembers("test_counter")).to include '1:2' }
it { expect(redis.smembers("test_counter")).to include '2:1' }
it { expect(redis.smembers("test_counter")).to include '3:2' }
end

context 'when no cluster keys given, but partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:param3, :param4]
} }

before { values.times { counter.add(:param0 => 1, :param1 => 2, :param3 => :part1, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 2, :param1 => 1, :param3 => :part1, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 3, :param1 => 2, :param3 => :part2, :param4 => :part2) } }
before { values.times { counter.add(:param0 => 4, :param1 => 5, :param3 => :part1, :param4 => :part2) } }

it { expect(redis.keys('*')).to have(3).key }

it { expect(redis.exists("test_counter:part1:part2")).to be_true }
it { expect(redis.exists("test_counter:part2:part2")).to be_true }

it { expect(redis.smembers("test_counter:part1:part2")).to have(3).keys }
it { expect(redis.smembers("test_counter:part2:part2")).to have(1).keys }

it { expect(redis.smembers("test_counter:part1:part2")).to include '1:2' }
it { expect(redis.smembers("test_counter:part1:part2")).to include '2:1' }
it { expect(redis.smembers("test_counter:part2:part2")).to include '3:2' }
it { expect(redis.smembers("test_counter:part1:part2")).to include '4:5' }
end

context 'when cluster keys given, but partition keys not given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:param2]
} }

before { values.times { counter.add(:param0 => 1, :param1 => 2, :param2 => :cluster1) } }
before { values.times { counter.add(:param0 => 2, :param1 => 1, :param2 => :cluster1) } }
before { values.times { counter.add(:param0 => 3, :param1 => 2, :param2 => :cluster1) } }
before { values.times { counter.add(:param0 => 4, :param1 => 5, :param2 => :cluster2) } }

it { expect(redis.keys('*')).to have(2).key }

it { expect(redis.exists("test_counter:cluster1")).to be_true }
it { expect(redis.exists("test_counter:cluster2")).to be_true }

it { expect(redis.smembers("test_counter:cluster1")).to have(3).keys }
it { expect(redis.smembers("test_counter:cluster2")).to have(1).keys }

it { expect(redis.smembers("test_counter:cluster1")).to include '1:2' }
it { expect(redis.smembers("test_counter:cluster1")).to include '2:1' }
it { expect(redis.smembers("test_counter:cluster1")).to include '3:2' }
it { expect(redis.smembers("test_counter:cluster2")).to include '4:5' }
end

context 'when block given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0]
:counter_name => :test_counter,
:value_keys => [:param0]
} }

context 'when item added' do
Expand Down Expand Up @@ -180,10 +78,10 @@

context 'when cluster and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одном кластере и партиции
Expand Down Expand Up @@ -238,9 +136,9 @@

context 'when not cluster keys given and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одной партиции
Expand Down Expand Up @@ -278,9 +176,9 @@

context 'when cluster keys given and partition keys not given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster]
} }

# 2 разных знач в одном кластере
Expand Down Expand Up @@ -316,10 +214,10 @@

context 'when cluster and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одном кластере и партиции
Expand All @@ -338,17 +236,17 @@
# новое значение в новом подкластере
before { values.times { counter.add(:param0 => 6, :param1 => 7, :cluster => :cluster1, :subcluster => :subcluster2, :part => :part1, :subpart => :subpart1) } }

context 'when no cluster given' do
it { expect { counter.data }.to raise_error ArgumentError }
end

context 'when no leaf cluster given' do
it { expect { counter.data(:cluster => :cluster1) }.to raise_error KeyError }
end

context 'when unknown cluster given' do
it { expect(counter.data(:cluster => :unknown_cluster, :subcluster => :subcluster)).to have(0).partitions }
end
# context 'when no cluster given' do
# it { expect { counter.data }.to raise_error ArgumentError }
# end
#
# context 'when no leaf cluster given' do
# it { expect { counter.data(:cluster => :cluster1) }.to raise_error KeyError }
# end
#
# context 'when unknown cluster given' do
# it { expect(counter.data(:cluster => :unknown_cluster, :subcluster => :subcluster)).to have(0).partitions }
# end

context 'when no partition given' do
it { expect(counter.data(cluster1_subcluster1)).to have(4).rows }
Expand Down Expand Up @@ -377,9 +275,9 @@

context 'when not cluster keys given and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одной партиции
Expand Down Expand Up @@ -412,16 +310,17 @@
end

context 'when leaf partition given' do
it { expect(counter.data(:part => :part1, 'subpart' => 'subpart1')).to have(2).items }
it { expect(counter.data(:part => :part1, 'subpart' => 'subpart1')).to include ({'param0' => '1', 'param1' => '2'}) }
it { expect(counter.data(:part => :part1, 'subpart' => 'subpart1').first).to include ({'param0' => '1', 'param1' => '3'}) }
it { expect(counter.data(:part => :part1, 'subpart' => 'subpart1')).to include ({'param0' => '1', 'param1' => '3'}) }
end
end

context 'when cluster keys given and partition keys not given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster]
} }

# 2 разных знач в одном кластере
Expand Down Expand Up @@ -457,10 +356,10 @@

context 'when cluster and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одном кластере и партиции
Expand Down Expand Up @@ -539,10 +438,10 @@

context 'when cluster and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:cluster_keys => [:cluster, :subcluster],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одном кластере и партиции
Expand Down Expand Up @@ -596,9 +495,9 @@

context 'when cluster not given and partition keys given' do
let(:options) { {
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
:counter_name => :test_counter,
:value_keys => [:param0, :param1],
:partition_keys => [:part, :subpart]
} }

# 2 разных знач в одном кластере и партиции
Expand Down
Loading

0 comments on commit 7521fd8

Please sign in to comment.