slave_pools 0.1.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +0,0 @@
1
- module SlavePoolsModule
2
- class SlavePool
3
-
4
- attr_accessor :name, :slaves,:pool_size, :current_index
5
-
6
- def initialize(name, slaves)
7
- @name = name
8
- @slaves = slaves
9
- @pool_size = @slaves.length
10
- @current_index = 0
11
- end
12
-
13
- def current
14
- @slaves[@current_index]
15
- end
16
-
17
- def next
18
- next_index! if @pool_size != 1
19
- current
20
- end
21
-
22
- protected
23
-
24
- def next_index!
25
- @current_index = (@current_index + 1) % @pool_size
26
- end
27
-
28
- end
29
- end
data/slave_pools.gemspec DELETED
@@ -1,25 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{slave_pools}
5
- s.version = "0.1.2"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Dan Drabik"]
9
- s.description = "Connection proxy for ActiveRecord for single master / multiple slave database groups"
10
- s.email = "dan@kickstarter.com"
11
- s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
12
- s.files = ["lib/slave_pools.rb", "lib/slave_pools/active_record_extensions.rb", "lib/slave_pools/connection_proxy.rb", "lib/slave_pools/observer_extensions.rb", "lib/slave_pools/query_cache_compat.rb", "lib/slave_pools/slave_pool.rb", "LICENSE", "README.rdoc", "spec/config/database.yml", "spec/connection_proxy_spec.rb", "spec/slave_pool_spec.rb","spec/slave_pools_spec.rb", "spec/spec_helper.rb", "slave_pools.gemspec"]
13
- s.has_rdoc = true
14
- s.homepage = "https://github.com/kickstarter/slave_pools"
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "slave_pools", "--main", "README.rdoc"]
16
- s.require_paths = ["lib"]
17
- s.rubygems_version = %q{1.3.1}
18
- s.summary = "Connection proxy for ActiveRecord for single master / multiple slave database groups"
19
- s.license = 'MIT'
20
-
21
- s.add_dependency('activerecord', ["~> 3.2.12"])
22
- s.add_development_dependency('mysql2', ["~> 0.3.11"])
23
- s.add_development_dependency('rspec')
24
- s.add_development_dependency('rake')
25
- end
@@ -1,43 +0,0 @@
1
- login: &login
2
- adapter: mysql2
3
- username: root
4
- password:
5
- host: localhost
6
- encoding: utf8
7
- read_timeout: 1
8
-
9
- readonly_login: &readonly_login
10
- adapter: mysql2
11
- username: read_only
12
- password: readme
13
- host: localhost
14
- encoding: utf8
15
- read_timeout: 1
16
-
17
- test:
18
- database: test_db
19
- <<: *login
20
-
21
- test_pool_secondary_name_db1:
22
- database: test_db
23
- <<: *readonly_login
24
-
25
- test_pool_secondary_name_db2:
26
- database: test_db
27
- <<: *readonly_login
28
-
29
- test_pool_secondary_name_db3:
30
- database: test_db
31
- <<: *readonly_login
32
-
33
- test_pool_default_name_db1:
34
- database: test_db
35
- <<: *readonly_login
36
-
37
- test_pool_default_name_db2:
38
- database: test_db
39
- <<: *readonly_login
40
-
41
- test_pool_default_name_fake_db:
42
- database: fake_db_that_doesnt_exist #do not create this db, used to test the connection
43
- <<: *readonly_login
@@ -1,43 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe SlavePoolsModule::SlavePool do
4
-
5
- context "Multiple slaves" do
6
- before do
7
- @slaves = ["db1", "db2", "db3"]
8
- @slave_pool = SlavePoolsModule::SlavePool.new("name", @slaves.clone)
9
- end
10
- specify {@slave_pool.pool_size.should == 3}
11
-
12
- it "should return items in a round robin fashion" do
13
- first = @slaves.shift
14
- @slave_pool.current.should == first
15
- @slaves.each do |item|
16
- @slave_pool.next.should == item
17
- end
18
- @slave_pool.next.should == first
19
- end
20
- end
21
-
22
- context "Single Slave" do
23
- before do
24
- @slaves = ["db1"]
25
- @slave_pool = SlavePoolsModule::SlavePool.new("name", @slaves.clone)
26
- end
27
- specify {@slave_pool.pool_size.should == 1}
28
-
29
- it "should return items in a round robin fashion" do
30
- @slave_pool.current.should == "db1"
31
- @slave_pool.next.should == "db1"
32
- @slave_pool.next.should == "db1"
33
- end
34
-
35
- it "shouldn't call next_reader! if there is only one slave" do
36
- @slave_pool.should_not_receive(:next_index!)
37
- @slave_pool.current.should == "db1"
38
- @slave_pool.next.should == "db1"
39
- @slave_pool.next.should == "db1"
40
- end
41
- end
42
- end
43
-