ar_mysql_flexmaster 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem "rake"
6
+ gem "rails", "~> 4.0.0"
7
+ gem "mysql2", "~> 0.3.0", "<= 0.3.11"
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ ar_mysql_flexmaster (0.4.4)
5
+ activerecord
6
+ activesupport
7
+ mysql2
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.0.12)
13
+ actionpack (= 4.0.12)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ actionpack (4.0.12)
16
+ activesupport (= 4.0.12)
17
+ builder (~> 3.1.0)
18
+ erubis (~> 2.7.0)
19
+ rack (~> 1.5.2)
20
+ rack-test (~> 0.6.2)
21
+ activemodel (4.0.12)
22
+ activesupport (= 4.0.12)
23
+ builder (~> 3.1.0)
24
+ activerecord (4.0.12)
25
+ activemodel (= 4.0.12)
26
+ activerecord-deprecated_finders (~> 1.0.2)
27
+ activesupport (= 4.0.12)
28
+ arel (~> 4.0.0)
29
+ activerecord-deprecated_finders (1.0.3)
30
+ activesupport (4.0.12)
31
+ i18n (~> 0.6, >= 0.6.9)
32
+ minitest (~> 4.2)
33
+ multi_json (~> 1.3)
34
+ thread_safe (~> 0.1)
35
+ tzinfo (~> 0.3.37)
36
+ arel (4.0.2)
37
+ builder (3.1.4)
38
+ bump (0.5.1)
39
+ erubis (2.7.0)
40
+ hike (1.2.3)
41
+ i18n (0.6.11)
42
+ mail (2.6.3)
43
+ mime-types (>= 1.16, < 3)
44
+ mime-types (2.4.3)
45
+ minitest (4.7.5)
46
+ multi_json (1.10.1)
47
+ mysql2 (0.3.11)
48
+ mysql_isolated_server (0.5.3)
49
+ rack (1.5.2)
50
+ rack-test (0.6.2)
51
+ rack (>= 1.0)
52
+ rails (4.0.12)
53
+ actionmailer (= 4.0.12)
54
+ actionpack (= 4.0.12)
55
+ activerecord (= 4.0.12)
56
+ activesupport (= 4.0.12)
57
+ bundler (>= 1.3.0, < 2.0)
58
+ railties (= 4.0.12)
59
+ sprockets-rails (~> 2.0)
60
+ railties (4.0.12)
61
+ actionpack (= 4.0.12)
62
+ activesupport (= 4.0.12)
63
+ rake (>= 0.8.7)
64
+ thor (>= 0.18.1, < 2.0)
65
+ rake (10.4.2)
66
+ sprockets (2.12.3)
67
+ hike (~> 1.2)
68
+ multi_json (~> 1.0)
69
+ rack (~> 1.0)
70
+ tilt (~> 1.1, != 1.3.0)
71
+ sprockets-rails (2.2.2)
72
+ actionpack (>= 3.0)
73
+ activesupport (>= 3.0)
74
+ sprockets (>= 2.8, < 4.0)
75
+ thor (0.19.1)
76
+ thread_safe (0.3.4)
77
+ tilt (1.4.1)
78
+ tzinfo (0.3.42)
79
+ wwtd (0.5.5)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ ar_mysql_flexmaster!
86
+ bump
87
+ minitest
88
+ mysql2 (~> 0.3.0, <= 0.3.11)
89
+ mysql_isolated_server (~> 0.5)
90
+ rails (~> 4.0.0)
91
+ rake
92
+ wwtd
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem "rake"
6
+ gem "rails", "~> 4.1.8"
7
+ gem "mysql2", "~> 0.3.0"
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ ar_mysql_flexmaster (0.4.4)
5
+ activerecord
6
+ activesupport
7
+ mysql2
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.1.8)
13
+ actionpack (= 4.1.8)
14
+ actionview (= 4.1.8)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ actionpack (4.1.8)
17
+ actionview (= 4.1.8)
18
+ activesupport (= 4.1.8)
19
+ rack (~> 1.5.2)
20
+ rack-test (~> 0.6.2)
21
+ actionview (4.1.8)
22
+ activesupport (= 4.1.8)
23
+ builder (~> 3.1)
24
+ erubis (~> 2.7.0)
25
+ activemodel (4.1.8)
26
+ activesupport (= 4.1.8)
27
+ builder (~> 3.1)
28
+ activerecord (4.1.8)
29
+ activemodel (= 4.1.8)
30
+ activesupport (= 4.1.8)
31
+ arel (~> 5.0.0)
32
+ activesupport (4.1.8)
33
+ i18n (~> 0.6, >= 0.6.9)
34
+ json (~> 1.7, >= 1.7.7)
35
+ minitest (~> 5.1)
36
+ thread_safe (~> 0.1)
37
+ tzinfo (~> 1.1)
38
+ arel (5.0.1.20140414130214)
39
+ builder (3.2.2)
40
+ bump (0.5.1)
41
+ erubis (2.7.0)
42
+ hike (1.2.3)
43
+ i18n (0.6.11)
44
+ json (1.8.1)
45
+ mail (2.6.3)
46
+ mime-types (>= 1.16, < 3)
47
+ mime-types (2.4.3)
48
+ minitest (5.4.3)
49
+ multi_json (1.10.1)
50
+ mysql2 (0.3.17)
51
+ mysql_isolated_server (0.5.3)
52
+ rack (1.5.2)
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rails (4.1.8)
56
+ actionmailer (= 4.1.8)
57
+ actionpack (= 4.1.8)
58
+ actionview (= 4.1.8)
59
+ activemodel (= 4.1.8)
60
+ activerecord (= 4.1.8)
61
+ activesupport (= 4.1.8)
62
+ bundler (>= 1.3.0, < 2.0)
63
+ railties (= 4.1.8)
64
+ sprockets-rails (~> 2.0)
65
+ railties (4.1.8)
66
+ actionpack (= 4.1.8)
67
+ activesupport (= 4.1.8)
68
+ rake (>= 0.8.7)
69
+ thor (>= 0.18.1, < 2.0)
70
+ rake (10.4.2)
71
+ sprockets (2.12.3)
72
+ hike (~> 1.2)
73
+ multi_json (~> 1.0)
74
+ rack (~> 1.0)
75
+ tilt (~> 1.1, != 1.3.0)
76
+ sprockets-rails (2.2.2)
77
+ actionpack (>= 3.0)
78
+ activesupport (>= 3.0)
79
+ sprockets (>= 2.8, < 4.0)
80
+ thor (0.19.1)
81
+ thread_safe (0.3.4)
82
+ tilt (1.4.1)
83
+ tzinfo (1.2.2)
84
+ thread_safe (~> 0.1)
85
+ wwtd (0.5.5)
86
+
87
+ PLATFORMS
88
+ ruby
89
+
90
+ DEPENDENCIES
91
+ ar_mysql_flexmaster!
92
+ bump
93
+ minitest
94
+ mysql2 (~> 0.3.0)
95
+ mysql_isolated_server (~> 0.5)
96
+ rails (~> 4.1.8)
97
+ rake
98
+ wwtd
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => "../"
4
+
5
+ gem "rake"
6
+ gem "rails", "~> 4.2.0.rc2"
7
+ gem "mysql2", "~> 0.3.0"
@@ -0,0 +1,123 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ ar_mysql_flexmaster (0.4.4)
5
+ activerecord
6
+ activesupport
7
+ mysql2
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.0.rc2)
13
+ actionpack (= 4.2.0.rc2)
14
+ actionview (= 4.2.0.rc2)
15
+ activejob (= 4.2.0.rc2)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.0.rc2)
19
+ actionview (= 4.2.0.rc2)
20
+ activesupport (= 4.2.0.rc2)
21
+ rack (~> 1.6.0.beta2)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
25
+ actionview (4.2.0.rc2)
26
+ activesupport (= 4.2.0.rc2)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
31
+ activejob (4.2.0.rc2)
32
+ activesupport (= 4.2.0.rc2)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.0.rc2)
35
+ activesupport (= 4.2.0.rc2)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.0.rc2)
38
+ activemodel (= 4.2.0.rc2)
39
+ activesupport (= 4.2.0.rc2)
40
+ arel (~> 6.0)
41
+ activesupport (4.2.0.rc2)
42
+ i18n (>= 0.7.0.beta1, < 0.8)
43
+ json (~> 1.7, >= 1.7.7)
44
+ minitest (~> 5.1)
45
+ thread_safe (~> 0.1)
46
+ tzinfo (~> 1.1)
47
+ arel (6.0.0)
48
+ builder (3.2.2)
49
+ bump (0.5.1)
50
+ erubis (2.7.0)
51
+ globalid (0.3.0)
52
+ activesupport (>= 4.1.0)
53
+ hike (1.2.3)
54
+ i18n (0.7.0.beta1)
55
+ json (1.8.1)
56
+ loofah (2.0.1)
57
+ nokogiri (>= 1.5.9)
58
+ mail (2.6.3)
59
+ mime-types (>= 1.16, < 3)
60
+ mime-types (2.4.3)
61
+ mini_portile (0.6.1)
62
+ minitest (5.4.3)
63
+ multi_json (1.10.1)
64
+ mysql2 (0.3.17)
65
+ mysql_isolated_server (0.5.3)
66
+ nokogiri (1.6.5)
67
+ mini_portile (~> 0.6.0)
68
+ rack (1.6.0.beta2)
69
+ rack-test (0.6.2)
70
+ rack (>= 1.0)
71
+ rails (4.2.0.rc2)
72
+ actionmailer (= 4.2.0.rc2)
73
+ actionpack (= 4.2.0.rc2)
74
+ actionview (= 4.2.0.rc2)
75
+ activejob (= 4.2.0.rc2)
76
+ activemodel (= 4.2.0.rc2)
77
+ activerecord (= 4.2.0.rc2)
78
+ activesupport (= 4.2.0.rc2)
79
+ bundler (>= 1.3.0, < 2.0)
80
+ railties (= 4.2.0.rc2)
81
+ sprockets-rails
82
+ rails-deprecated_sanitizer (1.0.3)
83
+ activesupport (>= 4.2.0.alpha)
84
+ rails-dom-testing (1.0.5)
85
+ activesupport (>= 4.2.0.beta, < 5.0)
86
+ nokogiri (~> 1.6.0)
87
+ rails-deprecated_sanitizer (>= 1.0.1)
88
+ rails-html-sanitizer (1.0.1)
89
+ loofah (~> 2.0)
90
+ railties (4.2.0.rc2)
91
+ actionpack (= 4.2.0.rc2)
92
+ activesupport (= 4.2.0.rc2)
93
+ rake (>= 0.8.7)
94
+ thor (>= 0.18.1, < 2.0)
95
+ rake (10.4.2)
96
+ sprockets (2.12.3)
97
+ hike (~> 1.2)
98
+ multi_json (~> 1.0)
99
+ rack (~> 1.0)
100
+ tilt (~> 1.1, != 1.3.0)
101
+ sprockets-rails (2.2.2)
102
+ actionpack (>= 3.0)
103
+ activesupport (>= 3.0)
104
+ sprockets (>= 2.8, < 4.0)
105
+ thor (0.19.1)
106
+ thread_safe (0.3.4)
107
+ tilt (1.4.1)
108
+ tzinfo (1.2.2)
109
+ thread_safe (~> 0.1)
110
+ wwtd (0.5.5)
111
+
112
+ PLATFORMS
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ ar_mysql_flexmaster!
117
+ bump
118
+ minitest
119
+ mysql2 (~> 0.3.0)
120
+ mysql_isolated_server (~> 0.5)
121
+ rails (~> 4.2.0.rc2)
122
+ rake
123
+ wwtd
@@ -1,9 +1,13 @@
1
1
  require 'bundler/setup'
