andyjeffries-rubyrep 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/History.txt +83 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +151 -0
  4. data/README.txt +37 -0
  5. data/bin/rubyrep +8 -0
  6. data/lib/rubyrep.rb +72 -0
  7. data/lib/rubyrep/base_runner.rb +195 -0
  8. data/lib/rubyrep/command_runner.rb +144 -0
  9. data/lib/rubyrep/committers/buffered_committer.rb +151 -0
  10. data/lib/rubyrep/committers/committers.rb +152 -0
  11. data/lib/rubyrep/configuration.rb +275 -0
  12. data/lib/rubyrep/connection_extenders/connection_extenders.rb +165 -0
  13. data/lib/rubyrep/connection_extenders/jdbc_extender.rb +65 -0
  14. data/lib/rubyrep/connection_extenders/mysql_extender.rb +59 -0
  15. data/lib/rubyrep/connection_extenders/postgresql_extender.rb +277 -0
  16. data/lib/rubyrep/database_proxy.rb +52 -0
  17. data/lib/rubyrep/direct_table_scan.rb +75 -0
  18. data/lib/rubyrep/generate_runner.rb +105 -0
  19. data/lib/rubyrep/initializer.rb +39 -0
  20. data/lib/rubyrep/log_helper.rb +30 -0
  21. data/lib/rubyrep/logged_change.rb +160 -0
  22. data/lib/rubyrep/logged_change_loader.rb +197 -0
  23. data/lib/rubyrep/noisy_connection.rb +80 -0
  24. data/lib/rubyrep/proxied_table_scan.rb +171 -0
  25. data/lib/rubyrep/proxy_block_cursor.rb +145 -0
  26. data/lib/rubyrep/proxy_connection.rb +431 -0
  27. data/lib/rubyrep/proxy_cursor.rb +44 -0
  28. data/lib/rubyrep/proxy_row_cursor.rb +43 -0
  29. data/lib/rubyrep/proxy_runner.rb +89 -0
  30. data/lib/rubyrep/replication_difference.rb +100 -0
  31. data/lib/rubyrep/replication_extenders/mysql_replication.rb +271 -0
  32. data/lib/rubyrep/replication_extenders/postgresql_replication.rb +236 -0
  33. data/lib/rubyrep/replication_extenders/replication_extenders.rb +26 -0
  34. data/lib/rubyrep/replication_helper.rb +142 -0
  35. data/lib/rubyrep/replication_initializer.rb +327 -0
  36. data/lib/rubyrep/replication_run.rb +142 -0
  37. data/lib/rubyrep/replication_runner.rb +166 -0
  38. data/lib/rubyrep/replicators/replicators.rb +42 -0
  39. data/lib/rubyrep/replicators/two_way_replicator.rb +361 -0
  40. data/lib/rubyrep/scan_progress_printers/progress_bar.rb +65 -0
  41. data/lib/rubyrep/scan_progress_printers/scan_progress_printers.rb +65 -0
  42. data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +111 -0
  43. data/lib/rubyrep/scan_report_printers/scan_report_printers.rb +67 -0
  44. data/lib/rubyrep/scan_report_printers/scan_summary_reporter.rb +75 -0
  45. data/lib/rubyrep/scan_runner.rb +25 -0
  46. data/lib/rubyrep/session.rb +230 -0
  47. data/lib/rubyrep/sync_helper.rb +121 -0
  48. data/lib/rubyrep/sync_runner.rb +31 -0
  49. data/lib/rubyrep/syncers/syncers.rb +112 -0
  50. data/lib/rubyrep/syncers/two_way_syncer.rb +174 -0
  51. data/lib/rubyrep/table_scan.rb +54 -0
  52. data/lib/rubyrep/table_scan_helper.rb +46 -0
  53. data/lib/rubyrep/table_sorter.rb +70 -0
  54. data/lib/rubyrep/table_spec_resolver.rb +142 -0
  55. data/lib/rubyrep/table_sync.rb +90 -0
  56. data/lib/rubyrep/task_sweeper.rb +77 -0
  57. data/lib/rubyrep/trigger_mode_switcher.rb +63 -0
  58. data/lib/rubyrep/type_casting_cursor.rb +31 -0
  59. data/lib/rubyrep/uninstall_runner.rb +93 -0
  60. data/lib/rubyrep/version.rb +9 -0
  61. data/rubyrep +8 -0
  62. data/rubyrep.bat +4 -0
  63. data/setup.rb +1585 -0
  64. data/spec/base_runner_spec.rb +218 -0
  65. data/spec/buffered_committer_spec.rb +274 -0
  66. data/spec/command_runner_spec.rb +145 -0
  67. data/spec/committers_spec.rb +178 -0
  68. data/spec/configuration_spec.rb +203 -0
  69. data/spec/connection_extender_interface_spec.rb +141 -0
  70. data/spec/connection_extenders_registration_spec.rb +164 -0
  71. data/spec/database_proxy_spec.rb +48 -0
  72. data/spec/database_rake_spec.rb +40 -0
  73. data/spec/db_specific_connection_extenders_spec.rb +34 -0
  74. data/spec/db_specific_replication_extenders_spec.rb +38 -0
  75. data/spec/direct_table_scan_spec.rb +61 -0
  76. data/spec/dolphins.jpg +0 -0
  77. data/spec/generate_runner_spec.rb +84 -0
  78. data/spec/initializer_spec.rb +46 -0
  79. data/spec/log_helper_spec.rb +39 -0
  80. data/spec/logged_change_loader_spec.rb +68 -0
  81. data/spec/logged_change_spec.rb +470 -0
  82. data/spec/noisy_connection_spec.rb +78 -0
  83. data/spec/postgresql_replication_spec.rb +48 -0
  84. data/spec/postgresql_schema_support_spec.rb +212 -0
  85. data/spec/postgresql_support_spec.rb +63 -0
  86. data/spec/progress_bar_spec.rb +77 -0
  87. data/spec/proxied_table_scan_spec.rb +151 -0
  88. data/spec/proxy_block_cursor_spec.rb +197 -0
  89. data/spec/proxy_connection_spec.rb +423 -0
  90. data/spec/proxy_cursor_spec.rb +56 -0
  91. data/spec/proxy_row_cursor_spec.rb +66 -0
  92. data/spec/proxy_runner_spec.rb +70 -0
  93. data/spec/replication_difference_spec.rb +161 -0
  94. data/spec/replication_extender_interface_spec.rb +367 -0
  95. data/spec/replication_extenders_spec.rb +32 -0
  96. data/spec/replication_helper_spec.rb +178 -0
  97. data/spec/replication_initializer_spec.rb +509 -0
  98. data/spec/replication_run_spec.rb +443 -0
  99. data/spec/replication_runner_spec.rb +254 -0
  100. data/spec/replicators_spec.rb +36 -0
  101. data/spec/rubyrep_spec.rb +8 -0
  102. data/spec/scan_detail_reporter_spec.rb +119 -0
  103. data/spec/scan_progress_printers_spec.rb +68 -0
  104. data/spec/scan_report_printers_spec.rb +67 -0
  105. data/spec/scan_runner_spec.rb +50 -0
  106. data/spec/scan_summary_reporter_spec.rb +61 -0
  107. data/spec/session_spec.rb +253 -0
  108. data/spec/spec.opts +1 -0
  109. data/spec/spec_helper.rb +305 -0
  110. data/spec/strange_name_support_spec.rb +135 -0
  111. data/spec/sync_helper_spec.rb +169 -0
  112. data/spec/sync_runner_spec.rb +78 -0
  113. data/spec/syncers_spec.rb +171 -0
  114. data/spec/table_scan_helper_spec.rb +36 -0
  115. data/spec/table_scan_spec.rb +49 -0
  116. data/spec/table_sorter_spec.rb +30 -0
  117. data/spec/table_spec_resolver_spec.rb +111 -0
  118. data/spec/table_sync_spec.rb +140 -0
  119. data/spec/task_sweeper_spec.rb +47 -0
  120. data/spec/trigger_mode_switcher_spec.rb +83 -0
  121. data/spec/two_way_replicator_spec.rb +721 -0
  122. data/spec/two_way_syncer_spec.rb +256 -0
  123. data/spec/type_casting_cursor_spec.rb +50 -0
  124. data/spec/uninstall_runner_spec.rb +93 -0
  125. metadata +190 -0
