seamless_database_pool 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,10 +22,11 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = "seamless_database_pool"
25
- s.version = "1.0.3"
25
+ s.version = "1.0.4"
26
26
  s.author = "Brian Durand"
27
27
  s.platform = Gem::Platform::RUBY
28
28
  s.summary = "Support for master/slave database clusters in ActiveRecord"
29
+ s.description = "Add support for master/slave database clusters in ActiveRecord to improve performance."
29
30
  s.files = FileList["lib/**/*", "init.rb", "MIT-LICENSE", 'Rakefile'].to_a
30
31
  s.require_path = "lib"
31
32
  s.test_files = FileList["{spec}/**/*_spec.rb"].to_a
@@ -199,6 +199,14 @@ module ActiveRecord
199
199
  master_connection.delete(sql, name)
200
200
  end
201
201
 
202
+ def execute (*args)
203
+ proxy_connection_method(current_read_connection, :execute, :read, *args)
204
+ end
205
+
206
+ def select_rows(*args)
207
+ proxy_connection_method(current_read_connection, :select_rows, :read, *args)
208
+ end
209
+
202
210
  def using_master_connection?
203
211
  !!@use_master
204
212
  end
@@ -279,10 +287,10 @@ module ActiveRecord
279
287
 
280
288
  protected
281
289
 
282
- def select (sql, name = nil)
290
+ def select (*args)
283
291
  connection = current_read_connection
284
292
  begin
285
- proxy_connection_method(connection, :select, :read, *[sql, name])
293
+ proxy_connection_method(connection, :select, :read, *args)
286
294
  rescue DatabaseConnectionError => e
287
295
  unless using_master_connection?
288
296
  # Try again with a different connection if needed unless it could have a side effect
@@ -291,7 +299,7 @@ module ActiveRecord
291
299
  connection = current_read_connection
292
300
  SeamlessDatabasePool.set_persistent_read_connection(self, connection)
293
301
  end
294
- proxy_connection_method(connection, :select, :retry, *[sql, name])
302
+ proxy_connection_method(connection, :select, :retry, *args)
295
303
  else
296
304
  raise e.wrapped_exception
297
305
  end
@@ -135,10 +135,22 @@ describe "SeamlessDatabasePoolAdapter" do
135
135
 
136
136
  it "should proxy select methods to a read connection" do
137
137
  @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
138
- @read_connection_1.should_receive(:select).with('SQL', nil).and_return(:retval)
138
+ @read_connection_1.should_receive(:select).with('SQL').and_return(:retval)
139
139
  @pool_connection.send(:select, 'SQL').should == :retval
140
140
  end
141
141
 
142
+ it "should proxy execute methods to a read connection" do
143
+ @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
144
+ @read_connection_1.should_receive(:execute).with('SQL').and_return(:retval)
145
+ @pool_connection.execute('SQL').should == :retval
146
+ end
147
+
148
+ it "should proxy select_rows methods to a read connection" do
149
+ @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
150
+ @read_connection_1.should_receive(:select_rows).with('SQL').and_return(:retval)
151
+ @pool_connection.select_rows('SQL').should == :retval
152
+ end
153
+
142
154
  # Master connection methods
143
155
 
144
156
  it "should proxy insert method to the master connection" do
@@ -247,11 +259,11 @@ describe "SeamlessDatabasePoolAdapter" do
247
259
  connection_error = ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter::DatabaseConnectionError.new
248
260
  connection_error.wrapped_exception = StandardError.new("Error")
249
261
  @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
250
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL', nil).and_raise(connection_error)
262
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL').and_raise(connection_error)
251
263
  @read_connection_1.should_receive(:active?).and_return(true)
252
264
  @pool_connection.should_not_receive(:suppress_read_connection)
253
265
  SeamlessDatabasePool.should_not_receive(:set_persistent_read_connection)
254
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :retry, 'SQL', nil).and_return(:results)
266
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :retry, 'SQL').and_return(:results)
255
267
  @pool_connection.send(:select, 'SQL').should == :results
256
268
  end
257
269
 
@@ -259,7 +271,7 @@ describe "SeamlessDatabasePoolAdapter" do
259
271
  connection_error = ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter::DatabaseConnectionError.new
260
272
  connection_error.wrapped_exception = StandardError.new("Error")
261
273
  @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
262
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL', nil).and_raise(connection_error)
274
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL').and_raise(connection_error)
263
275
  @pool_connection.use_master_connection do
264
276
  lambda{@pool_connection.send(:select, 'SQL')}.should raise_error("Error")
265
277
  end
@@ -267,7 +279,7 @@ describe "SeamlessDatabasePoolAdapter" do
267
279
 
268
280
  it "should not try to execute a read statement again after a non-connection error" do
269
281
  @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1)
270
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL', nil).and_raise("SQL Error")
282
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL').and_raise("SQL Error")
271
283
  lambda{@pool_connection.send(:select, 'SQL')}.should raise_error("SQL Error")
272
284
  end
273
285
 
@@ -275,11 +287,11 @@ describe "SeamlessDatabasePoolAdapter" do
275
287
  connection_error = ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter::DatabaseConnectionError.new
276
288
  connection_error.wrapped_exception = StandardError.new("Error")
277
289
  @pool_connection.should_receive(:current_read_connection).and_return(@read_connection_1, @read_connection_2)
278
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL', nil).and_raise(connection_error)
290
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_1, :select, :read, 'SQL').and_raise(connection_error)
279
291
  @read_connection_1.should_receive(:active?).and_return(false)
280
292
  @pool_connection.should_receive(:suppress_read_connection).with(@read_connection_1, 30)
281
293
  SeamlessDatabasePool.should_receive(:set_persistent_read_connection).with(@pool_connection, @read_connection_2)
282
- @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_2, :select, :retry, 'SQL', nil).and_return(:results)
294
+ @pool_connection.should_receive(:proxy_connection_method).with(@read_connection_2, :select, :retry, 'SQL').and_return(:results)
283
295
  @pool_connection.send(:select, 'SQL').should == :results
284
296
  end
285
297
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamless_database_pool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-26 00:00:00 -05:00
12
+ date: 2009-10-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
16
+ description: Add support for master/slave database clusters in ActiveRecord to improve performance.
17
17
  email: brian@embellishedvisions.com
18
18
  executables: []
19
19
 
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - rspec 1.0.8 or higher is needed to run the tests
62
62
  rubyforge_project: seamlessdbpool
63
- rubygems_version: 1.3.3
63
+ rubygems_version: 1.3.5
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: Support for master/slave database clusters in ActiveRecord