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
@@ -1,274 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe Committers::BufferedCommitter do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = standard_config
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should register itself" do
|
11
|
-
Committers.committers[:buffered_commit].should == Committers::BufferedCommitter
|
12
|
-
end
|
13
|
-
|
14
|
-
# Stubs out the starting of transactions in the given Session.
|
15
|
-
def stub_begin_transaction(session)
|
16
|
-
session.left.stub! :begin_db_transaction
|
17
|
-
session.right.stub! :begin_db_transaction
|
18
|
-
end
|
19
|
-
|
20
|
-
# Stubs out the executing of SQL statements for the given Session.
|
21
|
-
def stub_execute(session)
|
22
|
-
session.left.stub! :execute
|
23
|
-
session.right.stub! :execute
|
24
|
-
end
|
25
|
-
|
26
|
-
it "trigger_mode_switcher should return and if necessary create the trigger mode switcher" do
|
27
|
-
session = Session.new
|
28
|
-
stub_begin_transaction session
|
29
|
-
stub_execute session
|
30
|
-
committer = Committers::BufferedCommitter.new(session)
|
31
|
-
switcher = committer.trigger_mode_switcher
|
32
|
-
switcher.should be_an_instance_of(TriggerModeSwitcher)
|
33
|
-
|
34
|
-
committer.trigger_mode_switcher.should == switcher # ensure it is only created one
|
35
|
-
end
|
36
|
-
|
37
|
-
it "exclude_rr_activity should exclude the rubyrep activity for the specified table" do
|
38
|
-
session = Session.new
|
39
|
-
stub_begin_transaction session
|
40
|
-
stub_execute session
|
41
|
-
committer = Committers::BufferedCommitter.new(session)
|
42
|
-
committer.trigger_mode_switcher.should_receive(:exclude_rr_activity).with(:left, 'dummy_table')
|
43
|
-
committer.exclude_rr_activity :left, 'dummy_table'
|
44
|
-
end
|
45
|
-
|
46
|
-
it "activity_marker_table should return the correct table name" do
|
47
|
-
config = deep_copy(standard_config)
|
48
|
-
config.options[:rep_prefix] = 'rx'
|
49
|
-
session = Session.new config
|
50
|
-
stub_begin_transaction session
|
51
|
-
stub_execute session
|
52
|
-
committer = Committers::BufferedCommitter.new(session)
|
53
|
-
committer.activity_marker_table.should == 'rx_running_flags'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "maintain_activity_status should return true if activity marker table exists" do
|
57
|
-
session = Session.new
|
58
|
-
stub_begin_transaction session
|
59
|
-
stub_execute session
|
60
|
-
committer = Committers::BufferedCommitter.new(session)
|
61
|
-
committer.maintain_activity_status?.should be_true
|
62
|
-
end
|
63
|
-
|
64
|
-
it "maintain_activity_status should return false if activity marker does not exist" do
|
65
|
-
config = deep_copy(standard_config)
|
66
|
-
config.options[:rep_prefix] = 'rx'
|
67
|
-
session = Session.new config
|
68
|
-
stub_begin_transaction session
|
69
|
-
stub_execute session
|
70
|
-
committer = Committers::BufferedCommitter.new(session)
|
71
|
-
committer.maintain_activity_status?.should be_false
|
72
|
-
end
|
73
|
-
|
74
|
-
it "commit_frequency should return the configured commit frequency" do
|
75
|
-
config = deep_copy(standard_config)
|
76
|
-
config.options[:commit_frequency] = 5
|
77
|
-
session = Session.new config
|
78
|
-
stub_begin_transaction session
|
79
|
-
stub_execute session
|
80
|
-
committer = Committers::BufferedCommitter.new(session)
|
81
|
-
committer.commit_frequency.should == 5
|
82
|
-
end
|
83
|
-
|
84
|
-
it "commit_frequency should return the the default commit frequency if nothing else is configured" do
|
85
|
-
config = deep_copy(standard_config)
|
86
|
-
config.options.delete :commit_frequency
|
87
|
-
session = Session.new config
|
88
|
-
stub_begin_transaction session
|
89
|
-
stub_execute session
|
90
|
-
committer = Committers::BufferedCommitter.new(session)
|
91
|
-
committer.commit_frequency.should == Committers::BufferedCommitter::DEFAULT_COMMIT_FREQUENCY
|
92
|
-
end
|
93
|
-
|
94
|
-
it "initialize should start transactions and setup rubyrep activity filtering" do
|
95
|
-
session = nil
|
96
|
-
begin
|
97
|
-
session = Session.new
|
98
|
-
session.left.should_receive(:begin_db_transaction)
|
99
|
-
session.right.should_receive(:begin_db_transaction)
|
100
|
-
session.left.select_one("select * from rr_running_flags").should be_nil # verify starting situation
|
101
|
-
committer = Committers::BufferedCommitter.new(session)
|
102
|
-
|
103
|
-
# rubyrep activity should be marked
|
104
|
-
session.left.select_one("select * from rr_running_flags").should_not be_nil
|
105
|
-
session.right.select_one("select * from rr_running_flags").should_not be_nil
|
106
|
-
ensure
|
107
|
-
session.left.execute "delete from rr_running_flags" if session
|
108
|
-
session.right.execute "delete from rr_running_flags" if session
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "commit_db_transactions should commit the transactions in both databases" do
|
113
|
-
session = Session.new
|
114
|
-
stub_begin_transaction session
|
115
|
-
stub_execute session
|
116
|
-
committer = Committers::BufferedCommitter.new(session)
|
117
|
-
|
118
|
-
session.left.should_receive(:commit_db_transaction)
|
119
|
-
session.right.should_receive(:commit_db_transaction)
|
120
|
-
committer.commit_db_transactions
|
121
|
-
end
|
122
|
-
|
123
|
-
it "commit_db_transactions should clear the activity marker table" do
|
124
|
-
session = Session.new
|
125
|
-
stub_begin_transaction session
|
126
|
-
session.left.stub!(:commit_db_transaction)
|
127
|
-
session.right.stub!(:commit_db_transaction)
|
128
|
-
stub_execute session
|
129
|
-
committer = Committers::BufferedCommitter.new(session)
|
130
|
-
|
131
|
-
session.left.should_receive(:execute).with("delete from rr_running_flags")
|
132
|
-
session.right.should_receive(:execute).with("delete from rr_running_flags")
|
133
|
-
committer.commit_db_transactions
|
134
|
-
end
|
135
|
-
|
136
|
-
it "commit_db_transactions should not clear the activity marker table if it doesn't exist" do
|
137
|
-
config = deep_copy(standard_config)
|
138
|
-
config.options[:rep_prefix] = 'rx'
|
139
|
-
session = Session.new config
|
140
|
-
stub_begin_transaction session
|
141
|
-
session.left.stub!(:commit_db_transaction)
|
142
|
-
session.right.stub!(:commit_db_transaction)
|
143
|
-
stub_execute session
|
144
|
-
committer = Committers::BufferedCommitter.new(session)
|
145
|
-
|
146
|
-
session.left.should_not_receive(:execute)
|
147
|
-
session.right.should_not_receive(:execute)
|
148
|
-
committer.commit_db_transactions
|
149
|
-
end
|
150
|
-
|
151
|
-
it "begin_db_transactions should begin new transactions in both databases" do
|
152
|
-
session = Session.new
|
153
|
-
stub_begin_transaction session
|
154
|
-
stub_execute session
|
155
|
-
committer = Committers::BufferedCommitter.new(session)
|
156
|
-
|
157
|
-
session.left.should_receive(:begin_db_transaction)
|
158
|
-
session.right.should_receive(:begin_db_transaction)
|
159
|
-
committer.begin_db_transactions
|
160
|
-
end
|
161
|
-
|
162
|
-
it "begin_db_transactions should insert a record into the activity marker table" do
|
163
|
-
session = Session.new
|
164
|
-
stub_begin_transaction session
|
165
|
-
stub_execute session
|
166
|
-
committer = Committers::BufferedCommitter.new(session)
|
167
|
-
|
168
|
-
session.left.should_receive(:execute).with("insert into rr_running_flags values(1)")
|
169
|
-
session.right.should_receive(:execute).with("insert into rr_running_flags values(1)")
|
170
|
-
committer.begin_db_transactions
|
171
|
-
end
|
172
|
-
|
173
|
-
it "begin_db_transactions should not clear the activity marker table if it doesn't exist" do
|
174
|
-
config = deep_copy(standard_config)
|
175
|
-
config.options[:rep_prefix] = 'rx'
|
176
|
-
session = Session.new config
|
177
|
-
stub_begin_transaction session
|
178
|
-
stub_execute session
|
179
|
-
committer = Committers::BufferedCommitter.new(session)
|
180
|
-
|
181
|
-
session.left.should_not_receive(:execute)
|
182
|
-
session.right.should_not_receive(:execute)
|
183
|
-
committer.begin_db_transactions
|
184
|
-
end
|
185
|
-
|
186
|
-
it "rollback_db_transactions should roll back the transactions in both databases" do
|
187
|
-
session = Session.new
|
188
|
-
stub_begin_transaction session
|
189
|
-
stub_execute session
|
190
|
-
committer = Committers::BufferedCommitter.new(session)
|
191
|
-
|
192
|
-
session.left.should_receive(:rollback_db_transaction)
|
193
|
-
session.right.should_receive(:rollback_db_transaction)
|
194
|
-
committer.rollback_db_transactions
|
195
|
-
end
|
196
|
-
|
197
|
-
it "commit should only commit and start new transactions if the specified number of changes have been executed" do
|
198
|
-
config = deep_copy(standard_config)
|
199
|
-
config.options[:commit_frequency] = 2
|
200
|
-
session = Session.new config
|
201
|
-
stub_begin_transaction session
|
202
|
-
stub_execute session
|
203
|
-
committer = Committers::BufferedCommitter.new(session)
|
204
|
-
|
205
|
-
committer.should_receive(:commit_db_transactions).twice
|
206
|
-
committer.should_receive(:begin_db_transactions).twice
|
207
|
-
committer.commit
|
208
|
-
committer.new_transaction?.should be_false
|
209
|
-
3.times {committer.commit}
|
210
|
-
committer.new_transaction?.should be_true
|
211
|
-
end
|
212
|
-
|
213
|
-
it "insert_record should commit" do
|
214
|
-
session = Session.new
|
215
|
-
stub_begin_transaction session
|
216
|
-
stub_execute session
|
217
|
-
committer = Committers::BufferedCommitter.new(session)
|
218
|
-
|
219
|
-
committer.should_receive(:exclude_rr_activity).with(:right, 'right_table').ordered
|
220
|
-
session.right.should_receive(:insert_record).with('right_table', :dummy_values).ordered
|
221
|
-
committer.should_receive(:commit).ordered
|
222
|
-
|
223
|
-
committer.insert_record(:right, 'right_table', :dummy_values)
|
224
|
-
end
|
225
|
-
|
226
|
-
it "update_record should commit" do
|
227
|
-
session = Session.new
|
228
|
-
stub_begin_transaction session
|
229
|
-
stub_execute session
|
230
|
-
committer = Committers::BufferedCommitter.new(session)
|
231
|
-
|
232
|
-
committer.should_receive(:exclude_rr_activity).with(:right, 'right_table').ordered
|
233
|
-
session.right.should_receive(:update_record).with('right_table', :dummy_values, :dummy_org_key).ordered
|
234
|
-
committer.should_receive(:commit).ordered
|
235
|
-
|
236
|
-
committer.update_record(:right, 'right_table', :dummy_values, :dummy_org_key)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "delete_record should commit" do
|
240
|
-
session = Session.new
|
241
|
-
stub_begin_transaction session
|
242
|
-
stub_execute session
|
243
|
-
committer = Committers::BufferedCommitter.new(session)
|
244
|
-
|
245
|
-
committer.should_receive(:exclude_rr_activity).with(:right, 'right_table').ordered
|
246
|
-
session.right.should_receive(:delete_record).with('right_table', :dummy_values).ordered
|
247
|
-
committer.should_receive(:commit).ordered
|
248
|
-
|
249
|
-
committer.delete_record(:right, 'right_table', :dummy_values)
|
250
|
-
end
|
251
|
-
|
252
|
-
it "finalize should commit the transactions if called with success = true" do
|
253
|
-
session = Session.new
|
254
|
-
stub_begin_transaction session
|
255
|
-
stub_execute session
|
256
|
-
committer = Committers::BufferedCommitter.new(session)
|
257
|
-
|
258
|
-
committer.should_receive(:commit_db_transactions)
|
259
|
-
|
260
|
-
committer.finalize true
|
261
|
-
end
|
262
|
-
|
263
|
-
it "finalize should rollbackup the transactions if called with success = false" do
|
264
|
-
session = Session.new
|
265
|
-
stub_begin_transaction session
|
266
|
-
stub_execute session
|
267
|
-
committer = Committers::BufferedCommitter.new(session)
|
268
|
-
|
269
|
-
committer.should_receive(:rollback_db_transactions)
|
270
|
-
|
271
|
-
committer.finalize false
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
data/spec/command_runner_spec.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe CommandRunner do
|
6
|
-
before(:each) do
|
7
|
-
@org_commands = CommandRunner.commands
|
8
|
-
CommandRunner.instance_variable_set :@commands, nil
|
9
|
-
end
|
10
|
-
|
11
|
-
after(:each) do
|
12
|
-
CommandRunner.instance_variable_set :@commands, @org_commands
|
13
|
-
end
|
14
|
-
|
15
|
-
it "show_version should print the version string" do
|
16
|
-
$stdout.should_receive(:puts).with(/rubyrep version ([0-9]+\.){2}[0-9]+/)
|
17
|
-
CommandRunner.show_version
|
18
|
-
end
|
19
|
-
|
20
|
-
it "register should register commands, commands should return it" do
|
21
|
-
CommandRunner.register :bla => :bla_command
|
22
|
-
CommandRunner.register :blub => :blub_command
|
23
|
-
CommandRunner.commands.should == {
|
24
|
-
:bla => :bla_command,
|
25
|
-
:blub => :blub_command
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
it "run should print a short help if --help is specified" do
|
30
|
-
org_stderr = $stderr
|
31
|
-
$stderr = StringIO.new
|
32
|
-
begin
|
33
|
-
CommandRunner.register 'c1' => {:description => 'desc 1'}, 'c2' => {:description => 'desc 2'}
|
34
|
-
CommandRunner.run(['--help'])
|
35
|
-
$stderr.string.should =~ /Usage/
|
36
|
-
$stderr.string.should =~ /c1.*desc 1\n/
|
37
|
-
$stderr.string.should =~ /c2.*desc 2\n/
|
38
|
-
ensure
|
39
|
-
$stderr = org_stderr
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "run should print help if no command line parameters are given" do
|
44
|
-
org_stderr = $stderr
|
45
|
-
$stderr = StringIO.new
|
46
|
-
begin
|
47
|
-
CommandRunner.run([]).should == 1
|
48
|
-
$stderr.string.should =~ /Available commands/
|
49
|
-
ensure
|
50
|
-
$stderr = org_stderr
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "run should print help if --help or help without further params is given" do
|
55
|
-
org_stderr = $stderr
|
56
|
-
$stderr = StringIO.new
|
57
|
-
begin
|
58
|
-
CommandRunner.run(['--help']).should == 0
|
59
|
-
$stderr.string.should =~ /Available commands/
|
60
|
-
$stderr = StringIO.new
|
61
|
-
CommandRunner.run(['help']).should == 0
|
62
|
-
$stderr.string.should =~ /Available commands/
|
63
|
-
ensure
|
64
|
-
$stderr = org_stderr
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "run should print version if --version is given" do
|
69
|
-
CommandRunner.should_receive(:show_version)
|
70
|
-
CommandRunner.run(['--version'])
|
71
|
-
end
|
72
|
-
|
73
|
-
it "run should call the specified command with the specified params" do
|
74
|
-
c = mock('dummy_command')
|
75
|
-
c.should_receive(:run).with(['param1', 'param2'])
|
76
|
-
CommandRunner.register 'dummy_command' => {:command => c}
|
77
|
-
CommandRunner.run(['dummy_command', 'param1', 'param2'])
|
78
|
-
end
|
79
|
-
|
80
|
-
it "run should print help if unknown command is given" do
|
81
|
-
org_stderr = $stderr
|
82
|
-
$stderr = StringIO.new
|
83
|
-
begin
|
84
|
-
CommandRunner.run('non-existing-command').should == 1
|
85
|
-
$stderr.string.should =~ /Available commands/
|
86
|
-
ensure
|
87
|
-
$stderr = org_stderr
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "run should print stacktrace if --verbose option is given" do
|
92
|
-
org_stderr = $stderr
|
93
|
-
$stderr = StringIO.new
|
94
|
-
begin
|
95
|
-
c = mock('dummy_command')
|
96
|
-
c.stub!(:run).and_return {raise 'bla'}
|
97
|
-
CommandRunner.register 'dummy_command' => {:command => c}
|
98
|
-
CommandRunner.run(['--verbose', 'dummy_command', '-c', 'non_existing_file']).should == 1
|
99
|
-
$stderr.string.should =~ /Exception caught/
|
100
|
-
$stderr.string.should =~ /command_runner.rb:[0-9]+:in /
|
101
|
-
|
102
|
-
# also verify that no stacktrace is printed if --verbose is not specified
|
103
|
-
$stderr = StringIO.new
|
104
|
-
CommandRunner.run(['dummy_command', '-c', 'non_existing_file']).should == 1
|
105
|
-
$stderr.string.should =~ /Exception caught/
|
106
|
-
$stderr.string.should_not =~ /command_runner.rb:[0-9]+:in /
|
107
|
-
ensure
|
108
|
-
$stderr = org_stderr
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "rubyrep should call CommandRunner#run" do
|
113
|
-
CommandRunner.should_receive(:run).with(ARGV).and_return(0)
|
114
|
-
Kernel.any_instance_should_receive(:exit) {
|
115
|
-
load File.dirname(__FILE__) + '/../bin/rubyrep'
|
116
|
-
}
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe HelpRunner do
|
121
|
-
it "should register itself" do
|
122
|
-
CommandRunner.commands['help'][:command].should == HelpRunner
|
123
|
-
CommandRunner.commands['help'][:description].should be_an_instance_of(String)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "run should call help for the specified command" do
|
127
|
-
CommandRunner.should_receive(:run).with(['dummy_command', '--help'])
|
128
|
-
HelpRunner.run(['dummy_command'])
|
129
|
-
end
|
130
|
-
|
131
|
-
it "run should print help for itself if '--help' or 'help' is specified" do
|
132
|
-
org_stderr = $stderr
|
133
|
-
$stderr = StringIO.new
|
134
|
-
begin
|
135
|
-
HelpRunner.run(['--help'])
|
136
|
-
$stderr.string.should =~ /Shows the help for the specified command/
|
137
|
-
|
138
|
-
$stderr = StringIO.new
|
139
|
-
HelpRunner.run(['help'])
|
140
|
-
$stderr.string.should =~ /Shows the help for the specified command/
|
141
|
-
ensure
|
142
|
-
$stderr = org_stderr
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
data/spec/committers_spec.rb
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe Committers do
|
6
|
-
before(:each) do
|
7
|
-
@old_committers = Committers.committers
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:each) do
|
11
|
-
Committers.instance_variable_set :@committers, @old_committers
|
12
|
-
end
|
13
|
-
|
14
|
-
it "committers should return empty hash if nil" do
|
15
|
-
Committers.instance_variable_set :@committers, nil
|
16
|
-
Committers.committers.should == {}
|
17
|
-
end
|
18
|
-
|
19
|
-
it "committers should return the registered committers" do
|
20
|
-
Committers.instance_variable_set :@committers, :dummy_data
|
21
|
-
Committers.committers.should == :dummy_data
|
22
|
-
end
|
23
|
-
|
24
|
-
it "register should register the provided commiter" do
|
25
|
-
Committers.instance_variable_set :@committers, nil
|
26
|
-
Committers.register :a_key => :a
|
27
|
-
Committers.register :b_key => :b
|
28
|
-
Committers.committers[:a_key].should == :a
|
29
|
-
Committers.committers[:b_key].should == :b
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
describe "Committer", :shared => true do
|
35
|
-
it "should support the right constructor interface" do
|
36
|
-
session = mock("session")
|
37
|
-
session.should_receive(:left).any_number_of_times \
|
38
|
-
.and_return(mock("left connection", :null_object => true))
|
39
|
-
session.should_receive(:right).any_number_of_times \
|
40
|
-
.and_return(mock("right connection", :null_object => true))
|
41
|
-
@committer.class.new session
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should proxy insert_record, update_record and delete_record calls" do
|
45
|
-
left_connection = mock("left connection", :null_object => true)
|
46
|
-
left_connection.should_receive(:insert_record).with("left", :dummy_insert_values)
|
47
|
-
|
48
|
-
right_connection = mock("right connection", :null_object => true)
|
49
|
-
right_connection.should_receive(:update_record).with("right", :dummy_update_values, :dummy_org_key)
|
50
|
-
right_connection.should_receive(:delete_record).with("right", :dummy_delete_values)
|
51
|
-
|
52
|
-
session = mock("session")
|
53
|
-
session.should_receive(:left).any_number_of_times.and_return(left_connection)
|
54
|
-
session.should_receive(:right).any_number_of_times.and_return(right_connection)
|
55
|
-
|
56
|
-
committer = @committer.class.new session
|
57
|
-
|
58
|
-
committer.insert_record :left, 'left', :dummy_insert_values
|
59
|
-
committer.update_record :right, 'right', :dummy_update_values, :dummy_org_key
|
60
|
-
committer.delete_record :right, 'right', :dummy_delete_values
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should support finalize" do
|
64
|
-
@committer.finalize(false)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe Committers::DefaultCommitter do
|
69
|
-
before(:each) do
|
70
|
-
@session = mock("session")
|
71
|
-
@session.should_receive(:left).any_number_of_times.and_return(:left_connection)
|
72
|
-
@session.should_receive(:right).any_number_of_times.and_return(:right_connection)
|
73
|
-
@committer = Committers::DefaultCommitter.new @session
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should register itself" do
|
77
|
-
Committers.committers[:default].should == Committers::DefaultCommitter
|
78
|
-
end
|
79
|
-
|
80
|
-
it "initialize should store the provided parameters" do
|
81
|
-
@committer.session.should == @session
|
82
|
-
@committer.connections \
|
83
|
-
.should == {:left => @session.left, :right => @session.right}
|
84
|
-
end
|
85
|
-
|
86
|
-
it "new_transaction? should return false" do
|
87
|
-
@committer.new_transaction?.should be_false
|
88
|
-
end
|
89
|
-
|
90
|
-
it_should_behave_like "Committer"
|
91
|
-
end
|
92
|
-
|
93
|
-
describe Committers::NeverCommitter do
|
94
|
-
before(:each) do
|
95
|
-
@old_session = Committers::NeverCommitter.current_session
|
96
|
-
Committers::NeverCommitter.current_session = nil
|
97
|
-
@session = mock("session")
|
98
|
-
@session.should_receive(:left).any_number_of_times \
|
99
|
-
.and_return(mock("left connection", :null_object => true))
|
100
|
-
@session.should_receive(:right).any_number_of_times \
|
101
|
-
.and_return(mock("right connection", :null_object => true))
|
102
|
-
@committer = Committers::NeverCommitter.new @session
|
103
|
-
end
|
104
|
-
|
105
|
-
after(:each) do
|
106
|
-
Committers::NeverCommitter.current_session = @old_session
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should register itself" do
|
110
|
-
Committers.committers[:never_commit].should == Committers::NeverCommitter
|
111
|
-
end
|
112
|
-
|
113
|
-
it "initialize should store the provided parameters" do
|
114
|
-
@committer.session.should == @session
|
115
|
-
@committer.connections \
|
116
|
-
.should == {:left => @session.left, :right => @session.right}
|
117
|
-
end
|
118
|
-
|
119
|
-
it "initialize should rollback the previous current session and then register the new one as current session" do
|
120
|
-
old_session = mock("old session", :null_object => true)
|
121
|
-
new_session = mock("new session", :null_object => true)
|
122
|
-
Committers::NeverCommitter.current_session = old_session
|
123
|
-
Committers::NeverCommitter.should_receive(:rollback_current_session)
|
124
|
-
|
125
|
-
Committers::NeverCommitter.new new_session
|
126
|
-
Committers::NeverCommitter.current_session.should == new_session
|
127
|
-
end
|
128
|
-
|
129
|
-
it "initialize should start new transactions" do
|
130
|
-
# Ensure that initialize handles the case of no previous database session
|
131
|
-
# being present
|
132
|
-
Committers::NeverCommitter.current_session = nil
|
133
|
-
new_session = mock("new session")
|
134
|
-
|
135
|
-
left_connection = mock("left connection")
|
136
|
-
left_connection.should_receive :begin_db_transaction
|
137
|
-
new_session.should_receive(:left).any_number_of_times.and_return(left_connection)
|
138
|
-
|
139
|
-
right_connection = mock("right connection")
|
140
|
-
right_connection.should_receive :begin_db_transaction
|
141
|
-
new_session.should_receive(:right).any_number_of_times.and_return(right_connection)
|
142
|
-
|
143
|
-
@committer = Committers::NeverCommitter.new new_session
|
144
|
-
end
|
145
|
-
|
146
|
-
it "rollback_current_session should rollback current session" do
|
147
|
-
old_session = mock("old session")
|
148
|
-
|
149
|
-
left_connection = mock("left connection")
|
150
|
-
left_connection.should_receive :rollback_db_transaction
|
151
|
-
old_session.should_receive(:left).and_return(left_connection)
|
152
|
-
|
153
|
-
right_connection = mock("right connection")
|
154
|
-
right_connection.should_receive :rollback_db_transaction
|
155
|
-
old_session.should_receive(:right).and_return(right_connection)
|
156
|
-
|
157
|
-
Committers::NeverCommitter.current_session = old_session
|
158
|
-
Committers::NeverCommitter.rollback_current_session
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should work will real sessions" do
|
162
|
-
session = Session.new(standard_config)
|
163
|
-
Committers::NeverCommitter.new session
|
164
|
-
Committers::NeverCommitter.new session
|
165
|
-
Committers::NeverCommitter.rollback_current_session
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should work will real proxied sessions" do
|
169
|
-
ensure_proxy
|
170
|
-
session = Session.new(proxied_config)
|
171
|
-
Committers::NeverCommitter.new session
|
172
|
-
Committers::NeverCommitter.new session
|
173
|
-
Committers::NeverCommitter.rollback_current_session
|
174
|
-
end
|
175
|
-
|
176
|
-
it_should_behave_like "Committer"
|
177
|
-
|
178
|
-
end
|