2
2
  require 'ar_mysql_flexmaster'
3
3
  require 'active_record'
4
+ require 'minitest/autorun'
5
+
6
+ if !defined?(Minitest::Test)
7
+ Minitest::Test = MiniTest::Unit::TestCase
8
+ end
9
+
4
10
  require_relative 'boot_mysql_env'
5
- require 'test/unit'
6
- require 'debugger'
7
11
 
8
12
  File.open(File.dirname(File.expand_path(__FILE__)) + "/database.yml", "w+") do |f|
9
13
  f.write <<-EOL
@@ -32,7 +36,7 @@ reconnect_slave:
32
36
  end
33
37
 
34
38
  ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
35
- ActiveRecord::Base.establish_connection("test")
39
+ ActiveRecord::Base.establish_connection(:test)
36
40
 
37
41
  class User < ActiveRecord::Base
38
42
  end
@@ -57,9 +61,9 @@ end
57
61
 
58
62
  $original_master_port = $mysql_master.port
59
63
 
60
- class TestArFlexmaster < Test::Unit::TestCase
64
+ class TestArFlexmaster < Minitest::Test
61
65
  def setup
62
- ActiveRecord::Base.establish_connection("test")
66
+ ActiveRecord::Base.establish_connection(:test)
63
67
 
64
68
  $mysql_master.set_rw(true) if $mysql_master