@@ -0,0 +1,141 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+ require 'digest/md5'
4
+
5
+ include RR
6
+
7
+ # All ConnectionExtenders need to pass this spec
8
+ describe "ConnectionExtender", :shared => true do
9
+ before(:each) do
10
+ end
11
+
12
+ it "primary_key_names should return primary key names ordered as per primary key index" do
13
+ session = Session.new
14
+ session.left.primary_key_names('extender_combined_key').should == ['first_id', 'second_id']
15
+
16
+ session.left.primary_key_names('extender_inverted_combined_key') \
17
+ .should == ['second_id', 'first_id']
18
+ end
19
+
20
+ it "primary_key_names should return an empty array for tables without any primary key" do
21
+ session = Session.new
22
+ session.left.primary_key_names('extender_without_key') \
23
+ .should == []
24
+ end
25
+
26
+ it "primary_key_names called for a non-existing table should throw an exception" do
27
+ session = Session.new
28
+ lambda {session.left.primary_key_names('non_existing_table')} \
29
+ .should raise_error(RuntimeError, /.*non_existing_table.*not exist/)
30
+ end
31
+
32
+ it "referenced_tables should identify the correct table dependencies" do
33
+ session = Session.new
34
+ referenced_tables = session.left.referenced_tables(['scanner_records', 'referencing_table'])
35
+ referenced_tables.size.should == 2
36
+ referenced_tables['scanner_records'].should == []
37
+ referenced_tables['referencing_table'].sort.
38
+ should == ["referenced_table", "referenced_table2"]
39
+ end
40
+
41
+ it "referenced_tables should return those tables without primary key" do
42
+ session = Session.new
43
+ referenced_tables = session.left.referenced_tables(['table_with_manual_key'])
44
+ referenced_tables.should == {'table_with_manual_key' => []}
45
+ end
46
+
47
+ it "select_cursor should handle zero result queries" do
48
+ session = Session.new
49
+ result = session.left.select_cursor :table => 'extender_no_record'
50
+ result.next?.should be_false
51
+ end
52
+
53
+ it "select_cursor should work if row_buffer_size is smaller than table size" do
54
+ session = Session.new
55
+ result = session.left.select_cursor(:table => 'scanner_records', :row_buffer_size => 2)
56
+ result.next_row
57
+ result.next_row
58
+ result.next_row['id'].should == 3
59
+ result.clear
60
+ end
61
+
62
+ it "select_cursor should allow iterating through records" do
63
+ session = Session.new
64
+ result = session.left.select_cursor :table => 'extender_one_record'
65
+ result.next?.should be_true
66
+ result.next_row.should == {'id' => 1, 'name' => 'Alice'}
67
+ end
68
+
69
+ it "select_cursor next_row should raise if there are no records" do
70
+ session = Session.new
71
+ result = session.left.select_cursor :table => 'extender_no_record'
72
+ lambda {result.next_row}.should raise_error(RuntimeError, 'no more rows available')
73
+ end
74
+
75
+ it "select_cursor next_row should handle multi byte characters correctly" do
76
+ session = Session.new
77
+ result = session.left.select_record(:table => "extender_type_check")['multi_byte'].
78
+ should == "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor."
79
+ end
80
+
81
+ it "select_cursor should read null values correctly" do
82
+ session = Session.new
83
+ result = session.left.select_record(
84
+ :table => 'extender_combined_key',
85
+ :row_keys => ['first_id' => 3, 'second_id' => 1]
86
+ ).should == {'first_id' => 3, 'second_id' => 1, 'name' => nil}
87
+ end
88
+
89
+ it "should read and write binary data correctly" do
90
+ session = Session.new
91
+
92
+ org_data = File.new(File.dirname(__FILE__) + '/dolphins.jpg').read
93
+ result_data = nil
94
+ begin
95
+ session.left.begin_db_transaction
96
+ session.left.insert_record('extender_type_check', {'id' => 6, 'binary_test' => org_data})
97
+
98
+ row = session.left.select_one(
99
+ 'select md5(binary_test) as md5 from extender_type_check where id = 6'
100
+ )
101
+ row['md5'].should == Digest::MD5.hexdigest(org_data)
102
+
103
+ result_data = session.left.select_record(
104
+ :table => "extender_type_check",
105
+ :row_keys => ["id" => 6]
106
+ )['binary_test']
107
+ Digest::MD5.hexdigest(result_data).should == Digest::MD5.hexdigest(org_data)
108
+ ensure
109
+ session.left.rollback_db_transaction
110
+ end
111
+ result_data.should == org_data
112
+ end
113
+
114
+ it "should read and write text data correctly" do
115
+ session = Session.new
116
+
117
+ org_data = "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor."
118
+ result_data = nil
119
+ begin
120
+ session.left.begin_db_transaction
121
+ sql = "insert into extender_type_check(id, text_test) values(2, '#{org_data}')"
122
+ session.left.execute sql
123
+
124
+ result_data = session.left.select_record(
125
+ :table => "extender_type_check",
126
+ :row_keys => ["id" => 2]
127
+ )["text_test"]
128
+ ensure
129
+ session.left.rollback_db_transaction
130
+ end
131
+ result_data.should == org_data
132
+ end
133
+
134
+ it "cursors returned by select_cursor should support clear" do
135
+ session = Session.new
136
+ result = session.left.select_cursor :table => 'extender_one_record'
137
+ result.next?.should be_true
138
+ result.should respond_to(:clear)
139
+ result.clear
140
+ end
141
+ end
@@ -0,0 +1,164 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ include RR
4
+
5
+ describe ConnectionExtenders do
6
+ before(:each) do
7
+ Initializer.configuration = standard_config
8
+ end
9
+
10
+ it "db_connect should install the already created logger" do
11
+ configuration = deep_copy(Initializer.configuration)
12
+ io = StringIO.new
13
+ logger = ActiveSupport::BufferedLogger.new(io)
14
+ configuration.left[:logger] = logger
15
+ session = Session.new configuration
16
+
17
+ session.left.connection.instance_eval {@logger}.should == logger
18
+ session.right.connection.instance_eval {@logger}.should_not == logger
19
+
20
+ session.left.select_one "select 'left_query'"
21
+ session.right.select_one "select 'right_query'"
22
+
23
+ io.string.should =~ /left_query/
24
+ io.string.should_not =~ /right_query/
25
+ end
26
+
27
+ it "db_connect should create and install the specified logger" do
28
+ configuration = deep_copy(Initializer.configuration)
29
+ io = StringIO.new
30
+ configuration.left[:logger] = io
31
+ session = Session.new configuration
32
+ session.left.select_one "select 'left_query'"
33
+ session.right.select_one "select 'right_query'"
34
+
35
+ io.string.should =~ /left_query/
36
+ io.string.should_not =~ /right_query/
37
+ end
38
+ end
39
+
40
+ describe ConnectionExtenders, "Registration" do
41
+ before(:each) do
42
+ Initializer.configuration = standard_config
43
+ @@old_cache_status = ConnectionExtenders.use_db_connection_cache(false)
44
+ end
45
+
46
+ after(:each) do
47
+ ConnectionExtenders.use_db_connection_cache(@@old_cache_status)
48
+ end
49
+
50
+ it "extenders should return list of registered connection extenders" do
51
+ ConnectionExtenders.extenders.include?(:postgresql).should be_true
52
+ end
53
+
54
+ it "register should register a new connection extender" do
55
+ ConnectionExtenders.register(:bla => :blub)
56
+
57
+ ConnectionExtenders.extenders.include?(:bla).should be_true
58
+ end
59
+
60
+ it "register should replace already existing connection extenders" do
61
+ ConnectionExtenders.register(:bla => :blub)
62
+ ConnectionExtenders.register(:bla => :blub2)
63
+
64
+ ConnectionExtenders.extenders[:bla].should == :blub2
65
+ end
66
+
67
+ it "initialize should establish the database connections" do
68
+ mock_active_record :once
69
+
70
+ ConnectionExtenders.db_connect Initializer.configuration.left
71
+ end
72
+
73
+ it "db_connect should use jdbc configuration adapter and extender under jruby" do
74
+ fake_ruby_platform 'java' do
75
+ mock_active_record :once
76
+ used_extender = nil
77
+ ConnectionExtenders.extenders.should_receive('[]'.to_sym).once \
78
+ .and_return {|extender| used_extender = extender }
79
+
80
+ configuration = deep_copy(Initializer.configuration)
81
+ configuration.left[:adapter] = 'dummyadapter'
82
+
83
+ ConnectionExtenders.db_connect configuration.left
84
+
85
+ $used_config[:adapter].should == "jdbcdummyadapter"
86
+ used_extender.should == :jdbc
87
+ end
88
+ end
89
+
90
+ it "db_connect created connections should be alive" do
91
+ connection = ConnectionExtenders.db_connect Initializer.configuration.left
92
+
93
+ connection.should be_active
94
+ end
95
+
96
+ it "db_connect should include the connection extender into connection" do
97
+ connection = ConnectionExtenders.db_connect Initializer.configuration.left
98
+
99
+ connection.should respond_to(:primary_key_names)
100
+ end
101
+
102
+ it "db_connect should raise an Exception if no fitting connection extender is available" do
103
+ # If unknown connection adapters are encountered in jruby, then we
104
+ # automatically use JdbcExtender.
105
+ # Means that this test only makes sense if not running on jruby
106
+ if not RUBY_PLATFORM =~ /java/
107
+ mock_active_record :once
108
+
109
+ config = deep_copy(Initializer.configuration)
110
+
111
+ config.left[:adapter] = 'dummy'
112
+
113
+ lambda {ConnectionExtenders.db_connect config.left}.should raise_error(RuntimeError, /dummy/)
114
+ end
115
+ end
116
+
117
+ it "use_db_connection_cache should set the new cache status and return the old one" do
118
+ ConnectionExtenders.use_db_connection_cache :first_status
119
+ first_status = ConnectionExtenders.use_db_connection_cache :second_status
120
+ second_status = ConnectionExtenders.use_db_connection_cache :whatever
121
+ first_status.should == :first_status
122
+ second_status.should == :second_status
123
+ end
124
+
125
+ it "clear_db_connection_cache should clear the connection cache" do
126
+ old_cache = ConnectionExtenders.connection_cache
127
+ begin
128
+ ConnectionExtenders.connection_cache = :dummy_cache
129
+ ConnectionExtenders.clear_db_connection_cache
130
+ ConnectionExtenders.connection_cache.should == {}
131
+ ensure
132
+ ConnectionExtenders.connection_cache = old_cache
133
+ end
134
+ end
135
+
136
+ it "db_connect should create the database connection if not yet cached" do
137
+ old_cache = ConnectionExtenders.connection_cache
138
+ begin
139
+ ConnectionExtenders.clear_db_connection_cache
140
+ mock_active_record :once
141
+ ConnectionExtenders.use_db_connection_cache true
142
+ ConnectionExtenders.db_connect Initializer.configuration.left
143
+ ConnectionExtenders.connection_cache.should_not be_empty
144
+ ensure
145
+ ConnectionExtenders.connection_cache = old_cache
146
+ end
147
+ end
148
+
149
+ it "db_connect should not create the database connection if already cached and alive" do
150
+ old_cache = ConnectionExtenders.connection_cache
151
+ begin
152
+ ConnectionExtenders.clear_db_connection_cache
153
+ mock_active_record :once # only mocked once even though db_connect is called twice
154
+ ConnectionExtenders.use_db_connection_cache true
155
+ connection = ConnectionExtenders.db_connect Initializer.configuration.left
156
+ connection.should_receive(:active?).and_return(:true)
157
+ ConnectionExtenders.db_connect Initializer.configuration.left
158
+ ensure
159
+ ConnectionExtenders.connection_cache = old_cache
160
+ end
161
+ end
162
+
163
+ end
164
+
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ include RR
4
+
5
+ describe DatabaseProxy do
6
+ before(:each) do
7
+ Initializer.configuration = standard_config
8
+ end
9
+
10
+ it "initialize should create an empty session regiser" do
11
+ proxy = DatabaseProxy.new
12
+ proxy.session_register.should == {}
13
+ end
14
+
15
+ def create_proxy_and_session
16
+ proxy = DatabaseProxy.new
17
+ session = proxy.create_session Initializer.configuration.left
18
+ return proxy, session
19
+ end
20
+
21
+ it "create_session should register the created session" do
22
+ proxy, session = create_proxy_and_session
23
+
24
+ session.should be_an_instance_of(ProxyConnection)
25
+ proxy.session_register.include?(session).should == true
26
+ end
27
+
28
+ it "destroy_session should destroy and unregister the session" do
29
+ proxy, session = create_proxy_and_session
30
+ session.should_receive(:destroy)
31
+
32
+ proxy.destroy_session session
33
+
34
+ proxy.session_register.include?(session).should == false
35
+ end
36
+
37
+ it "ping should respond with 'pong'" do
38
+ proxy = DatabaseProxy.new
39
+ proxy.ping.should == 'pong'
40
+ end
41
+
42
+ it "terminate should exit the proxy" do
43
+ proxy = DatabaseProxy.new
44
+ Thread.main.should_receive(:raise).with(SystemExit)
45
+
46
+ proxy.terminate!
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ load File.dirname(__FILE__) + '/../tasks/database.rake'
3
+
4
+ describe "database.rake" do
5
+ before(:each) do
6
+ end
7
+
8
+ it "create_database should create a non-existing database" do
9
+ RR::ConnectionExtenders.should_receive(:db_connect).and_raise("something")
10
+ should_receive("`").with("createdb \"dummy\" -E utf8")
11
+
12
+ create_database :adapter => "postgresql", :database => "dummy"
13
+ end
14
+
15
+ it "create_database should not try to create existing databases" do
16
+ RR::ConnectionExtenders.should_receive(:db_connect)
17
+ should_receive(:puts).with("database existing_db already exists")
18
+
19
+ create_database :adapter => 'postgresql', :database => "existing_db"
20
+ end
21
+
22
+ it "create_database should complain about unsupported adapters" do
23
+ should_receive(:puts).with("adapter unsupported_adapter not supported")
24
+
25
+ create_database :adapter => "unsupported_adapter"
26
+ end
27
+
28
+ it "drop_database should drop a PostgreSQL database" do
29
+ should_receive("`").with("dropdb \"dummy\"")
30
+
31
+ drop_database :adapter => "postgresql", :database => "dummy"
32
+ end
33
+
34
+ it "drop_database should complain about unsupported adapters" do
35
+ should_receive(:puts).with("adapter unsupported_adapter not supported")
36
+
37
+ drop_database :adapter => "unsupported_adapter"
38
+ end
39
+ end
40
+
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+
4
+ include RR
5
+
6
+ extenders = [:mysql2, :postgres]
7
+
8
+ extenders.each do |extender|
9
+ describe "#{extender.to_s.capitalize} Connection Extender" do
10
+ before(:each) do
11
+ @org_test_db = ENV['RR_TEST_DB']
12
+ ENV['RR_TEST_DB'] = extender.to_s
13
+ Initializer.configuration = standard_config
14
+ end
15
+
16
+ after(:each) do
17
+ ENV['RR_TEST_DB'] = @org_test_db
18
+ end
19
+
20
+ begin
21
+ if ENV['RR_TEST_DB'] != @org_test_db.to_s
22
+ # If the current adapter is *not* the adapter for the standard tests
23
+ # (meaning the adapter which is used to run all other tests)
24
+ # then only run the extender spec if the database connection is available
25
+ Session.new read_config(extender)
26
+ end
27
+ it_should_behave_like "ConnectionExtender"
28
+ rescue Exception => e
29
+ at_exit do
30
+ puts "#{__FILE__}:#{__LINE__}: DB Connection failed with '#{e}' ==> #{extender.to_s.capitalize} connection extender not tested"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+
4
+ require 'replication_extender_interface_spec.rb'
5
+ require 'postgresql_replication_spec.rb'
6
+
7
+ include RR
8
+
9
+ extenders = [:postgres, :mysql2]
10
+
11
+ extenders.each do |extender|
12
+ describe "#{extender.to_s.capitalize} Replication Extender" do
13
+ before(:each) do
14
+ @org_test_db = ENV['RR_TEST_DB']
15
+ ENV['RR_TEST_DB'] = extender.to_s
16
+ Initializer.configuration = standard_config
17
+ end
18
+
19
+ after(:each) do
20
+ ENV['RR_TEST_DB'] = @org_test_db
21
+ end
22
+
23
+ begin
24
+ if ENV['RR_TEST_DB'] != @org_test_db.to_s
25
+ # If the current adapter is *not* the adapter for the standard tests
26
+ # (meaning the adapter which is used to run all other tests)
27
+ # then only run the extender spec if the database connection is available
28
+ Session.new read_config(extender)
29
+ end
30
+ it_should_behave_like "ReplicationExtender"
31
+ it_should_behave_like "PostgreSQLReplication" if extender == :postgres
32
+ rescue Exception => e
33
+ at_exit do
34
+ puts "#{__FILE__}:#{__LINE__}: DB Connection failed with '#{e}' ==> #{extender.to_s.capitalize} replication extender not tested"
35
+ end
36
+ end
37
+ end
38
+ end