rubyrep 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +84 -0
- data/History.txt +6 -0
- data/README.txt +1 -1
- data/Rakefile +6 -27
- data/bin/rubyrep +1 -1
- data/config/mysql_config.rb +2 -2
- data/config/postgres_config.rb +5 -3
- data/lib/rubyrep/command_runner.rb +1 -1
- data/lib/rubyrep/connection_extenders/connection_extenders.rb +30 -44
- data/lib/rubyrep/connection_extenders/mysql_extender.rb +23 -1
- data/lib/rubyrep/connection_extenders/postgresql_extender.rb +31 -168
- data/lib/rubyrep/generate_runner.rb +1 -1
- data/lib/rubyrep/logged_change.rb +1 -1
- data/lib/rubyrep/proxy_connection.rb +22 -12
- data/lib/rubyrep/replication_difference.rb +1 -1
- data/lib/rubyrep/replication_extenders/mysql_replication.rb +1 -1
- data/lib/rubyrep/replication_helper.rb +1 -1
- data/lib/rubyrep/replication_runner.rb +10 -0
- data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +1 -1
- data/lib/rubyrep/table_spec_resolver.rb +1 -1
- data/lib/rubyrep/type_casting_cursor.rb +8 -4
- data/lib/rubyrep/version.rb +1 -7
- data/lib/rubyrep.rb +4 -3
- data/rubyrep +4 -0
- data/rubyrep.bat +5 -0
- data/rubyrep.gemspec +29 -0
- data/sims/performance/big_rep_spec.rb +34 -17
- data/sims/performance/performance.rake +11 -31
- data/tasks/database.rake +14 -14
- data/tasks/java.rake +18 -5
- data/tasks/rspec.rake +14 -34
- data/tasks/stats.rake +1 -16
- metadata +99 -162
- data/.gemtest +0 -0
- data/config/requirements.rb +0 -32
- data/lib/rubyrep/connection_extenders/jdbc_extender.rb +0 -65
- data/spec/base_runner_spec.rb +0 -218
- data/spec/buffered_committer_spec.rb +0 -274
- data/spec/command_runner_spec.rb +0 -145
- data/spec/committers_spec.rb +0 -178
- data/spec/configuration_spec.rb +0 -203
- data/spec/connection_extender_interface_spec.rb +0 -141
- data/spec/connection_extenders_registration_spec.rb +0 -164
- data/spec/database_proxy_spec.rb +0 -48
- data/spec/database_rake_spec.rb +0 -40
- data/spec/db_specific_connection_extenders_spec.rb +0 -34
- data/spec/db_specific_replication_extenders_spec.rb +0 -38
- data/spec/direct_table_scan_spec.rb +0 -61
- data/spec/dolphins.jpg +0 -0
- data/spec/generate_runner_spec.rb +0 -84
- data/spec/initializer_spec.rb +0 -46
- data/spec/log_helper_spec.rb +0 -39
- data/spec/logged_change_loader_spec.rb +0 -68
- data/spec/logged_change_spec.rb +0 -470
- data/spec/noisy_connection_spec.rb +0 -78
- data/spec/postgresql_replication_spec.rb +0 -48
- data/spec/postgresql_schema_support_spec.rb +0 -212
- data/spec/postgresql_support_spec.rb +0 -63
- data/spec/progress_bar_spec.rb +0 -77
- data/spec/proxied_table_scan_spec.rb +0 -151
- data/spec/proxy_block_cursor_spec.rb +0 -197
- data/spec/proxy_connection_spec.rb +0 -423
- data/spec/proxy_cursor_spec.rb +0 -56
- data/spec/proxy_row_cursor_spec.rb +0 -66
- data/spec/proxy_runner_spec.rb +0 -70
- data/spec/replication_difference_spec.rb +0 -161
- data/spec/replication_extender_interface_spec.rb +0 -367
- data/spec/replication_extenders_spec.rb +0 -32
- data/spec/replication_helper_spec.rb +0 -178
- data/spec/replication_initializer_spec.rb +0 -509
- data/spec/replication_run_spec.rb +0 -443
- data/spec/replication_runner_spec.rb +0 -254
- data/spec/replicators_spec.rb +0 -36
- data/spec/rubyrep_spec.rb +0 -8
- data/spec/scan_detail_reporter_spec.rb +0 -119
- data/spec/scan_progress_printers_spec.rb +0 -68
- data/spec/scan_report_printers_spec.rb +0 -67
- data/spec/scan_runner_spec.rb +0 -50
- data/spec/scan_summary_reporter_spec.rb +0 -61
- data/spec/session_spec.rb +0 -253
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -305
- data/spec/strange_name_support_spec.rb +0 -135
- data/spec/sync_helper_spec.rb +0 -169
- data/spec/sync_runner_spec.rb +0 -78
- data/spec/syncers_spec.rb +0 -171
- data/spec/table_scan_helper_spec.rb +0 -36
- data/spec/table_scan_spec.rb +0 -49
- data/spec/table_sorter_spec.rb +0 -30
- data/spec/table_spec_resolver_spec.rb +0 -111
- data/spec/table_sync_spec.rb +0 -140
- data/spec/task_sweeper_spec.rb +0 -47
- data/spec/trigger_mode_switcher_spec.rb +0 -83
- data/spec/two_way_replicator_spec.rb +0 -721
- data/spec/two_way_syncer_spec.rb +0 -256
- data/spec/type_casting_cursor_spec.rb +0 -50
- data/spec/uninstall_runner_spec.rb +0 -93
- data/tasks/rubyrep.tailor +0 -18
- data/tasks/website.rake +0 -19
data/spec/syncers_spec.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe Syncers do
|
6
|
-
before(:each) do
|
7
|
-
@old_syncers = Syncers.syncers
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:each) do
|
11
|
-
Syncers.instance_variable_set :@syncers, @old_syncers
|
12
|
-
end
|
13
|
-
|
14
|
-
it "syncers should return empty hash if nil" do
|
15
|
-
Syncers.instance_variable_set :@syncers, nil
|
16
|
-
Syncers.syncers.should == {}
|
17
|
-
end
|
18
|
-
|
19
|
-
it "syncers should return the registered syncers" do
|
20
|
-
Syncers.instance_variable_set :@syncers, :dummy_data
|
21
|
-
Syncers.syncers.should == :dummy_data
|
22
|
-
end
|
23
|
-
|
24
|
-
it "configured_syncer should return the correct syncer as per :syncer option, if both :syncer and :replicator is configured" do
|
25
|
-
options = {
|
26
|
-
:syncer => :two_way,
|
27
|
-
:replicator => :key2
|
28
|
-
}
|
29
|
-
Syncers.configured_syncer(options).should == Syncers::TwoWaySyncer
|
30
|
-
end
|
31
|
-
|
32
|
-
it "configured_syncer should return the correct syncer as per :replicator option if no :syncer option is provided" do
|
33
|
-
options = {:replicator => :two_way}
|
34
|
-
Syncers.configured_syncer(options).should == Syncers::TwoWaySyncer
|
35
|
-
end
|
36
|
-
|
37
|
-
it "register should register the provided commiter" do
|
38
|
-
Syncers.instance_variable_set :@syncers, nil
|
39
|
-
Syncers.register :a_key => :a
|
40
|
-
Syncers.register :b_key => :b
|
41
|
-
Syncers.syncers[:a_key].should == :a
|
42
|
-
Syncers.syncers[:b_key].should == :b
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe Syncers::OneWaySyncer do
|
47
|
-
before(:each) do
|
48
|
-
Initializer.configuration = standard_config
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should register itself" do
|
52
|
-
Syncers::syncers[:one_way].should == Syncers::OneWaySyncer
|
53
|
-
end
|
54
|
-
|
55
|
-
it "initialize should store sync_helper" do
|
56
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
57
|
-
helper = SyncHelper.new(sync)
|
58
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
59
|
-
syncer.sync_helper.should == helper
|
60
|
-
end
|
61
|
-
|
62
|
-
it "initialize should calculate course source, target and source_record_index" do
|
63
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
64
|
-
helper = SyncHelper.new(sync)
|
65
|
-
|
66
|
-
# verify correct behaviour if syncing to the left
|
67
|
-
helper.stub!(:sync_options).and_return({:direction => :left})
|
68
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
69
|
-
syncer.source.should == :right
|
70
|
-
syncer.target.should == :left
|
71
|
-
syncer.source_record_index.should == 1
|
72
|
-
|
73
|
-
# verify correct behaviour if syncing to the right
|
74
|
-
helper.stub!(:sync_options).and_return({:direction => :right})
|
75
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
76
|
-
syncer.source.should == :left
|
77
|
-
syncer.target.should == :right
|
78
|
-
syncer.source_record_index.should == 0
|
79
|
-
end
|
80
|
-
|
81
|
-
it "default_option should return the correct default options" do
|
82
|
-
Syncers::OneWaySyncer.default_options.should == {
|
83
|
-
:direction => :right,
|
84
|
-
:delete => false, :update => true, :insert => true
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
it "sync_difference should only delete if :delete option is given" do
|
89
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
90
|
-
helper = SyncHelper.new(sync)
|
91
|
-
helper.stub!(:sync_options).and_return({:direction => :left})
|
92
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
93
|
-
helper.should_not_receive(:delete_record)
|
94
|
-
helper.should_not_receive(:update_record)
|
95
|
-
helper.should_not_receive(:insert_record)
|
96
|
-
syncer.sync_difference(:left, :dummy_record)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "sync_difference should delete in the right database" do
|
100
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
101
|
-
helper = SyncHelper.new(sync)
|
102
|
-
helper.stub!(:sync_options).and_return({:direction => :left, :delete => true})
|
103
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
104
|
-
helper.should_receive(:delete_record).with(:left, 'scanner_records', :dummy_record)
|
105
|
-
helper.should_not_receive(:update_record)
|
106
|
-
helper.should_not_receive(:insert_record)
|
107
|
-
syncer.sync_difference(:left, :dummy_record)
|
108
|
-
|
109
|
-
helper = SyncHelper.new(sync)
|
110
|
-
helper.stub!(:sync_options).and_return({:direction => :right, :delete => true})
|
111
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
112
|
-
helper.should_receive(:delete_record).with(:right, 'scanner_records', :dummy_record)
|
113
|
-
syncer.sync_difference(:right, :dummy_record)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "sync_difference should not insert if :insert option is not true" do
|
117
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
118
|
-
helper = SyncHelper.new(sync)
|
119
|
-
helper.stub!(:sync_options).and_return({:direction => :left, :insert => false})
|
120
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
121
|
-
helper.should_not_receive(:delete_record)
|
122
|
-
helper.should_not_receive(:update_record)
|
123
|
-
helper.should_not_receive(:insert_record)
|
124
|
-
syncer.sync_difference(:right, :dummy_record)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "sync_difference should insert in the right database" do
|
128
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
129
|
-
helper = SyncHelper.new(sync)
|
130
|
-
helper.stub!(:sync_options).and_return({:direction => :left, :insert => true})
|
131
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
132
|
-
helper.should_not_receive(:delete_record)
|
133
|
-
helper.should_not_receive(:update_record)
|
134
|
-
helper.should_receive(:insert_record).with(:left, 'scanner_records', :dummy_record)
|
135
|
-
syncer.sync_difference(:right, :dummy_record)
|
136
|
-
|
137
|
-
helper = SyncHelper.new(sync)
|
138
|
-
helper.stub!(:sync_options).and_return({:direction => :right, :insert => true})
|
139
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
140
|
-
helper.should_receive(:insert_record).with(:right, 'scanner_records', :dummy_record)
|
141
|
-
syncer.sync_difference(:left, :dummy_record)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "sync_difference should not update if :update option is not true" do
|
145
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
146
|
-
helper = SyncHelper.new(sync)
|
147
|
-
helper.stub!(:sync_options).and_return({:direction => :left, :update => false})
|
148
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
149
|
-
helper.should_not_receive(:delete_record)
|
150
|
-
helper.should_not_receive(:update_record)
|
151
|
-
helper.should_not_receive(:insert_record)
|
152
|
-
syncer.sync_difference(:conflict, :dummy_records)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "sync_difference should update the right values in the right database" do
|
156
|
-
sync = TableSync.new(Session.new, 'scanner_records')
|
157
|
-
helper = SyncHelper.new(sync)
|
158
|
-
helper.stub!(:sync_options).and_return({:direction => :left, :update => true})
|
159
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
160
|
-
helper.should_not_receive(:delete_record)
|
161
|
-
helper.should_receive(:update_record).with(:left, 'scanner_records', :right_record)
|
162
|
-
helper.should_not_receive(:insert_record)
|
163
|
-
syncer.sync_difference(:conflict, [:left_record, :right_record])
|
164
|
-
|
165
|
-
helper = SyncHelper.new(sync)
|
166
|
-
helper.stub!(:sync_options).and_return({:direction => :right, :update => true})
|
167
|
-
syncer = Syncers::OneWaySyncer.new(helper)
|
168
|
-
helper.should_receive(:update_record).with(:right, 'scanner_records', :left_record)
|
169
|
-
syncer.sync_difference(:conflict, [:left_record, :right_record])
|
170
|
-
end
|
171
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TableScanHelper do
|
6
|
-
before(:each) do
|
7
|
-
@scan = Object.new
|
8
|
-
@scan.extend TableScanHelper
|
9
|
-
end
|
10
|
-
|
11
|
-
it "rank_rows should calculate the correct rank of rows based on their primary keys" do
|
12
|
-
@scan.stub!(:primary_key_names).and_return(['first_id', 'second_id'])
|
13
|
-
@scan.rank_rows({'first_id' => 1, 'second_id' => 1}, {'first_id' => 1, 'second_id' => 1}).should == 0
|
14
|
-
@scan.rank_rows({'first_id' => 1, 'second_id' => 1}, {'first_id' => 1, 'second_id' => 2}).should == -1
|
15
|
-
@scan.rank_rows({'first_id' => 2, 'second_id' => 1}, {'first_id' => 1, 'second_id' => 1}).should == 1
|
16
|
-
|
17
|
-
# should rank strings according to database logic ('a' < 'A')
|
18
|
-
# instead of the Ruby logic (which is the other way round)
|
19
|
-
@scan.rank_rows({'first_id' => 'a', 'second_id' => 1}, {'first_id' => 'B', 'second_id' => 1}).should == -1
|
20
|
-
@scan.rank_rows({'first_id' => 'a', 'second_id' => 1}, {'first_id' => 'A', 'second_id' => 1}).should == -1
|
21
|
-
@scan.rank_rows({'first_id' => 'a', 'second_id' => 1}, {'first_id' => 'a', 'second_id' => 1}).should == 0
|
22
|
-
|
23
|
-
lambda {@scan.rank_rows(nil,nil)}.should raise_error(RuntimeError, 'At least one of left_row and right_row must not be nil!')
|
24
|
-
@scan.rank_rows(nil, {'first_id' => 1, 'second_id' => 1}).should == 1
|
25
|
-
@scan.rank_rows({'first_id' => 1, 'second_id' => 1}, nil).should == -1
|
26
|
-
end
|
27
|
-
|
28
|
-
it "table_scan_class should return TableScan for non-proxied sessions" do
|
29
|
-
TableScanHelper.scan_class(Session.new(standard_config)).should == DirectTableScan
|
30
|
-
end
|
31
|
-
|
32
|
-
it "table_scan_class should return ProxiedTableScan for proxied sessions" do
|
33
|
-
ensure_proxy
|
34
|
-
TableScanHelper.scan_class(Session.new(proxied_config)).should == ProxiedTableScan
|
35
|
-
end
|
36
|
-
end
|
data/spec/table_scan_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TableScan do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = standard_config
|
8
|
-
end
|
9
|
-
|
10
|
-
it "initialize should raise exception if table doesn't have primary keys" do
|
11
|
-
session = Session.new
|
12
|
-
lambda {TableScan.new session, 'extender_without_key'} \
|
13
|
-
.should raise_error(RuntimeError, /.*extender_without_key.*primary key/)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "initialize should cache the primary keys of the given table" do
|
17
|
-
session = Session.new
|
18
|
-
scann = TableScan.new session, 'scanner_records'
|
19
|
-
scann.primary_key_names.should == ['id']
|
20
|
-
end
|
21
|
-
|
22
|
-
it "initialize should use the name of the left table as overwritable default for right table" do
|
23
|
-
session = Session.new
|
24
|
-
TableScan.new(session, 'scanner_records').right_table.should == 'scanner_records'
|
25
|
-
TableScan.new(session, 'scanner_records', 'dummy').right_table.should == 'dummy'
|
26
|
-
end
|
27
|
-
|
28
|
-
it "progress_printer= should store the progress printer class" do
|
29
|
-
session = Session.new
|
30
|
-
TableScan.new(session, 'scanner_records').progress_printer = :dummy_printer_class
|
31
|
-
end
|
32
|
-
|
33
|
-
it "update_progres should create the progress printer and report the progress" do
|
34
|
-
session = Session.new
|
35
|
-
scan = TableScan.new(session, 'extender_one_record', 'extender_no_record')
|
36
|
-
|
37
|
-
progress_printer_class = mock("progress printer class")
|
38
|
-
progress_printer = mock("progress printer")
|
39
|
-
progress_printer_class.should_receive(:new).
|
40
|
-
with(1, scan.session, 'extender_one_record', 'extender_no_record').
|
41
|
-
and_return(progress_printer)
|
42
|
-
progress_printer.should_receive(:step).with(2)
|
43
|
-
progress_printer.should_receive(:step).with(3)
|
44
|
-
|
45
|
-
scan.progress_printer = progress_printer_class
|
46
|
-
scan.update_progress 2
|
47
|
-
scan.update_progress 3
|
48
|
-
end
|
49
|
-
end
|
data/spec/table_sorter_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TableSorter do
|
6
|
-
before(:each) do
|
7
|
-
end
|
8
|
-
|
9
|
-
it "sort should order the tables correctly" do
|
10
|
-
tables = [
|
11
|
-
'scanner_records',
|
12
|
-
'referencing_table',
|
13
|
-
'referenced_table',
|
14
|
-
'scanner_text_key',
|
15
|
-
]
|
16
|
-
|
17
|
-
sorter = TableSorter.new Session.new(standard_config), tables
|
18
|
-
sorted_tables = sorter.sort
|
19
|
-
|
20
|
-
# make sure it contains the original tables
|
21
|
-
sorted_tables.sort.should == tables.sort
|
22
|
-
|
23
|
-
# make sure the referenced table comes before the referencing table
|
24
|
-
sorted_tables.grep(/referenc/).should == ['referenced_table', 'referencing_table']
|
25
|
-
|
26
|
-
# verify that we are using TSort#tsort to get that result
|
27
|
-
sorter.should_not_receive(:tsort)
|
28
|
-
sorter.sort
|
29
|
-
end
|
30
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TableSpecResolver do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = standard_config
|
8
|
-
@session = Session.new
|
9
|
-
@resolver = TableSpecResolver.new @session
|
10
|
-
end
|
11
|
-
|
12
|
-
it "initialize should store the session and cache the tables of the session" do
|
13
|
-
@resolver.session.should == @session
|
14
|
-
end
|
15
|
-
|
16
|
-
it "tables should return the tables of the specified database" do
|
17
|
-
@resolver.tables(:left).should == @session.left.tables
|
18
|
-
@resolver.tables(:right).should == @session.right.tables
|
19
|
-
end
|
20
|
-
|
21
|
-
it "resolve should resolve direct table names correctly" do
|
22
|
-
@resolver.resolve(['scanner_records', 'referenced_table']).should == [
|
23
|
-
{:left => 'scanner_records', :right => 'scanner_records'},
|
24
|
-
{:left => 'referenced_table', :right => 'referenced_table'}
|
25
|
-
]
|
26
|
-
end
|
27
|
-
|
28
|
-
it "resolve should resolve table name pairs correctly" do
|
29
|
-
@resolver.resolve(['left_table , right_table']).should == [
|
30
|
-
{:left => 'left_table', :right => 'right_table'}
|
31
|
-
]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "resolve should complain about non-existing tables" do
|
35
|
-
lambda {@resolver.resolve(['dummy, scanner_records'])}.
|
36
|
-
should raise_error(/non-existing.*dummy/)
|
37
|
-
lambda {@resolver.resolve(['left_table, left_table'])}.
|
38
|
-
should raise_error(/non-existing.*left_table/)
|
39
|
-
lambda {@resolver.resolve(['left_table'])}.
|
40
|
-
should raise_error(/non-existing.*left_table/)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "resolve should not complain about regexp specified tables not existing in right database" do
|
44
|
-
@resolver.resolve([/^scanner_records$/, /left_table/]).
|
45
|
-
should == [{:left => 'scanner_records', :right => 'scanner_records'}]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "resolve should not check for non-existing tables if that is disabled" do
|
49
|
-
lambda {@resolver.resolve(['dummy, scanner_records'], [], false)}.
|
50
|
-
should_not raise_error
|
51
|
-
end
|
52
|
-
|
53
|
-
it "resolve should resolve string in form of regular expression correctly" do
|
54
|
-
@resolver.resolve(['/SCANNER_RECORDS|scanner_text_key/']).sort { |a,b|
|
55
|
-
a[:left] <=> b[:left]
|
56
|
-
}.should == [
|
57
|
-
{:left => 'scanner_records', :right => 'scanner_records'},
|
58
|
-
{:left => 'scanner_text_key', :right => 'scanner_text_key'}
|
59
|
-
]
|
60
|
-
end
|
61
|
-
|
62
|
-
it "resolve should resolve regular expressions correctly" do
|
63
|
-
@resolver.resolve([/SCANNER_RECORDS|scanner_text_key/]).sort { |a,b|
|
64
|
-
a[:left] <=> b[:left]
|
65
|
-
}.should == [
|
66
|
-
{:left => 'scanner_records', :right => 'scanner_records'},
|
67
|
-
{:left => 'scanner_text_key', :right => 'scanner_text_key'}
|
68
|
-
]
|
69
|
-
end
|
70
|
-
|
71
|
-
it "resolve should should not return the same table multiple times" do
|
72
|
-
@resolver.resolve([
|
73
|
-
'scanner_records',
|
74
|
-
'scanner_records',
|
75
|
-
'scanner_records, bla',
|
76
|
-
'/scanner_records/'
|
77
|
-
]
|
78
|
-
).should == [
|
79
|
-
{:left => 'scanner_records', :right => 'scanner_records'}
|
80
|
-
]
|
81
|
-
end
|
82
|
-
|
83
|
-
it "resolve should not return tables that are excluded" do
|
84
|
-
@resolver.resolve(
|
85
|
-
[/SCANNER_RECORDS|scanner_text_key/],
|
86
|
-
[/scanner_text/]
|
87
|
-
).should == [
|
88
|
-
{:left => 'scanner_records', :right => 'scanner_records'},
|
89
|
-
]
|
90
|
-
end
|
91
|
-
|
92
|
-
it "non_existing_tables should return an empty hash if all tables exist" do
|
93
|
-
table_pairs = [{:left => 'scanner_records', :right => 'referenced_table'}]
|
94
|
-
@resolver.non_existing_tables(table_pairs).should == {}
|
95
|
-
end
|
96
|
-
|
97
|
-
it "non_existing_tables should return a hash of non-existing tables" do
|
98
|
-
table_pairs = [{:left => 'scanner_records', :right => 'bla'}]
|
99
|
-
@resolver.non_existing_tables(table_pairs).should == {:right => ['bla']}
|
100
|
-
|
101
|
-
table_pairs = [
|
102
|
-
{:left => 'blub', :right => 'bla'},
|
103
|
-
{:left => 'scanner_records', :right => 'xyz'}
|
104
|
-
]
|
105
|
-
@resolver.non_existing_tables(table_pairs).should == {
|
106
|
-
:left => ['blub'],
|
107
|
-
:right => ['bla', 'xyz']
|
108
|
-
}
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
data/spec/table_sync_spec.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TableSync do
|
6
|
-
it "sync_options should return the correct table specific sync options" do
|
7
|
-
config = deep_copy(standard_config)
|
8
|
-
old_table_specific_options = config.tables_with_options
|
9
|
-
begin
|
10
|
-
config.options = {:syncer => :bla}
|
11
|
-
config.include_tables 'scanner_records', {:syncer => :blub}
|
12
|
-
TableSync.new(Session.new(config), 'scanner_records').sync_options[:syncer] \
|
13
|
-
.should == :blub
|
14
|
-
ensure
|
15
|
-
config.instance_eval {@tables_with_options = old_table_specific_options}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "execute_sync_hook should work if the hook is not configured" do
|
20
|
-
session = Session.new standard_config
|
21
|
-
sync = TableSync.new(session, 'scanner_records')
|
22
|
-
sync.execute_sync_hook(:before_table_sync)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "execute_sync_hook should execute the given SQL command" do
|
26
|
-
config = deep_copy(standard_config)
|
27
|
-
config.add_table_options 'scanner_records', :before_table_sync => 'dummy_command'
|
28
|
-
session = Session.new config
|
29
|
-
sync = TableSync.new(session, 'scanner_records')
|
30
|
-
|
31
|
-
session.left.should_receive(:execute).with('dummy_command')
|
32
|
-
session.right.should_receive(:execute).with('dummy_command')
|
33
|
-
|
34
|
-
sync.execute_sync_hook(:before_table_sync)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "execute_sync_hook should execute the given Proc" do
|
38
|
-
config = deep_copy(standard_config)
|
39
|
-
received_handler = nil
|
40
|
-
config.add_table_options 'scanner_records',
|
41
|
-
:before_table_sync => lambda {|helper| received_handler = helper}
|
42
|
-
session = Session.new config
|
43
|
-
sync = TableSync.new(session, 'scanner_records')
|
44
|
-
sync.helper = :dummy_helper
|
45
|
-
|
46
|
-
sync.execute_sync_hook(:before_table_sync)
|
47
|
-
|
48
|
-
received_handler.should == :dummy_helper
|
49
|
-
end
|
50
|
-
|
51
|
-
it "event_filtered? should return false if there is no event filter" do
|
52
|
-
session = Session.new standard_config
|
53
|
-
sync = TableSync.new(session, 'scanner_records')
|
54
|
-
|
55
|
-
sync.event_filtered?(:left, 'id' => 1).should be_false
|
56
|
-
end
|
57
|
-
|
58
|
-
it "event_filtered? should return false if event filter does not filter sync events" do
|
59
|
-
config = deep_copy(standard_config)
|
60
|
-
config.add_table_options 'scanner_records', :event_filter => Object.new
|
61
|
-
session = Session.new config
|
62
|
-
sync = TableSync.new(session, 'scanner_records')
|
63
|
-
|
64
|
-
sync.event_filtered?(:left, 'id' => 1).should be_false
|
65
|
-
end
|
66
|
-
|
67
|
-
it "event_filtered? should signal filtering (i. e. return true) if the event filter result is false" do
|
68
|
-
filter = Object.new
|
69
|
-
def filter.before_sync(table, key, helper, type, row)
|
70
|
-
false
|
71
|
-
end
|
72
|
-
config = deep_copy(standard_config)
|
73
|
-
config.add_table_options 'scanner_records', :event_filter => filter
|
74
|
-
session = Session.new config
|
75
|
-
sync = TableSync.new(session, 'scanner_records')
|
76
|
-
sync.helper = SyncHelper.new(sync)
|
77
|
-
sync.event_filtered?(:left, 'id' => 1).should be_true
|
78
|
-
end
|
79
|
-
|
80
|
-
it "event_filtered? should return false if the event filter result is true" do
|
81
|
-
filter = {}
|
82
|
-
def filter.before_sync(table, key, helper, type, row)
|
83
|
-
self[:args] = [table, key, helper, type, row]
|
84
|
-
true
|
85
|
-
end
|
86
|
-
config = deep_copy(standard_config)
|
87
|
-
config.add_table_options 'scanner_records', :event_filter => filter
|
88
|
-
session = Session.new config
|
89
|
-
sync = TableSync.new(session, 'scanner_records')
|
90
|
-
sync.helper = SyncHelper.new(sync)
|
91
|
-
sync.event_filtered?(:left, 'id' => 1, 'name' => 'bla').should be_false
|
92
|
-
|
93
|
-
# verify correct parameter assignment
|
94
|
-
filter[:args].should == ['scanner_records', {'id' => 1}, sync.helper, :left, {'id' => 1, 'name' => 'bla'}]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "run should synchronize the databases" do
|
98
|
-
config = deep_copy(standard_config)
|
99
|
-
config.options[:committer] = :never_commit
|
100
|
-
config.options[:logged_sync_events] = [:all_conflicts]
|
101
|
-
before_hook_called = false
|
102
|
-
after_hook_called = false
|
103
|
-
config.options[:before_table_sync] = lambda {|helper| before_hook_called = true}
|
104
|
-
config.options[:after_table_sync] = lambda { |helper| after_hook_called = true}
|
105
|
-
|
106
|
-
filter = Object.new
|
107
|
-
def filter.before_sync(table, key, helper, type, row)
|
108
|
-
key['id'] != 6
|
109
|
-
end
|
110
|
-
config.options[:event_filter] = filter
|
111
|
-
session = Session.new(config)
|
112
|
-
begin
|
113
|
-
sync = TableSync.new(session, 'scanner_records')
|
114
|
-
sync.run
|
115
|
-
|
116
|
-
# Verify that sync events are logged
|
117
|
-
row = session.left.select_one("select * from rr_logged_events where change_key = '2' order by id")
|
118
|
-
row['change_table'].should == 'scanner_records'
|
119
|
-
row['diff_type'].should == 'conflict'
|
120
|
-
row['description'].should == 'left_wins'
|
121
|
-
|
122
|
-
# verify that the table was synchronized
|
123
|
-
left_records = session.left.select_all("select * from scanner_records where id <> 6 order by id")
|
124
|
-
right_records = session.right.select_all("select * from scanner_records where id <> 6 order by id")
|
125
|
-
left_records.should == right_records
|
126
|
-
|
127
|
-
# verify that the filtered out record was not synced
|
128
|
-
session.left.select_one("select * from scanner_records where id = 6").
|
129
|
-
should be_nil
|
130
|
-
|
131
|
-
# verify that hooks where called
|
132
|
-
before_hook_called.should be_true
|
133
|
-
after_hook_called.should be_true
|
134
|
-
ensure
|
135
|
-
Committers::NeverCommitter.rollback_current_session
|
136
|
-
session.left.execute "delete from rr_logged_events"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
data/spec/task_sweeper_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TaskSweeper do
|
6
|
-
before(:each) do
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should execute the given task" do
|
10
|
-
x = nil
|
11
|
-
TaskSweeper.timeout(1) {|sweeper| x = 1}
|
12
|
-
x.should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should raise exceptions thrown by the task" do
|
16
|
-
lambda {
|
17
|
-
TaskSweeper.timeout(1) {raise "bla"}
|
18
|
-
}.should raise_error("bla")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should return if task stalls" do
|
22
|
-
start = Time.now
|
23
|
-
TaskSweeper.timeout(0.01) {sleep 10}.should be_terminated
|
24
|
-
(Time.now - start < 5).should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should not return if task is active" do
|
28
|
-
start = Time.now
|
29
|
-
TaskSweeper.timeout(0.1) do |sweeper|
|
30
|
-
10.times do
|
31
|
-
sleep 0.05
|
32
|
-
sweeper.ping
|
33
|
-
end
|
34
|
-
end.should_not be_terminated
|
35
|
-
(Time.now - start > 0.4).should be_true
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should notify a stalled task about it's termination" do
|
40
|
-
terminated = false
|
41
|
-
TaskSweeper.timeout(0.01) do |sweeper|
|
42
|
-
sleep 0.05
|
43
|
-
terminated = sweeper.terminated?
|
44
|
-
end.join
|
45
|
-
terminated.should be_true
|
46
|
-
end
|
47
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe TriggerModeSwitcher do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = standard_config
|
8
|
-
end
|
9
|
-
|
10
|
-
it "initialize should save the session and initialize triggers hash" do
|
11
|
-
session = Session.new
|
12
|
-
switcher = TriggerModeSwitcher.new(session)
|
13
|
-
switcher.session.should == session
|
14
|
-
end
|
15
|
-
|
16
|
-
it "exclude_rr_activity should switch the trigger for the given table" do
|
17
|
-
switcher = TriggerModeSwitcher.new(Session.new)
|
18
|
-
|
19
|
-
switcher.should_receive(:switch_trigger_mode).with(:right, 'right1', true).once
|
20
|
-
switcher.exclude_rr_activity(:right, 'right1')
|
21
|
-
|
22
|
-
# Verify that for a given table, the trigger is not modified multiple times
|
23
|
-
switcher.exclude_rr_activity(:right, 'right1')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "restore_triggers should restore the triggers" do
|
27
|
-
switcher = TriggerModeSwitcher.new(Session.new)
|
28
|
-
|
29
|
-
switcher.stub!(:switch_trigger_mode)
|
30
|
-
switcher.exclude_rr_activity :left, 'left1'
|
31
|
-
switcher.should_receive(:switch_trigger_mode).with(:left, 'left1', false).once
|
32
|
-
switcher.restore_triggers
|
33
|
-
switcher.restore_triggers # ensure the restore is only done once
|
34
|
-
end
|
35
|
-
|
36
|
-
it "switch_trigger_mode should switch the exclude_rr_activity mode as specified" do
|
37
|
-
session = nil
|
38
|
-
initializer = nil
|
39
|
-
begin
|
40
|
-
session = Session.new
|
41
|
-
initializer = ReplicationInitializer.new(session)
|
42
|
-
initializer.create_trigger(:left, 'trigger_test')
|
43
|
-
|
44
|
-
switcher = TriggerModeSwitcher.new session
|
45
|
-
switcher.switch_trigger_mode :left, 'trigger_test', true
|
46
|
-
|
47
|
-
session.left.insert_record 'trigger_test', {
|
48
|
-
'first_id' => 1,
|
49
|
-
'second_id' => 2,
|
50
|
-
'name' => 'blub'
|
51
|
-
}
|
52
|
-
session.left.execute "insert into rr_running_flags values(1)"
|
53
|
-
session.left.insert_record 'trigger_test', {
|
54
|
-
'first_id' => 1,
|
55
|
-
'second_id' => 3,
|
56
|
-
'name' => 'bla'
|
57
|
-
}
|
58
|
-
|
59
|
-
rows = session.left.select_all("select * from rr_pending_changes order by id")
|
60
|
-
rows.each {|row| row.delete 'id'; row.delete 'change_time'}
|
61
|
-
rows.should == [{
|
62
|
-
'change_table' => 'trigger_test',
|
63
|
-
'change_key' => 'first_id|1|second_id|2',
|
64
|
-
'change_new_key' => nil,
|
65
|
-
'change_type' => 'I'
|
66
|
-
}]
|
67
|
-
ensure
|
68
|
-
initializer.drop_trigger :left, 'trigger_test' if initializer
|
69
|
-
if session
|
70
|
-
session.left.execute 'delete from rr_running_flags'
|
71
|
-
session.left.execute 'delete from trigger_test'
|
72
|
-
session.left.execute 'delete from rr_pending_changes'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it "switch_trigger_mode should not switch the trigger mode if the table has no trigger" do
|
78
|
-
session = Session.new
|
79
|
-
switcher = TriggerModeSwitcher.new session
|
80
|
-
session.left.should_not_receive(:execute)
|
81
|
-
switcher.switch_trigger_mode(:left, 'scanner_records', true)
|
82
|
-
end
|
83
|
-
end
|