-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
287 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--color | ||
--tty | ||
--format progress | ||
--order random | ||
--backtrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
appraise 'rails3.1' do | ||
gem 'activesupport', '~> 3.1.0' | ||
gem 'activerecord', '~> 3.1.0' | ||
end | ||
|
||
appraise 'rails3.2' do | ||
gem 'activesupport', '~> 3.2.0' | ||
gem 'activerecord', '~> 3.2.0' | ||
end | ||
|
||
appraise 'rails4.0' do | ||
gem 'activesupport', '~> 4.0.0' | ||
gem 'activerecord', '~> 4.0.0' | ||
end | ||
|
||
appraise 'rails4.1' do | ||
gem 'activesupport', '~> 4.1.0' | ||
gem 'activerecord', '~> 4.1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in redis_counters-dumpers.gemspec | ||
|
||
group :development, :test do | ||
gem 'combustion', github: 'pat/combustion', ref: '7d0d24c3f36ce0eb336177fc493be0721bc26665' | ||
end | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
RAILS_ENV = test | ||
BUNDLE = RAILS_ENV=${RAILS_ENV} bundle | ||
BUNDLE_OPTIONS = -j 2 | ||
RSPEC = rspec | ||
APPRAISAL = appraisal | ||
|
||
all: test | ||
|
||
test: config/database bundler/install appraisal/install | ||
${BUNDLE} exec ${APPRAISAL} ${RSPEC} spec 2>&1 | ||
|
||
config/database: | ||
touch spec/internal/config/database.yml | ||
echo 'test:' >> spec/internal/config/database.yml | ||
echo ' adapter: postgresql' >> spec/internal/config/database.yml | ||
echo ' database: docker' >> spec/internal/config/database.yml | ||
echo ' username: docker' >> spec/internal/config/database.yml | ||
echo ' host: localhost' >> spec/internal/config/database.yml | ||
echo ' min_messages: warning' >> spec/internal/config/database.yml | ||
|
||
bundler/install: | ||
if ! gem list bundler -i > /dev/null; then \ | ||
gem install bundler; \ | ||
fi | ||
${BUNDLE} install ${BUNDLE_OPTIONS} | ||
|
||
appraisal/install: | ||
${BUNDLE} exec ${APPRAISAL} install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "activesupport", "~> 3.1.0" | ||
gem "activerecord", "~> 3.1.0" | ||
|
||
group :development, :test do | ||
gem "combustion", :github => "pat/combustion", :ref => "7d0d24c3f36ce0eb336177fc493be0721bc26665" | ||
end | ||
|
||
gemspec :path => "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "activesupport", "~> 3.2.0" | ||
gem "activerecord", "~> 3.2.0" | ||
|
||
group :development, :test do | ||
gem "combustion", :github => "pat/combustion", :ref => "7d0d24c3f36ce0eb336177fc493be0721bc26665" | ||
end | ||
|
||
gemspec :path => "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "activesupport", "~> 4.0.0" | ||
gem "activerecord", "~> 4.0.0" | ||
|
||
group :development, :test do | ||
gem "combustion", :github => "pat/combustion", :ref => "7d0d24c3f36ce0eb336177fc493be0721bc26665" | ||
end | ||
|
||
gemspec :path => "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "activesupport", "~> 4.1.0" | ||
gem "activerecord", "~> 4.1.0" | ||
|
||
group :development, :test do | ||
gem "combustion", :github => "pat/combustion", :ref => "7d0d24c3f36ce0eb336177fc493be0721bc26665" | ||
end | ||
|
||
gemspec :path => "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'active_record' | ||
require 'redis_counters/dumpers/version' | ||
|
||
module RedisCounters | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class StatsAggTotal < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class StatsByDay < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class StatsTotal < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
database.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ActiveRecord::Schema.define do | ||
create_table :stats_by_days do |t| | ||
t.integer :record_id, null: false | ||
t.integer :column_id, null: false | ||
t.date :date, null: false | ||
t.integer :hits, null: false, default: 0 | ||
end | ||
|
||
add_index :stats_by_days, [:record_id, :column_id, :date], unique: true | ||
|
||
create_table :stats_totals do |t| | ||
t.integer :record_id, null: false | ||
t.integer :column_id, null: false | ||
t.integer :hits, null: false, default: 0 | ||
end | ||
|
||
add_index :stats_totals, [:record_id, :column_id], unique: true | ||
|
||
create_table :stats_agg_totals do |t| | ||
t.integer :record_id, null: false | ||
t.integer :hits, null: false, default: 0 | ||
end | ||
|
||
add_index :stats_agg_totals, [:record_id], unique: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'spec_helper' | ||
|
||
describe RedisCounters::Dumpers::Engine do | ||
let(:dumper) do | ||
RedisCounters::Dumpers::Engine.build do | ||
name :stats_totals | ||
fields record_id: :integer, | ||
column_id: :integer, | ||
value: :integer, | ||
date: :date | ||
|
||
destination do | ||
model StatsByDay | ||
take :record_id, :column_id, :hits, :date | ||
key_fields :record_id, :column_id, :date | ||
increment_fields :hits | ||
map :hits, to: :value | ||
condition 'target.date = :date' | ||
end | ||
|
||
destination do | ||
model StatsTotal | ||
take :record_id, :column_id, :hits | ||
key_fields :record_id, :column_id | ||
increment_fields :hits | ||
map :hits, to: :value | ||
end | ||
|
||
destination do | ||
model StatsAggTotal | ||
take :record_id, :hits | ||
key_fields :record_id | ||
increment_fields :hits | ||
map :hits, to: 'sum(value)' | ||
group_by :record_id | ||
end | ||
|
||
on_before_merge do |dumper, _connection| | ||
dumper.common_params = {date: dumper.date.strftime('%Y-%m-%d')} | ||
end | ||
end | ||
end | ||
|
||
let(:prev_date) { Date.new(2015, 1, 19) } | ||
let(:prev_date_s) { prev_date.strftime('%Y-%m-%d') } | ||
|
||
let(:date) { Date.new(2015, 1, 20) } | ||
let(:date_s) { date.strftime('%Y-%m-%d') } | ||
|
||
let(:counter) do | ||
RedisCounters.create_counter(Redis.current, | ||
counter_class: RedisCounters::HashCounter, | ||
counter_name: :record_hits_by_day, | ||
group_keys: [:record_id, :column_id], | ||
partition_keys: [:date] | ||
) | ||
end | ||
|
||
before do | ||
allow(dumper).to receive(:redis_session).and_return(MockRedis.new) | ||
end | ||
|
||
describe '#process!' do | ||
before do | ||
counter.increment(date: prev_date_s, record_id: 1, column_id: 100) | ||
counter.increment(date: prev_date_s, record_id: 1, column_id: 200) | ||
counter.increment(date: prev_date_s, record_id: 1, column_id: 200) | ||
counter.increment(date: prev_date_s, record_id: 2, column_id: 100) | ||
|
||
dumper.process!(counter, prev_date) | ||
|
||
counter.increment(date: date_s, record_id: 1, column_id: 100) | ||
counter.increment(date: date_s, record_id: 1, column_id: 200) | ||
counter.increment(date: date_s, record_id: 1, column_id: 200) | ||
counter.increment(date: date_s, record_id: 2, column_id: 100) | ||
|
||
dumper.process!(counter, date) | ||
end | ||
|
||
Then { expect(StatsByDay.count).to eq 6 } | ||
And { expect(StatsByDay.where(record_id: 1, column_id: 100, date: prev_date).first.hits).to eq 1 } | ||
And { expect(StatsByDay.where(record_id: 1, column_id: 200, date: prev_date).first.hits).to eq 2 } | ||
And { expect(StatsByDay.where(record_id: 2, column_id: 100, date: prev_date).first.hits).to eq 1 } | ||
And { expect(StatsByDay.where(record_id: 1, column_id: 100, date: date).first.hits).to eq 1 } | ||
And { expect(StatsByDay.where(record_id: 1, column_id: 200, date: date).first.hits).to eq 2 } | ||
And { expect(StatsByDay.where(record_id: 2, column_id: 100, date: date).first.hits).to eq 1 } | ||
|
||
And { expect(StatsTotal.count).to eq 3 } | ||
And { expect(StatsTotal.where(record_id: 1, column_id: 100).first.hits).to eq 2 } | ||
And { expect(StatsTotal.where(record_id: 1, column_id: 200).first.hits).to eq 4 } | ||
And { expect(StatsTotal.where(record_id: 2, column_id: 100).first.hits).to eq 2 } | ||
|
||
And { expect(StatsAggTotal.count).to eq 2 } | ||
And { expect(StatsAggTotal.where(record_id: 1).first.hits).to eq 6 } | ||
And { expect(StatsAggTotal.where(record_id: 2).first.hits).to eq 2 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# coding: utf-8 | ||
require 'bundler/setup' | ||
require 'redis_counters/dumpers' | ||
|
||
require 'combustion' | ||
Combustion.initialize! :active_record | ||
|
||
require 'rspec/rails' | ||
require 'rspec/given' | ||
|
||
require 'mock_redis' | ||
require 'redis' | ||
Redis.current = MockRedis.new | ||
|
||
RSpec.configure do |config| | ||
config.use_transactional_fixtures = true | ||
config.before { Redis.current.flushdb } | ||
end |