65
69
  $mysql_slave.set_rw(false) if $mysql_slave
@@ -103,7 +107,11 @@ class TestArFlexmaster < Test::Unit::TestCase
103
107
  end
104
108
  User.create(:name => "foo")
105
109
  assert_equal $mysql_slave, master_connection
106
- assert User.first(:conditions => {:name => "foo"})
110
+ if ActiveRecord::VERSION::MAJOR >= 4
111
+ assert User.where(:name => "foo").exists?
112
+ else
113
+ assert User.first(:conditions => {:name => "foo"})
114
+ end
107
115
  end
108
116
 
109
117
  def test_should_hold_implicit_txs_and_then_continue
@@ -152,16 +160,6 @@ class TestArFlexmaster < Test::Unit::TestCase
152
160
  end
153
161
  end
154
162
 
155
- def test_should_choose_a_random_slave_connection
156
- h = {}
157
- 10.times do
158
- port = UserSlave.connection.execute("show global variables like 'port'").first.last.to_i
159
- h[port] = 1
160
- UserSlave.connection.reconnect!
161
- end
162
- assert_equal 2, h.size
163
- end
164
-
165
163
  def test_should_expose_the_current_master_and_port
166
164
  cx = ActiveRecord::Base.connection
167
165
  assert_equal "127.0.0.1", cx.current_host
