ar-octopus 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -28,8 +28,8 @@ begin
28
28
  gem.homepage = "http://github.com/tchandy/octopus"
29
29
  gem.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
30
30
  gem.add_development_dependency "rspec", ">= 1.2.9"
31
- gem.add_dependency('activerecord')
32
- gem.version = "0.0.11"
31
+ gem.add_dependency('activerecord', '>= 3.0.0beta')
32
+ gem.version = "0.0.12"
33
33
  end
34
34
  Jeweler::GemcutterTasks.new
35
35
  rescue LoadError
data/ar-octopus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ar-octopus}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
12
- s.date = %q{2010-06-28}
12
+ s.date = %q{2010-06-29}
13
13
  s.description = %q{This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.}
14
14
  s.email = %q{tchandy@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -101,14 +101,14 @@ Gem::Specification.new do |s|
101
101
 
102
102
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
103
103
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
104
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
104
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0beta"])
105
105
  else
106
106
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
107
- s.add_dependency(%q<activerecord>, [">= 0"])
107
+ s.add_dependency(%q<activerecord>, [">= 3.0.0beta"])
108
108
  end
109
109
  else
110
110
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
111
- s.add_dependency(%q<activerecord>, [">= 0"])
111
+ s.add_dependency(%q<activerecord>, [">= 3.0.0beta"])
112
112
  end
113
113
  end
114
114
 
data/lib/octopus/proxy.rb CHANGED
@@ -3,7 +3,7 @@ class Octopus::Proxy
3
3
 
4
4
  def initialize(config)
5
5
  initialize_shards(config)
6
- initialize_replication() if have_a_valid_configuration?(config) && config[Octopus.env()]["replicated"]
6
+ initialize_replication(config) if have_a_valid_configuration?(config) && config[Octopus.env()]["replicated"]
7
7
  end
8
8
 
9
9
  def initialize_shards(config)
@@ -31,8 +31,9 @@ class Octopus::Proxy
31
31
  end
32
32
  end
33
33
 
34
- def initialize_replication()
34
+ def initialize_replication(config)
35
35
  @replicated = true
36
+ @entire_replicated = config[Octopus.env()]["entire_replicated"]
36
37
  @slaves_list = @shards.keys.map {|sym| sym.to_s}.sort
37
38
  @slaves_list.delete('master')
38
39
  end
@@ -187,7 +188,7 @@ class Octopus::Proxy
187
188
  def send_queries_to_selected_slave(method, *args, &block)
188
189
  old_shard = self.current_shard
189
190
 
190
- if current_model.read_inheritable_attribute(:replicated)
191
+ if current_model.read_inheritable_attribute(:replicated) || @entire_replicated
191
192
  if !using_enabled
192
193
  self.current_shard = @slaves_list.shift.to_sym
193
194
  @slaves_list << self.current_shard
@@ -73,4 +73,28 @@ production_replicated:
73
73
  slave4:
74
74
  adapter: mysql
75
75
  host: localhost
76
- database: octopus_shard5
76
+ database: octopus_shard5
77
+
78
+
79
+ production_entire_replicated:
80
+ replicated: true
81
+ entire_replicated: true
82
+ shards:
83
+ slave1:
84
+ adapter: mysql
85
+ host: localhost
86
+ database: octopus_shard2
87
+ slave2:
88
+ adapter: mysql
89
+ host: localhost
90
+ database: octopus_shard3
91
+ slave3:
92
+ adapter: mysql
93
+ host: localhost
94
+ database: octopus_shard4
95
+ slave4:
96
+ adapter: mysql
97
+ host: localhost
98
+ database: octopus_shard5
99
+
100
+
@@ -6,7 +6,7 @@ describe "when the database is replicated" do
6
6
  clean_connection_proxy()
7
7
  end
8
8
 
9
- it "should send all writes/reads queries to master when you have a replicated model" do
9
+ it "should send all writes/reads queries to master when you have a non replicated model" do
10
10
  u = User.create!(:name => "Replicated")
11
11
  User.count.should == 1
12
12
  User.find(u.id).should == u
@@ -15,11 +15,11 @@ describe "when the database is replicated" do
15
15
  it "should send read queries to slaves, when you have a replicated model, using a round robin algorithm" do
16
16
  u = Cat.create!(:name => "master")
17
17
  c = Client.create!(:name => "client_master")
18
-
18
+
19
19
  [:slave4, :slave1, :slave2, :slave3].each do |sym|
20
20
  Cat.using(sym).create!(:name => "Replicated_#{sym}")
21
21
  end
22
-
22
+
23
23
  Client.find(:first).should_not be_nil
24
24
  Cat.find(:first).name.should == "Replicated_slave1"
25
25
  Client.find(:first).should_not be_nil
@@ -31,9 +31,49 @@ describe "when the database is replicated" do
31
31
  Client.find(:first).should_not be_nil
32
32
  Cat.find(:first).name.should == "Replicated_slave1"
33
33
  Client.find(:first).should_not be_nil
34
-
34
+
35
35
  [:slave4, :slave1, :slave2, :slave3].each do |sym|
36
36
  Cat.using(sym).find_by_name("master").should be_false
37
37
  end
38
38
  end
39
39
  end
40
+
41
+
42
+ describe "when the database is replicated and the entire application is replicated" do
43
+ before(:each) do
44
+ Octopus.stub!(:env).and_return("production_entire_replicated")
45
+ clean_connection_proxy()
46
+ end
47
+
48
+ it "should send read queries to slaves,to all models, using a round robin algorithm" do
49
+ u = Cat.create!(:name => "master")
50
+ c = Client.create!(:name => "client_master")
51
+
52
+ [:slave4, :slave1, :slave2, :slave3].each do |sym|
53
+ Cat.using(sym).create!(:name => "Replicated_#{sym}")
54
+ end
55
+
56
+ [:slave4, :slave1, :slave2, :slave3].each do |sym|
57
+ Client.using(sym).create!(:name => "Replicated_#{sym}")
58
+ end
59
+
60
+ Client.find(:first).name.should == "Replicated_slave1"
61
+ Cat.find(:first).name.should == "Replicated_slave2"
62
+ Client.find(:first).name.should == "Replicated_slave3"
63
+ Cat.find(:first).name.should == "Replicated_slave4"
64
+ Cat.find(:first).name.should == "Replicated_slave1"
65
+ Client.find(:first).name.should == "Replicated_slave2"
66
+ Cat.find(:first).name.should == "Replicated_slave3"
67
+ Client.find(:first).name.should == "Replicated_slave4"
68
+
69
+
70
+ [:slave4, :slave1, :slave2, :slave3].each do |sym|
71
+ Cat.using(sym).find_by_name("master").should be_false
72
+ end
73
+
74
+ [:slave4, :slave1, :slave2, :slave3].each do |sym|
75
+ Client.using(sym).find_by_name("master").should be_false
76
+ end
77
+ end
78
+ end
79
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-octopus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thiago Pradi
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-28 00:00:00 -03:00
20
+ date: 2010-06-29 00:00:00 -03:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -44,10 +44,12 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- hash: 3
47
+ hash: -1139874873
48
48
  segments:
49
+ - 3
49
50
  - 0
50
- version: "0"
51
+ - 0beta
52
+ version: 3.0.0beta
51
53
  type: :runtime
52
54
  version_requirements: *id002
53
55
  description: This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards.