ebisu_connection 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98f897fee0659bddbed6e4539387a46f2c43a72a
4
- data.tar.gz: 8dcd5b499e30cd9bd32681e08ffa00cd7d338bb5
3
+ metadata.gz: 329f392b0c96e684f68b181ee65c8f17941e0537
4
+ data.tar.gz: d0f4b510081d702887b1253d6b240783e176b4b3
5
5
  SHA512:
6
- metadata.gz: 502269d5808c9dc2bb0d13e494d01fc15b726b9923f6dc8a2c736b732a8d587b82e57ef389c4c0fd8d1c8dca8af114a87a114924e0a8c73518ad007d7a03c915
7
- data.tar.gz: 543a8f54458d6f5bba4f523a689ef59958d649fe7942474f547a5858454272d4981b529a8f593199ad31213e29a25e8fdea37f59190461712801a1a90b37f99f
6
+ metadata.gz: a026f2a2e172f868d1cdc7a4be0269ae87cdfa204daef131f5e3d7755c39409b12b2485cdefdf33eb0a190799252fa0bae56f39eebcecd833dbc020e797d5d18
7
+ data.tar.gz: cd289b7235f65d828fd22e9867f916cb2aaa4a346d13694da9d0ff22ad17b2309ec4adf8890bdfa64f038ae50d66974e7308542de0c98dfd11eab8db9691e37a
data/README.md CHANGED
@@ -148,6 +148,22 @@ In transaction, Always will be access to master server.
148
148
  end
149
149
 
150
150
 
151
+ ### for Unicorn
152
+
153
+ ```ruby
154
+ before_fork do |server, worker|
155
+ ...
156
+ ActiveRecord::Base.clear_all_slave_connections!
157
+ ...
158
+ end
159
+
160
+ after_fork do |server, worker|
161
+ ...
162
+ ActiveRecord::Base.establish_fresh_connection
163
+ ...
164
+ end
165
+ ```
166
+
151
167
  ## Contributing
152
168
 
153
169
  1. Fork it
@@ -8,20 +8,22 @@ Gem::Specification.new do |spec|
8
8
  spec.version = EbisuConnection::VERSION
9
9
  spec.authors = ["tsukasaoishi"]
10
10
  spec.email = ["tsukasa.oishi@gmail.com"]
11
- spec.description = %q{EbisuConnection supports to connect with Mysql slave servers. It doesn't need Load Balancer.}
11
+
12
12
  spec.summary = %q{EbisuConnection supports to connect with Mysql slave servers.}
13
- spec.homepage = ""
13
+ spec.description = %q{EbisuConnection supports to connect with Mysql slave servers. It doesn't need Load Balancer.}
14
+ spec.homepage = "https://github.com/tsukasaoishi/ebisu_connection"
14
15
  spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
20
  spec.require_paths = ["lib"]
20
21
 
22
+ spec.required_ruby_version = '>= 2.0'
21
23
  spec.add_dependency 'fresh_connection', '~> 0.4.0'
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.7"
24
26
  spec.add_development_dependency "rake", '~> 10.0'
25
27
  spec.add_development_dependency "rspec", '~> 3.0'
26
- spec.add_development_dependency 'appraisal', '~> 1.0'
28
+ spec.add_development_dependency 'appraisal', '~> 2.0'
27
29
  end
@@ -1,6 +1,7 @@
1
1
  require 'fresh_connection/abstract_connection_manager'
2
2
  require 'ebisu_connection/conf_file'
3
3
  require 'ebisu_connection/slave_group'
4
+ require 'active_support/deprecation'
4
5
 
5
6
  module EbisuConnection
6
7
  class ConnectionManager < FreshConnection::AbstractConnectionManager
@@ -31,7 +32,7 @@ module EbisuConnection
31
32
  end
32
33
  end
33
34
 
34
- def clear_all_connection!
35
+ def clear_all_connections!
35
36
  synchronize do
36
37
  @slaves.values.each do |s|
37
38
  s.all_disconnect!
@@ -42,6 +43,11 @@ module EbisuConnection
42
43
  end
43
44
  end
44
45
 
46
+ def clear_all_connection!
47
+ ActiveSupport::Deprecation.warn("clear_all_connection! has been deprecated. Use clear_all_connections! instead", caller)
48
+ clear_all_connections!
49
+ end
50
+
45
51
  private
46
52
 
47
53
  def check_own_connection
@@ -1,3 +1,3 @@
1
1
  module EbisuConnection
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebisu_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tsukasaoishi
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fresh_connection
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.0'
75
+ version: '2.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.0'
82
+ version: '2.0'
83
83
  description: EbisuConnection supports to connect with Mysql slave servers. It doesn't
84
84
  need Load Balancer.
85
85
  email:
@@ -107,16 +107,7 @@ files:
107
107
  - lib/ebisu_connection/slave.rb
108
108
  - lib/ebisu_connection/slave_group.rb
109
109
  - lib/ebisu_connection/version.rb
110
- - spec/database.yml
111
- - spec/db_schema.sql
112
- - spec/prepare.rb
113
- - spec/slaves.yaml
114
- - spec/spec_helper.rb
115
- - spec/unit/ebisu_connection_spec.rb
116
- - spec/unit/greatest_common_divisor_spec.rb
117
- - spec/unit/slave_group_spec.rb
118
- - spec/unit/slave_spec.rb
119
- homepage: ''
110
+ homepage: https://github.com/tsukasaoishi/ebisu_connection
120
111
  licenses:
121
112
  - MIT
122
113
  metadata: {}
@@ -128,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
119
  requirements:
129
120
  - - ">="
130
121
  - !ruby/object:Gem::Version
131
- version: '0'
122
+ version: '2.0'
132
123
  required_rubygems_version: !ruby/object:Gem::Requirement
133
124
  requirements:
134
125
  - - ">="
@@ -140,13 +131,4 @@ rubygems_version: 2.4.5
140
131
  signing_key:
141
132
  specification_version: 4
142
133
  summary: EbisuConnection supports to connect with Mysql slave servers.
143
- test_files:
144
- - spec/database.yml
145
- - spec/db_schema.sql
146
- - spec/prepare.rb
147
- - spec/slaves.yaml
148
- - spec/spec_helper.rb
149
- - spec/unit/ebisu_connection_spec.rb
150
- - spec/unit/greatest_common_divisor_spec.rb
151
- - spec/unit/slave_group_spec.rb
152
- - spec/unit/slave_spec.rb
134
+ test_files: []
data/spec/database.yml DELETED
@@ -1,10 +0,0 @@
1
- test:
2
- adapter: mysql2
3
- encoding: utf8
4
- database: ebisu_connection_test_master
5
- pool: 5
6
- username: root
7
- password:
8
-
9
- slave:
10
- database: ebisu_connection_test_slave
data/spec/db_schema.sql DELETED
@@ -1,95 +0,0 @@
1
- -- MySQL dump 10.13 Distrib 5.6.19, for osx10.9 (x86_64)
2
- --
3
- -- Host: localhost Database: ebisu_connection_test_master
4
- -- ------------------------------------------------------
5
- -- Server version 5.6.19
6
-
7
- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8
- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9
- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10
- /*!40101 SET NAMES utf8 */;
11
- /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12
- /*!40103 SET TIME_ZONE='+00:00' */;
13
- /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14
- /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15
- /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16
- /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17
-
18
- --
19
- -- Current Database: `ebisu_connection_test_master`
20
- --
21
-
22
- CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ebisu_connection_test_master` /*!40100 DEFAULT CHARACTER SET utf8 */;
23
-
24
- USE `ebisu_connection_test_master`;
25
-
26
- --
27
- -- Table structure for table `users`
28
- --
29
-
30
- DROP TABLE IF EXISTS `users`;
31
- /*!40101 SET @saved_cs_client = @@character_set_client */;
32
- /*!40101 SET character_set_client = utf8 */;
33
- CREATE TABLE `users` (
34
- `id` int(11) NOT NULL AUTO_INCREMENT,
35
- `name` varchar(255) NOT NULL DEFAULT '',
36
- `created_at` datetime DEFAULT NULL,
37
- `updated_at` datetime DEFAULT NULL,
38
- PRIMARY KEY (`id`)
39
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
40
- /*!40101 SET character_set_client = @saved_cs_client */;
41
-
42
- --
43
- -- Dumping data for table `users`
44
- --
45
-
46
- LOCK TABLES `users` WRITE;
47
- /*!40000 ALTER TABLE `users` DISABLE KEYS */;
48
- INSERT INTO `users` VALUES (1,'Tsukasa (master)','2014-04-10 07:24:16','2014-04-10 07:24:16');
49
- /*!40000 ALTER TABLE `users` ENABLE KEYS */;
50
- UNLOCK TABLES;
51
-
52
- --
53
- -- Current Database: `ebisu_connection_test_slave`
54
- --
55
-
56
- CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ebisu_connection_test_slave` /*!40100 DEFAULT CHARACTER SET utf8 */;
57
-
58
- USE `ebisu_connection_test_slave`;
59
-
60
- --
61
- -- Table structure for table `users`
62
- --
63
-
64
- DROP TABLE IF EXISTS `users`;
65
- /*!40101 SET @saved_cs_client = @@character_set_client */;
66
- /*!40101 SET character_set_client = utf8 */;
67
- CREATE TABLE `users` (
68
- `id` int(11) NOT NULL AUTO_INCREMENT,
69
- `name` varchar(255) NOT NULL DEFAULT '',
70
- `created_at` datetime DEFAULT NULL,
71
- `updated_at` datetime DEFAULT NULL,
72
- PRIMARY KEY (`id`)
73
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
74
- /*!40101 SET character_set_client = @saved_cs_client */;
75
-
76
- --
77
- -- Dumping data for table `users`
78
- --
79
-
80
- LOCK TABLES `users` WRITE;
81
- /*!40000 ALTER TABLE `users` DISABLE KEYS */;
82
- INSERT INTO `users` VALUES (1,'Tsukasa (slave)','2014-04-10 07:24:16','2014-04-10 07:24:16');
83
- /*!40000 ALTER TABLE `users` ENABLE KEYS */;
84
- UNLOCK TABLES;
85
- /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
86
-
87
- /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
88
- /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
89
- /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
90
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
91
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
92
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
93
- /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
94
-
95
- -- Dump completed on 2014-06-16 21:22:37
data/spec/prepare.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'yaml'
2
- require 'active_record'
3
-
4
- system("mysql -uroot < spec/db_schema.sql")
5
-
6
- module ActiveRecord
7
- class Base
8
- self.configurations = YAML.load_file(File.join(File.dirname(__FILE__), "database.yml"))
9
- establish_connection(configurations["test"])
10
- end
11
- end
12
-
13
- class User < ActiveRecord::Base
14
- end
data/spec/slaves.yaml DELETED
@@ -1,7 +0,0 @@
1
- test:
2
- slave:
3
- - "localhost, 10"
4
- - "localhost, 10"
5
- -
6
- host: localhost
7
- wheight: 10
data/spec/spec_helper.rb DELETED
@@ -1,7 +0,0 @@
1
- ENV["RAILS_ENV"]="test"
2
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require 'ebisu_connection'
4
-
5
- EbisuConnection.env = "test"
6
- EbisuConnection.slaves_file = File.join(File.dirname(__FILE__), "slaves.yaml")
7
- require File.join(File.dirname(__FILE__), "prepare.rb")
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EbisuConnection do
4
- context "access to slave" do
5
- it "select from User is to access to slave" do
6
- expect(User.first.name).to be_include("slave")
7
- end
8
- end
9
-
10
- context "access to master" do
11
- it "specify read_master" do
12
- expect(User.read_master.first.name).to be_include("master")
13
- end
14
-
15
- it "specify readonly(false)" do
16
- expect(User.readonly(false).first.name).to be_include("master")
17
- end
18
- end
19
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EbisuConnection::GreatestCommonDivisor do
4
- before(:all) do
5
- @g = EbisuConnection::GreatestCommonDivisor
6
- end
7
-
8
- context ".calc" do
9
- it "return nil if set is empty" do
10
- expect(@g.calc([])).to be_nil
11
- end
12
-
13
- it "return first element if set has one element" do
14
- expect(@g.calc([1])).to eq(1)
15
- end
16
-
17
- it "return first element if set has elements that is all same" do
18
- set = [1] * 100
19
- expect(@g.calc(set)).to eq(1)
20
- end
21
-
22
- it "return 1 if set includes 1 in elements" do
23
- set = (1..100).to_a
24
- expect(@g.calc(set)).to eq(1)
25
- end
26
-
27
- it "return gcd" do
28
- expect(@g.calc([2,4])).to eq(2)
29
- expect(@g.calc([2,4,6])).to eq(2)
30
- expect(@g.calc([4,6])).to eq(2)
31
- expect(@g.calc([3,4,6])).to eq(1)
32
- expect(@g.calc([3,6])).to eq(3)
33
- expect(@g.calc([10,10,2])).to eq(2)
34
- expect(@g.calc([10,10,2,10,5])).to eq(1)
35
- expect(@g.calc([10,10,10,5])).to eq(5)
36
- end
37
- end
38
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EbisuConnection::SlaveGroup do
4
- before(:all) do
5
- @sg = EbisuConnection::SlaveGroup
6
- end
7
-
8
- context "#sample" do
9
- it "raise exception if slaves empty" do
10
- inst = @sg.new([], "slave")
11
- expect{
12
- inst.sample
13
- }.to raise_error(EbisuConnection::SlaveGroup::AllSlavesHasGoneError)
14
- end
15
-
16
- it "return slve instance object" do
17
- inst = @sg.new(["h"], "slave")
18
- expect(inst.sample).to be_a(EbisuConnection::Slave)
19
- end
20
- end
21
-
22
- context "#remove_connection" do
23
- it "raise exception AllSlavesHasGoneError when slaves size is one" do
24
- inst = @sg.new(["localhost"], "slave")
25
- c = inst.sample.connection
26
- expect {
27
- inst.remove_connection(c)
28
- }.to raise_error(EbisuConnection::SlaveGroup::AllSlavesHasGoneError)
29
- end
30
- end
31
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EbisuConnection::Slave do
4
- context "initialize(conf is String)" do
5
- it "hostname only" do
6
- s = EbisuConnection::Slave.new("host_1", "slave")
7
- expect(s.hostname).to eq("host_1")
8
- expect(s.weight).to eq(1)
9
- end
10
-
11
- it "hostname and weight" do
12
- s = EbisuConnection::Slave.new("host_1, 10", "slave")
13
- expect(s.hostname).to eq("host_1")
14
- expect(s.weight).to eq(10)
15
- end
16
-
17
- it "hostname, weight and port" do
18
- s = EbisuConnection::Slave.new("host_1:1975, 10", "slave")
19
- expect(s.hostname).to eq("host_1")
20
- expect(s.weight).to eq(10)
21
- end
22
- end
23
-
24
- context "initialize(conf is Hash)" do
25
- it "hostname only" do
26
- s = EbisuConnection::Slave.new({:host => "host_1"}, "slave")
27
- expect(s.hostname).to eq("host_1")
28
- expect(s.weight).to eq(1)
29
- end
30
-
31
- it "hostname and weight" do
32
- s = EbisuConnection::Slave.new({:host => "host_1", :weight => 10}, "slave")
33
- expect(s.hostname).to eq("host_1")
34
- expect(s.weight).to eq(10)
35
- end
36
-
37
- it "hostname, weight and port" do
38
- s = EbisuConnection::Slave.new({:host => "host_1", :weight => 10, :port => 1975}, "slave")
39
- expect(s.hostname).to eq("host_1")
40
- expect(s.weight).to eq(10)
41
- end
42
- end
43
-
44
- context "#connection" do
45
- it "return Mysql2Adapter object" do
46
- s = EbisuConnection::Slave.new("localhost", "slave")
47
- expect(s.connection).to be_a(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
48
- end
49
- end
50
- end