@@ -34,6 +34,17 @@ $mysql_master.connection.query("GRANT ALL ON flexmaster_test.* to flex@localhost
34
34
  $mysql_master.connection.query("CREATE DATABASE flexmaster_test")
35
35
  $mysql_master.connection.query("CREATE TABLE flexmaster_test.users (id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(20))")
36
36
  $mysql_master.connection.query("INSERT INTO flexmaster_test.users set name='foo'")
37
-
38
37
  $mysql_slave.set_rw(false)
38
+ $mysql_slave_2.set_rw(false)
39
+
40
+ # let replication for the grants and such flow down. bleh.
41
+ repl_sync = false
42
+ while !repl_sync
43
+ repl_sync = [[$mysql_master, $mysql_slave], [$mysql_slave, $mysql_slave_2]].all? do |master, slave|
44
+ master_pos = master.connection.query("show master status").to_a.first["Position"]
45
+ slave.connection.query("show slave status").to_a.first["Exec_Master_Log_Pos"] == master_pos
46
+ end
47
+ sleep 1
48
+ end
49
+
39
50
  sleep if __FILE__ == $0
@@ -1,23 +1,15 @@
1
- require 'bundler/setup'
2
- require 'mysql2'
3
- require_relative '../boot_mysql_env'
4
- master_cut_script = File.expand_path(File.dirname(__FILE__)) + "/../../bin/master_cut"
1
+ require_relative "../integration_helper"
5
2
 
6
- $mysql_master.connection.query("set GLOBAL READ_ONLY=0")
7
- $mysql_slave.connection.query("set GLOBAL READ_ONLY=1")
3
+ class NoTrafficTest < Minitest::Test
4
+ def test_basic_cutover
5
+ $mysql_master.connection.query("set GLOBAL READ_ONLY=0")
6
+ $mysql_slave.connection.query("set GLOBAL READ_ONLY=1")
8
7
 
9
- puts "testing basic cutover..."
8
+ puts "testing basic cutover..."
10
9
 
11
- system "#{master_cut_script} 127.0.0.1:#{$mysql_master.port} 127.0.0.1:#{$mysql_slave.port} root -p ''"
12
- if $mysql_master.connection.query("select @@read_only as ro").first['ro'] != 1
13
- puts "Master is not readonly!"
14
- exit 1
10
+ system "#{master_cut_script} 127.0.0.1:#{$mysql_master.port} 127.0.0.1:#{$mysql_slave.port} root -p ''"
11
+ assert_ro($mysql_master.connection, 'master', true)
12
+ assert_ro($mysql_slave.connection, 'master', false)
13
+ end
15
14
  end
16
15
 
17
- if $mysql_slave.connection.query("select @@read_only as ro").first['ro'] != 0
18
- puts "Slave is not readwrite!"
19
- exit 1
20
- end
21
-
22
- puts "everything seemed to go ok..."
23
-