seamless_database_pool 1.0.14 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49f36daf8b3d407d0a64c919cd55d41edb67299c
|
4
|
+
data.tar.gz: 27a40dda0546f89699c713a692119fc312da0da6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90c9a05dfb35afff08add517f6ddc3ab4f5ffeb2fe50d28a6102c9321c2d9fee384a6bbbccc08170a9290bf66950f3d8d72e50e952069a819293066367da6596
|
7
|
+
data.tar.gz: 37090f84c9134e7fe74657d0ff66623871b23aefbbae54d20fa6d17e59809773a9ffccfee5cc8e9d5d94c0fbbab3f5498eb30082e2525df911272228ea10736f
|
@@ -257,6 +257,10 @@ module ActiveRecord
|
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
|
+
def to_s
|
261
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{all_connections.size} connections>"
|
262
|
+
end
|
263
|
+
|
260
264
|
class DatabaseConnectionError < StandardError
|
261
265
|
end
|
262
266
|
|
@@ -371,6 +375,7 @@ module ActiveRecord
|
|
371
375
|
raise e if conn == master_connection
|
372
376
|
end
|
373
377
|
end
|
378
|
+
nil
|
374
379
|
end
|
375
380
|
end
|
376
381
|
end
|
@@ -13,7 +13,11 @@ describe "Test connection adapters" do
|
|
13
13
|
let(:master_connection){ connection.master_connection }
|
14
14
|
|
15
15
|
before(:all) do
|
16
|
-
ActiveRecord::
|
16
|
+
if ActiveRecord::VERSION::MAJOR < 3 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0)
|
17
|
+
ActiveRecord::Base.configurations = {'adapter' => "sqlite3", 'database' => ":memory:"}
|
18
|
+
else
|
19
|
+
ActiveRecord::Base.configurations = {"test" => {'adapter' => "sqlite3", 'database' => ":memory:"}}
|
20
|
+
end
|
17
21
|
ActiveRecord::Base.establish_connection('adapter' => "sqlite3", 'database' => ":memory:")
|
18
22
|
ActiveRecord::Base.connection
|
19
23
|
SeamlessDatabasePool::TestModel.db_model(adapter).create_tables
|
@@ -51,7 +51,7 @@ describe "SeamlessDatabasePoolAdapter ActiveRecord::Base extension" do
|
|
51
51
|
]
|
52
52
|
}
|
53
53
|
|
54
|
-
pool_connection =
|
54
|
+
pool_connection = double(:connection)
|
55
55
|
master_connection = SeamlessDatabasePool::MockConnection.new("master")
|
56
56
|
read_connection_1 = SeamlessDatabasePool::MockConnection.new("read_1")
|
57
57
|
read_connection_2 = SeamlessDatabasePool::MockConnection.new("read_2")
|
@@ -62,7 +62,7 @@ describe "SeamlessDatabasePoolAdapter ActiveRecord::Base extension" do
|
|
62
62
|
ActiveRecord::Base.should_receive(:reader_connection).with('adapter' => 'reader', 'host' => 'read_host_1', 'username' => 'user', 'pool_weight' => 1).and_return(read_connection_1)
|
63
63
|
ActiveRecord::Base.should_receive(:reader_connection).with('adapter' => 'reader', 'host' => 'read_host_2', 'username' => 'user', 'pool_weight' => 2).and_return(read_connection_2)
|
64
64
|
|
65
|
-
klass =
|
65
|
+
klass = double(:class)
|
66
66
|
ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter.should_receive(:adapter_class).with(master_connection).and_return(klass)
|
67
67
|
klass.should_receive(:new).with(nil, logger, master_connection, [read_connection_1, read_connection_2], weights).and_return(pool_connection)
|
68
68
|
|
@@ -88,6 +88,10 @@ describe "SeamlessDatabasePoolAdapter" do
|
|
88
88
|
connection_class.new(nil, nil, master_connection, [read_connection_1, read_connection_2], weights)
|
89
89
|
end
|
90
90
|
|
91
|
+
it "should be able to be converted to a string" do
|
92
|
+
pool_connection.to_s.should =~ /\A#<ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter::Abstract:0x[0-9a-f]+ 3 connections>\z/
|
93
|
+
end
|
94
|
+
|
91
95
|
context "selecting a connection from the pool" do
|
92
96
|
it "should initialize the connection pool" do
|
93
97
|
pool_connection.master_connection.should == master_connection
|
@@ -104,7 +108,8 @@ describe "SeamlessDatabasePoolAdapter" do
|
|
104
108
|
end
|
105
109
|
|
106
110
|
it "should select a random read connection" do
|
107
|
-
mock_connection =
|
111
|
+
mock_connection = double(:connection)
|
112
|
+
mock_connection.stub(:active? => true)
|
108
113
|
pool_connection.should_receive(:available_read_connections).and_return([:fake1, :fake2, mock_connection])
|
109
114
|
pool_connection.should_receive(:rand).with(3).and_return(2)
|
110
115
|
pool_connection.random_read_connection.should == mock_connection
|
@@ -117,7 +122,7 @@ describe "SeamlessDatabasePoolAdapter" do
|
|
117
122
|
|
118
123
|
it "should use the master connection in a block" do
|
119
124
|
connection_class = ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter.adapter_class(master_connection)
|
120
|
-
connection = connection_class.new(nil,
|
125
|
+
connection = connection_class.new(nil, double(:logger), master_connection, [read_connection_1], {read_connection_1 => 1})
|
121
126
|
connection.random_read_connection.should == read_connection_1
|
122
127
|
connection.use_master_connection do
|
123
128
|
connection.random_read_connection.should == master_connection
|
@@ -127,7 +132,7 @@ describe "SeamlessDatabasePoolAdapter" do
|
|
127
132
|
|
128
133
|
it "should use the master connection inside a transaction" do
|
129
134
|
connection_class = ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter.adapter_class(master_connection)
|
130
|
-
connection = connection_class.new(nil,
|
135
|
+
connection = connection_class.new(nil, double(:logger), master_connection, [read_connection_1], {read_connection_1 => 1})
|
131
136
|
master_connection.should_receive(:begin_db_transaction)
|
132
137
|
master_connection.should_receive(:commit_db_transaction)
|
133
138
|
master_connection.should_receive(:select).with('Transaction SQL', nil)
|
@@ -236,12 +241,12 @@ describe "SeamlessDatabasePoolAdapter" do
|
|
236
241
|
end
|
237
242
|
|
238
243
|
it "should try to reconnect dead connections when they become available again" do
|
239
|
-
master_connection.stub
|
244
|
+
master_connection.stub(:select).and_raise("SQL ERROR")
|
240
245
|
master_connection.should_receive(:active?).and_return(false, false, true)
|
241
246
|
master_connection.should_receive(:reconnect!)
|
242
247
|
now = Time.now
|
243
248
|
lambda{pool_connection.select_value("SQL")}.should raise_error("SQL ERROR")
|
244
|
-
Time.stub
|
249
|
+
Time.stub(:now => now + 31)
|
245
250
|
lambda{pool_connection.select_value("SQL")}.should raise_error("SQL ERROR")
|
246
251
|
end
|
247
252
|
|
@@ -11,16 +11,15 @@ describe "SeamlessDatabasePool" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should use the master connection by default" do
|
14
|
-
connection =
|
15
|
-
connection.stub!(:using_master_connection?).and_return(false)
|
14
|
+
connection = double(:connection, :master_connection => :master_db_connection, :using_master_connection? => false)
|
16
15
|
SeamlessDatabasePool.read_only_connection_type.should == :master
|
17
16
|
SeamlessDatabasePool.read_only_connection(connection).should == :master_db_connection
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should be able to set using persistent read connections" do
|
21
|
-
connection =
|
20
|
+
connection = double(:connection)
|
22
21
|
connection.should_receive(:random_read_connection).once.and_return(:read_db_connection)
|
23
|
-
connection.stub
|
22
|
+
connection.stub(:using_master_connection? => false)
|
24
23
|
SeamlessDatabasePool.use_persistent_read_connection
|
25
24
|
SeamlessDatabasePool.read_only_connection_type.should == :persistent
|
26
25
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection
|
@@ -28,9 +27,9 @@ describe "SeamlessDatabasePool" do
|
|
28
27
|
end
|
29
28
|
|
30
29
|
it "should be able to set using random read connections" do
|
31
|
-
connection =
|
30
|
+
connection = double(:connection)
|
32
31
|
connection.should_receive(:random_read_connection).and_return(:read_db_connection_1, :read_db_connection_2)
|
33
|
-
connection.stub
|
32
|
+
connection.stub(:using_master_connection? => false)
|
34
33
|
SeamlessDatabasePool.use_random_read_connection
|
35
34
|
SeamlessDatabasePool.read_only_connection_type.should == :random
|
36
35
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection_1
|
@@ -38,23 +37,23 @@ describe "SeamlessDatabasePool" do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should use the master connection if the connection is forcing it" do
|
41
|
-
connection =
|
40
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
42
41
|
connection.should_receive(:using_master_connection?).and_return(true)
|
43
42
|
SeamlessDatabasePool.use_persistent_read_connection
|
44
43
|
SeamlessDatabasePool.read_only_connection(connection).should == :master_db_connection
|
45
44
|
end
|
46
45
|
|
47
46
|
it "should be able to set using the master connection" do
|
48
|
-
connection =
|
49
|
-
connection.stub
|
47
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
48
|
+
connection.stub(:using_master_connection? => false)
|
50
49
|
SeamlessDatabasePool.use_master_connection
|
51
50
|
SeamlessDatabasePool.read_only_connection(connection).should == :master_db_connection
|
52
51
|
end
|
53
52
|
|
54
53
|
it "should be able to use persistent read connections within a block" do
|
55
|
-
connection =
|
54
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
56
55
|
connection.should_receive(:random_read_connection).once.and_return(:read_db_connection)
|
57
|
-
connection.stub
|
56
|
+
connection.stub(:using_master_connection? => false)
|
58
57
|
SeamlessDatabasePool.read_only_connection(connection).should == :master_db_connection
|
59
58
|
SeamlessDatabasePool.use_persistent_read_connection do
|
60
59
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection
|
@@ -65,9 +64,9 @@ describe "SeamlessDatabasePool" do
|
|
65
64
|
end
|
66
65
|
|
67
66
|
it "should be able to use random read connections within a block" do
|
68
|
-
connection =
|
67
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
69
68
|
connection.should_receive(:random_read_connection).and_return(:read_db_connection_1, :read_db_connection_2)
|
70
|
-
connection.stub
|
69
|
+
connection.stub(:using_master_connection? => false)
|
71
70
|
SeamlessDatabasePool.read_only_connection(connection).should == :master_db_connection
|
72
71
|
SeamlessDatabasePool.use_random_read_connection do
|
73
72
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection_1
|
@@ -78,9 +77,9 @@ describe "SeamlessDatabasePool" do
|
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should be able to use the master connection within a block" do
|
81
|
-
connection =
|
80
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
82
81
|
connection.should_receive(:random_read_connection).once.and_return(:read_db_connection)
|
83
|
-
connection.stub
|
82
|
+
connection.stub(:using_master_connection? => false)
|
84
83
|
SeamlessDatabasePool.use_persistent_read_connection
|
85
84
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection
|
86
85
|
SeamlessDatabasePool.use_master_connection do
|
@@ -92,9 +91,9 @@ describe "SeamlessDatabasePool" do
|
|
92
91
|
end
|
93
92
|
|
94
93
|
it "should be able to use connection blocks within connection blocks" do
|
95
|
-
connection =
|
96
|
-
connection.
|
97
|
-
connection.stub
|
94
|
+
connection = double(:connection, :master_connection => :master_db_connection)
|
95
|
+
connection.stub(:random_read_connection => :read_db_connection)
|
96
|
+
connection.stub(:using_master_connection? => false)
|
98
97
|
SeamlessDatabasePool.use_persistent_read_connection do
|
99
98
|
SeamlessDatabasePool.read_only_connection(connection).should == :read_db_connection
|
100
99
|
SeamlessDatabasePool.use_master_connection do
|
@@ -109,9 +108,8 @@ describe "SeamlessDatabasePool" do
|
|
109
108
|
end
|
110
109
|
|
111
110
|
it "should be able to change the persistent connection" do
|
112
|
-
connection =
|
113
|
-
connection.stub
|
114
|
-
connection.stub!(:using_master_connection?).and_return(false)
|
111
|
+
connection = double(:connection)
|
112
|
+
connection.stub(:random_read_connection => :read_db_connection, :using_master_connection? => false)
|
115
113
|
|
116
114
|
SeamlessDatabasePool.use_persistent_read_connection
|
117
115
|
SeamlessDatabasePool.read_only_connection_type.should == :persistent
|
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seamless_database_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.15
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Durand
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.20
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 3.0.20
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '2.0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '2.0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: jeweler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: sqlite3
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: mysql
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: pg
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description:
|
@@ -135,27 +122,26 @@ files:
|
|
135
122
|
- spec/test_model.rb
|
136
123
|
homepage: http://github.com/bdurand/seamless_database_pool
|
137
124
|
licenses: []
|
125
|
+
metadata: {}
|
138
126
|
post_install_message:
|
139
127
|
rdoc_options: []
|
140
128
|
require_paths:
|
141
129
|
- lib
|
142
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
131
|
requirements:
|
145
|
-
- -
|
132
|
+
- - ">="
|
146
133
|
- !ruby/object:Gem::Version
|
147
134
|
version: '0'
|
148
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
136
|
requirements:
|
151
|
-
- -
|
137
|
+
- - ">="
|
152
138
|
- !ruby/object:Gem::Version
|
153
139
|
version: '0'
|
154
140
|
requirements: []
|
155
141
|
rubyforge_project:
|
156
|
-
rubygems_version:
|
142
|
+
rubygems_version: 2.2.2
|
157
143
|
signing_key:
|
158
|
-
specification_version:
|
144
|
+
specification_version: 4
|
159
145
|
summary: Add support for master/slave database clusters in ActiveRecord to improve
|
160
146
|
performance.
|
161
147
|
test_files: []
|