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,423 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe ProxyConnection do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = proxied_config
|
8
|
-
@connection = ProxyConnection.new Initializer.configuration.left
|
9
|
-
end
|
10
|
-
|
11
|
-
it "initialize should connect to the database" do
|
12
|
-
(!!@connection.connection.active?).should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it "initialize should store the configuratin" do
|
16
|
-
@connection.config.should == Initializer.configuration.left
|
17
|
-
end
|
18
|
-
|
19
|
-
it "destroy should disconnect from the database" do
|
20
|
-
if ActiveSupport.const_defined?(:Notifications)
|
21
|
-
ConnectionExtenders::install_logger @connection.connection, :logger => StringIO.new
|
22
|
-
log_subscriber = @connection.connection.log_subscriber
|
23
|
-
|
24
|
-
ActiveSupport::Notifications.notifier.listeners_for("sql.active_record").should include(log_subscriber)
|
25
|
-
end
|
26
|
-
|
27
|
-
@connection.destroy
|
28
|
-
|
29
|
-
if ActiveSupport.const_defined?(:Notifications)
|
30
|
-
ActiveSupport::Notifications.notifier.listeners_for("sql.active_record").should_not include(log_subscriber)
|
31
|
-
@connection.connection.log_subscriber.should be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
(!!@connection.connection.active?).should == false
|
35
|
-
end
|
36
|
-
|
37
|
-
it "cursors should return the current cursor hash or an empty hash if nil" do
|
38
|
-
@connection.cursors.should == {}
|
39
|
-
@connection.cursors[:dummy_cursor] = :dummy_cursor
|
40
|
-
@connection.cursors.should == {:dummy_cursor => :dummy_cursor}
|
41
|
-
end
|
42
|
-
|
43
|
-
it "save_cursor should register the provided cursor" do
|
44
|
-
@connection.save_cursor :dummy_cursor
|
45
|
-
|
46
|
-
@connection.cursors[:dummy_cursor].should == :dummy_cursor
|
47
|
-
end
|
48
|
-
|
49
|
-
it "destroy should destroy and unregister any stored cursors" do
|
50
|
-
cursor = mock("Cursor")
|
51
|
-
cursor.should_receive(:destroy)
|
52
|
-
|
53
|
-
@connection.save_cursor cursor
|
54
|
-
@connection.destroy
|
55
|
-
|
56
|
-
@connection.cursors.should == {}
|
57
|
-
end
|
58
|
-
|
59
|
-
it "destroy_cursor should destroy and unregister the provided cursor" do
|
60
|
-
cursor = mock("Cursor")
|
61
|
-
cursor.should_receive(:destroy)
|
62
|
-
|
63
|
-
@connection.save_cursor cursor
|
64
|
-
@connection.destroy_cursor cursor
|
65
|
-
|
66
|
-
@connection.cursors.should == {}
|
67
|
-
end
|
68
|
-
|
69
|
-
it "create_cursor should create and register the cursor and initiate row fetching" do
|
70
|
-
cursor = @connection.create_cursor(
|
71
|
-
ProxyRowCursor,
|
72
|
-
'scanner_records',
|
73
|
-
:from => {'id' => 2},
|
74
|
-
:to => {'id' => 2}
|
75
|
-
)
|
76
|
-
|
77
|
-
cursor.should be_an_instance_of(ProxyRowCursor)
|
78
|
-
cursor.next_row_keys_and_checksum[0].should == {'id' => 2} # verify that 'from' range was used
|
79
|
-
cursor.next?.should be_false # verify that 'to' range was used
|
80
|
-
end
|
81
|
-
|
82
|
-
it "column_names should return the column names of the specified table" do
|
83
|
-
@connection.column_names('scanner_records').should == ['id', 'name']
|
84
|
-
end
|
85
|
-
|
86
|
-
it "column_names should cache the column names" do
|
87
|
-
@connection.column_names('scanner_records')
|
88
|
-
@connection.column_names('scanner_text_key')
|
89
|
-
@connection.connection.should_not_receive(:columns)
|
90
|
-
@connection.column_names('scanner_records').should == ['id', 'name']
|
91
|
-
end
|
92
|
-
|
93
|
-
it "primary_key_names should return the correct primary keys" do
|
94
|
-
@connection.primary_key_names('scanner_records').should == ['id']
|
95
|
-
end
|
96
|
-
|
97
|
-
it "primary_key_names should return the manual primary keys if they exist" do
|
98
|
-
@connection.stub!(:manual_primary_keys).
|
99
|
-
and_return({'scanner_records' => ['manual_key']})
|
100
|
-
@connection.primary_key_names('scanner_records').should == ['manual_key']
|
101
|
-
end
|
102
|
-
|
103
|
-
it "primary_key_names should not cache or manually overwrite if :raw option is given" do
|
104
|
-
@connection.stub!(:manual_primary_keys).
|
105
|
-
and_return({'scanner_records' => ['manual_key']})
|
106
|
-
key1 = @connection.primary_key_names('scanner_records', :raw => true)
|
107
|
-
key1.should == ['id']
|
108
|
-
|
109
|
-
key2 = @connection.primary_key_names('scanner_records', :raw => true)
|
110
|
-
key1.__id__.should_not == key2.__id__
|
111
|
-
end
|
112
|
-
|
113
|
-
it "primary_key_names should cache the primary primary keys" do
|
114
|
-
@connection.connection.should_receive(:primary_key_names) \
|
115
|
-
.with('dummy_table').once.and_return(['dummy_key'])
|
116
|
-
@connection.connection.should_receive(:primary_key_names) \
|
117
|
-
.with('dummy_table2').once.and_return(['dummy_key2'])
|
118
|
-
|
119
|
-
@connection.primary_key_names('dummy_table').should == ['dummy_key']
|
120
|
-
@connection.primary_key_names('dummy_table2').should == ['dummy_key2']
|
121
|
-
@connection.primary_key_names('dummy_table').should == ['dummy_key']
|
122
|
-
end
|
123
|
-
|
124
|
-
# Note:
|
125
|
-
# Additional select_cursor tests are executed via
|
126
|
-
# 'db_specific_connection_extenders_spec.rb'
|
127
|
-
# (To verify the behaviour for all supported databases)
|
128
|
-
|
129
|
-
it "select_cursor should return the result fetcher" do
|
130
|
-
fetcher = @connection.select_cursor(:table => 'scanner_records', :type_cast => false)
|
131
|
-
fetcher.connection.should == @connection
|
132
|
-
fetcher.options.should == {:table => 'scanner_records', :type_cast => false}
|
133
|
-
end
|
134
|
-
|
135
|
-
it "select_cursor should return a type casting cursor if :type_cast option is specified" do
|
136
|
-
fetcher = @connection.select_cursor(:table => 'scanner_records', :type_cast => true)
|
137
|
-
fetcher.should be_an_instance_of(TypeCastingCursor)
|
138
|
-
end
|
139
|
-
|
140
|
-
it "table_select_query should handle queries without any conditions" do
|
141
|
-
@connection.table_select_query('scanner_records') \
|
142
|
-
.should =~ sql_to_regexp("\
|
143
|
-
select 'id', 'name' from 'scanner_records'\
|
144
|
-
order by 'id'")
|
145
|
-
end
|
146
|
-
|
147
|
-
it "table_select_query should handle queries with only a from condition" do
|
148
|
-
@connection.table_select_query('scanner_records', :from => {'id' => 1}) \
|
149
|
-
.should =~ sql_to_regexp("\
|
150
|
-
select 'id', 'name' from 'scanner_records' \
|
151
|
-
where ('id') >= (1) order by 'id'")
|
152
|
-
end
|
153
|
-
|
154
|
-
it "table_select_query should handle queries with an exclusive from condition" do
|
155
|
-
@connection.table_select_query(
|
156
|
-
'scanner_records',
|
157
|
-
:from => {'id' => 1},
|
158
|
-
:exclude_starting_row => true
|
159
|
-
).should =~ sql_to_regexp("\
|
160
|
-
select 'id', 'name' from 'scanner_records' \
|
161
|
-
where ('id') > (1) order by 'id'")
|
162
|
-
end
|
163
|
-
|
164
|
-
it "table_select_query should handle queries with only a to condition" do
|
165
|
-
@connection.table_select_query('scanner_text_key', :to => {'text_id' => 'k1'}) \
|
166
|
-
.should =~ sql_to_regexp("\
|
167
|
-
select 'text_id', 'name' from 'scanner_text_key' \
|
168
|
-
where ('text_id') <= ('k1') order by 'text_id'")
|
169
|
-
end
|
170
|
-
|
171
|
-
it "table_select_query should handle queries with both from and to conditions" do
|
172
|
-
@connection.table_select_query('scanner_records',
|
173
|
-
:from => {'id' => 0}, :to => {'id' => 1}) \
|
174
|
-
.should =~ sql_to_regexp("\
|
175
|
-
select 'id', 'name' from 'scanner_records' \
|
176
|
-
where ('id') >= (0) and ('id') <= (1) order by 'id'")
|
177
|
-
end
|
178
|
-
|
179
|
-
it "table_select_query should handle queries for specific rows" do
|
180
|
-
@connection.table_select_query('scanner_records',
|
181
|
-
:row_keys => [{'id' => 0}, {'id' => 1}]) \
|
182
|
-
.should =~ sql_to_regexp("\
|
183
|
-
select 'id', 'name' from 'scanner_records' \
|
184
|
-
where ('id') in ((0), (1)) order by 'id'")
|
185
|
-
end
|
186
|
-
|
187
|
-
it "table_select_query should handle queries for specific rows with the row array actually being empty" do
|
188
|
-
@connection.table_select_query('scanner_records', :row_keys => []) \
|
189
|
-
.should =~ sql_to_regexp("\
|
190
|
-
select 'id', 'name' from 'scanner_records' \
|
191
|
-
where false order by 'id'")
|
192
|
-
end
|
193
|
-
|
194
|
-
it "table_select_query should handle queries for specific rows in combination with other conditions" do
|
195
|
-
@connection.table_select_query('scanner_records',
|
196
|
-
:from => {'id' => 0},
|
197
|
-
:row_keys => [{'id' => 1}, {'id' => 2}]) \
|
198
|
-
.should =~ sql_to_regexp("\
|
199
|
-
select 'id', 'name' from 'scanner_records' \
|
200
|
-
where ('id') >= (0) and ('id') in ((1), (2)) order by 'id'")
|
201
|
-
end
|
202
|
-
|
203
|
-
it "table_select_query should handle tables with combined primary keys" do
|
204
|
-
@connection.table_select_query('extender_combined_key',
|
205
|
-
:from => {'first_id' => 0, 'second_id' => 1},
|
206
|
-
:to => {'first_id' => 2, 'second_id' => 3}) \
|
207
|
-
.should =~ sql_to_regexp("\
|
208
|
-
select 'first_id', 'second_id', 'name' from 'extender_combined_key' \
|
209
|
-
where ('first_id', 'second_id') >= (0, 1) \
|
210
|
-
and ('first_id', 'second_id') <= (2, 3) \
|
211
|
-
order by 'first_id', 'second_id'")
|
212
|
-
end
|
213
|
-
|
214
|
-
it "table_select_query should quote column values" do
|
215
|
-
select_options = {:from => {'text_id' => 'a'}, :to => {'text_id' => 'b'}}
|
216
|
-
|
217
|
-
@connection.table_select_query('scanner_text_key', select_options) \
|
218
|
-
.should match(/'a'.*'b'/)
|
219
|
-
|
220
|
-
# additional check that the quoted query actually works
|
221
|
-
cursor = ProxyCursor.new(@connection, 'scanner_text_key')
|
222
|
-
results = cursor.prepare_fetch(select_options)
|
223
|
-
results.next_row.should == {'text_id' => 'a', 'name' => 'Alice'}
|
224
|
-
results.next_row.should == {'text_id' => 'b', 'name' => 'Bob'}
|
225
|
-
results.next?.should be_false
|
226
|
-
end
|
227
|
-
|
228
|
-
it "table_insert_query should return the correct SQL query" do
|
229
|
-
@connection.table_insert_query('scanner_records', 'name' => 'bla') \
|
230
|
-
.should =~ sql_to_regexp(%q!insert into "scanner_records"("name") values("bla")!)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "insert_record should insert the specified record" do
|
234
|
-
@connection.begin_db_transaction
|
235
|
-
begin
|
236
|
-
@connection.insert_record('scanner_records', 'id' => 9, 'name' => 'bla')
|
237
|
-
@connection.select_record(
|
238
|
-
:table => 'scanner_records',
|
239
|
-
:row_keys => ['id' => 9]
|
240
|
-
).should == {'id' => 9, 'name' => 'bla'}
|
241
|
-
ensure
|
242
|
-
@connection.rollback_db_transaction
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
it "insert_record should handle combined primary keys" do
|
247
|
-
@connection.begin_db_transaction
|
248
|
-
begin
|
249
|
-
@connection.insert_record('extender_combined_key', 'first_id' => 8, 'second_id' => '9')
|
250
|
-
@connection.select_record(
|
251
|
-
:table => 'extender_combined_key',
|
252
|
-
:row_keys => ['first_id' => 8, 'second_id' => 9]
|
253
|
-
).should == {'first_id' => 8, 'second_id' => 9, 'name' => nil}
|
254
|
-
ensure
|
255
|
-
@connection.rollback_db_transaction
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
it "insert_record should write nil values correctly" do
|
260
|
-
@connection.begin_db_transaction
|
261
|
-
begin
|
262
|
-
@connection.insert_record('extender_combined_key', 'first_id' => 8, 'second_id' => '9', 'name' => nil)
|
263
|
-
@connection.select_record(
|
264
|
-
:table => 'extender_combined_key',
|
265
|
-
:row_keys => ['first_id' => 8, 'second_id' => 9]
|
266
|
-
).should == {'first_id' => 8, 'second_id' => 9, "name" => nil}
|
267
|
-
ensure
|
268
|
-
@connection.rollback_db_transaction
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
it "insert_record should also insert uncommon data types correctly" do
|
273
|
-
@connection.begin_db_transaction
|
274
|
-
begin
|
275
|
-
test_data = {
|
276
|
-
'id' => 2,
|
277
|
-
'decimal_test' => 1.234,
|
278
|
-
'timestamp' => Time.local(2008,"jun",9,20,15,1),
|
279
|
-
'multi_byte' => "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor.",
|
280
|
-
'binary_test' => Marshal.dump(['bla',:dummy,1,2,3]),
|
281
|
-
'text_test' => 'dummy text'
|
282
|
-
}
|
283
|
-
@connection.insert_record('extender_type_check', test_data)
|
284
|
-
|
285
|
-
cursor = @connection.select_cursor(
|
286
|
-
:table => 'extender_type_check',
|
287
|
-
:row_keys => [{'id' => 2}],
|
288
|
-
:type_cast => true
|
289
|
-
)
|
290
|
-
result_data = cursor.next_row
|
291
|
-
result_data.should == test_data
|
292
|
-
ensure
|
293
|
-
@connection.rollback_db_transaction
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
it "table_update_query should return the correct SQL query" do
|
298
|
-
@connection.table_update_query('scanner_records', 'id' => 1) \
|
299
|
-
.should =~ sql_to_regexp(%q!update "scanner_records" set "id" = 1 where ("id") = (1)!)
|
300
|
-
end
|
301
|
-
|
302
|
-
it "update_record should update the specified record" do
|
303
|
-
@connection.begin_db_transaction
|
304
|
-
begin
|
305
|
-
@connection.update_record('scanner_records', 'id' => 1, 'name' => 'update_test')
|
306
|
-
@connection.select_record(
|
307
|
-
:table => "scanner_records",
|
308
|
-
:row_keys => ['id' => 1]
|
309
|
-
).should == {'id' => 1, 'name' => 'update_test'}
|
310
|
-
ensure
|
311
|
-
@connection.rollback_db_transaction
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
it "update_record should return the number of updated records" do
|
316
|
-
@connection.begin_db_transaction
|
317
|
-
begin
|
318
|
-
@connection.
|
319
|
-
update_record('scanner_records', 'id' => 1, 'name' => 'update_test').
|
320
|
-
should == 1
|
321
|
-
@connection.
|
322
|
-
update_record('scanner_records', 'id' => 0, 'name' => 'update_test').
|
323
|
-
should == 0
|
324
|
-
ensure
|
325
|
-
@connection.rollback_db_transaction
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
it "update_record should handle combined primary keys" do
|
330
|
-
@connection.begin_db_transaction
|
331
|
-
begin
|
332
|
-
@connection.update_record('extender_combined_key', 'first_id' => 1, 'second_id' => '1', 'name' => 'xy')
|
333
|
-
@connection.select_record(
|
334
|
-
:table => 'extender_combined_key',
|
335
|
-
:row_keys => ['first_id' => 1, 'second_id' => 1]
|
336
|
-
).should == {'first_id' => 1, 'second_id' => 1, 'name' => 'xy'}
|
337
|
-
ensure
|
338
|
-
@connection.rollback_db_transaction
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
it "update_record should handle key changes" do
|
343
|
-
@connection.begin_db_transaction
|
344
|
-
begin
|
345
|
-
@connection.update_record 'extender_combined_key',
|
346
|
-
{'first_id' => '8', 'second_id' => '9', 'name' => 'xy'},
|
347
|
-
{'first_id' => '1', 'second_id' => '1'}
|
348
|
-
@connection.select_record(
|
349
|
-
:table => 'extender_combined_key',
|
350
|
-
:row_keys => ['first_id' => 8, 'second_id' => 9]
|
351
|
-
).should == {'first_id' => 8, 'second_id' => 9, 'name' => 'xy'}
|
352
|
-
ensure
|
353
|
-
@connection.rollback_db_transaction
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
it "update_record should write nil values correctly" do
|
358
|
-
@connection.begin_db_transaction
|
359
|
-
begin
|
360
|
-
@connection.update_record('extender_combined_key', 'first_id' => 1, 'second_id' => '1', 'name' => nil)
|
361
|
-
@connection.select_record(
|
362
|
-
:table => 'extender_combined_key',
|
363
|
-
:row_keys => ['first_id' => 1, 'second_id' => 1]
|
364
|
-
).should == {'first_id' => 1, 'second_id' => 1, 'name' => nil}
|
365
|
-
ensure
|
366
|
-
@connection.rollback_db_transaction
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
it "update_record should also update uncommon data types correctly" do
|
371
|
-
@connection.begin_db_transaction
|
372
|
-
begin
|
373
|
-
test_data = {
|
374
|
-
'id' => 1,
|
375
|
-
'decimal_test' => 0.234,
|
376
|
-
'timestamp' => Time.local(2009,"jun",9,20,15,1),
|
377
|
-
'multi_byte' => "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor. bla",
|
378
|
-
'binary_test' => Marshal.dump(['bla',:dummy,1,2,3,4]),
|
379
|
-
'text_test' => 'dummy text bla'
|
380
|
-
}
|
381
|
-
@connection.update_record('extender_type_check', test_data)
|
382
|
-
|
383
|
-
@connection.select_record(
|
384
|
-
:table => "extender_type_check",
|
385
|
-
:row_keys => ["id" => 1]
|
386
|
-
).should == test_data
|
387
|
-
ensure
|
388
|
-
@connection.rollback_db_transaction
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
it "table_delete_query should return the correct SQL query" do
|
393
|
-
@connection.table_delete_query('scanner_records', 'id' => 1) \
|
394
|
-
.should =~ sql_to_regexp(%q!delete from "scanner_records" where ("id") = (1)!)
|
395
|
-
end
|
396
|
-
|
397
|
-
it "delete_record should delete the specified record" do
|
398
|
-
@connection.begin_db_transaction
|
399
|
-
begin
|
400
|
-
@connection.delete_record('extender_combined_key', 'first_id' => 1, 'second_id' => '1', 'name' => 'xy')
|
401
|
-
@connection.select_one(
|
402
|
-
"select first_id, second_id, name
|
403
|
-
from extender_combined_key where (first_id, second_id) = (1, 1)") \
|
404
|
-
.should be_nil
|
405
|
-
ensure
|
406
|
-
@connection.rollback_db_transaction
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
it "delete_record should return the number of deleted records" do
|
411
|
-
@connection.begin_db_transaction
|
412
|
-
begin
|
413
|
-
@connection.
|
414
|
-
delete_record('extender_combined_key', 'first_id' => 1, 'second_id' => '1').
|
415
|
-
should == 1
|
416
|
-
@connection.
|
417
|
-
delete_record('extender_combined_key', 'first_id' => 1, 'second_id' => '0').
|
418
|
-
should == 0
|
419
|
-
ensure
|
420
|
-
@connection.rollback_db_transaction
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|
data/spec/proxy_cursor_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe ProxyCursor do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = proxied_config
|
8
|
-
end
|
9
|
-
|
10
|
-
it "initialize should store session and table and cache the primary keys of table" do
|
11
|
-
connection = create_mock_proxy_connection 'dummy_table', ['dummy_key']
|
12
|
-
|
13
|
-
cursor = ProxyCursor.new connection, 'dummy_table'
|
14
|
-
|
15
|
-
cursor.connection.should == connection
|
16
|
-
cursor.table.should == 'dummy_table'
|
17
|
-
cursor.primary_key_names.should == ['dummy_key']
|
18
|
-
end
|
19
|
-
|
20
|
-
it "prepare_fetch should initiate the query and wrap it for type casting" do
|
21
|
-
connection = ProxyConnection.new Initializer.configuration.left
|
22
|
-
|
23
|
-
cursor = ProxyCursor.new(connection, 'scanner_records')
|
24
|
-
cursor.prepare_fetch
|
25
|
-
cursor.cursor.should be_an_instance_of(TypeCastingCursor)
|
26
|
-
cursor.cursor.next_row.should == {'id' => 1, 'name' => 'Alice - exists in both databases'}
|
27
|
-
end
|
28
|
-
|
29
|
-
it "prepare_fetch called with option :row_keys should initiate the correct query" do
|
30
|
-
# Note: I am testing row_keys exclusively to make sure that this type of
|
31
|
-
# sub query will work correctly on all supported databases
|
32
|
-
connection = ProxyConnection.new Initializer.configuration.left
|
33
|
-
|
34
|
-
cursor = ProxyCursor.new(connection, 'extender_combined_key')
|
35
|
-
cursor.prepare_fetch :row_keys => [
|
36
|
-
{'first_id' => 1, 'second_id' => 1},
|
37
|
-
{'first_id' => 1, 'second_id' => 2}
|
38
|
-
]
|
39
|
-
cursor.cursor.next_row.should == {'first_id' => 1, 'second_id' => 1, 'name' => 'aa'}
|
40
|
-
cursor.cursor.next_row.should == {'first_id' => 1, 'second_id' => 2, 'name' => 'ab'}
|
41
|
-
cursor.cursor.next?.should == false
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
it "destroy should clear and nil the cursor" do
|
46
|
-
connection = create_mock_proxy_connection 'dummy_table', ['dummy_key']
|
47
|
-
cursor = ProxyCursor.new connection, 'dummy_table'
|
48
|
-
|
49
|
-
table_cursor = mock("DBCursor")
|
50
|
-
table_cursor.should_receive(:clear)
|
51
|
-
cursor.cursor = table_cursor
|
52
|
-
|
53
|
-
cursor.destroy
|
54
|
-
cursor.cursor.should be_nil
|
55
|
-
end
|
56
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe ProxyRowCursor do
|
6
|
-
before(:each) do
|
7
|
-
Initializer.configuration = standard_config
|
8
|
-
end
|
9
|
-
|
10
|
-
it "initialize should super to ProxyCursor" do
|
11
|
-
session = create_mock_proxy_connection 'dummy_table', ['dummy_id']
|
12
|
-
cursor = ProxyRowCursor.new session, 'dummy_table'
|
13
|
-
cursor.table.should == 'dummy_table'
|
14
|
-
end
|
15
|
-
|
16
|
-
it "next? should delegate to the DB cursor" do
|
17
|
-
session = create_mock_proxy_connection 'dummy_table', ['dummy_id']
|
18
|
-
cursor = ProxyRowCursor.new session, 'dummy_table'
|
19
|
-
|
20
|
-
table_cursor = mock("DBCursor")
|
21
|
-
table_cursor.should_receive(:next?).and_return(true)
|
22
|
-
cursor.cursor = table_cursor
|
23
|
-
|
24
|
-
cursor.next?.should == true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "next_row should return the next row in the cursor" do
|
28
|
-
session = create_mock_proxy_connection 'dummy_table', ['dummy_id']
|
29
|
-
cursor = ProxyRowCursor.new session, 'dummy_table'
|
30
|
-
|
31
|
-
table_cursor = mock("DBCursor")
|
32
|
-
table_cursor.should_receive(:next_row).and_return(:dummy_row)
|
33
|
-
cursor.cursor = table_cursor
|
34
|
-
|
35
|
-
cursor.next_row.should == :dummy_row
|
36
|
-
end
|
37
|
-
|
38
|
-
it "next_row_keys_and_checksum should store the found row under current_row" do
|
39
|
-
session = create_mock_proxy_connection 'dummy_table', ['dummy_id']
|
40
|
-
cursor = ProxyRowCursor.new session, 'dummy_table'
|
41
|
-
|
42
|
-
table_cursor = mock("DBCursor")
|
43
|
-
table_cursor.should_receive(:next_row).and_return('dummy_id' => 'dummy_value')
|
44
|
-
|
45
|
-
cursor.cursor = table_cursor
|
46
|
-
cursor.next_row_keys_and_checksum
|
47
|
-
cursor.current_row.should == {'dummy_id' => 'dummy_value'}
|
48
|
-
end
|
49
|
-
|
50
|
-
it "next_row_keys_and_checksum should returns the primary_keys and checksum of the found row" do
|
51
|
-
session = ProxyConnection.new proxied_config.left
|
52
|
-
|
53
|
-
cursor = ProxyRowCursor.new session, 'scanner_records'
|
54
|
-
cursor.prepare_fetch
|
55
|
-
|
56
|
-
keys, checksum = cursor.next_row_keys_and_checksum
|
57
|
-
|
58
|
-
expected_checksum = Digest::SHA1.hexdigest(
|
59
|
-
Marshal.dump('id' => 1, 'name' => 'Alice - exists in both databases')
|
60
|
-
)
|
61
|
-
|
62
|
-
keys.should == {'id' => 1}
|
63
|
-
checksum.should == expected_checksum
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
data/spec/proxy_runner_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
include RR
|
4
|
-
|
5
|
-
describe ProxyRunner do
|
6
|
-
before(:each) do
|
7
|
-
DRb.stub!(:start_service)
|
8
|
-
DRb.thread.stub!(:join)
|
9
|
-
$stderr.stub!(:puts)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "get_options should return options as nil and status as 1 if command line parameters are unknown" do
|
13
|
-
# also verify that an error message is printed
|
14
|
-
$stderr.should_receive(:puts).any_number_of_times
|
15
|
-
options, status = ProxyRunner.new.get_options ["--nonsense"]
|
16
|
-
options.should == nil
|
17
|
-
status.should == 1
|
18
|
-
end
|
19
|
-
|
20
|
-
it "get_options should return options as nil and status as 0 if command line includes '--help'" do
|
21
|
-
# also verify that the help message is printed
|
22
|
-
$stderr.should_receive(:puts)
|
23
|
-
options, status = ProxyRunner.new.get_options ["--help"]
|
24
|
-
options.should == nil
|
25
|
-
status.should == 0
|
26
|
-
end
|
27
|
-
|
28
|
-
it "get_options should return the default options if none were given on the command line" do
|
29
|
-
options, status = ProxyRunner.new.get_options []
|
30
|
-
options.should == ProxyRunner::DEFAULT_OPTIONS
|
31
|
-
status.should == 0
|
32
|
-
end
|
33
|
-
|
34
|
-
it "get_options should return :host and :port options as per given command line" do
|
35
|
-
options, status = ProxyRunner.new.get_options ["--host", "127.0.0.1", "--port", "1234"]
|
36
|
-
options.should == {:host => '127.0.0.1', :port => 1234}
|
37
|
-
status.should == 0
|
38
|
-
end
|
39
|
-
|
40
|
-
it "construct_url should create the correct druby URL" do
|
41
|
-
ProxyRunner.new.build_url(:host => '127.0.0.1', :port => '1234').should == "druby://127.0.0.1:1234"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "start_server should create a DatabaseProxy and start the DRB server" do
|
45
|
-
DatabaseProxy.should_receive(:new)
|
46
|
-
DRb.should_receive(:start_service,"druby://127.0.0.1:1234")
|
47
|
-
DRb.stub!(:thread).and_return(Object.new)
|
48
|
-
DRb.thread.should_receive(:join)
|
49
|
-
ProxyRunner.new.start_server("druby://127.0.0.1:1234")
|
50
|
-
end
|
51
|
-
|
52
|
-
it "run should not start a server if the command line is invalid" do
|
53
|
-
DRb.should_not_receive(:start_service)
|
54
|
-
DRb.stub!(:thread).and_return(Object.new)
|
55
|
-
DRb.thread.should_not_receive(:join)
|
56
|
-
ProxyRunner.run("--nonsense")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "run should start a server if the command line is correct" do
|
60
|
-
DRb.should_receive(:start_service)
|
61
|
-
DRb.stub!(:thread).and_return(Object.new)
|
62
|
-
DRb.thread.should_receive(:join)
|
63
|
-
ProxyRunner.run(["--port=1234"])
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should register itself with CommandRunner" do
|
67
|
-
CommandRunner.commands['proxy'][:command].should == ProxyRunner
|
68
|
-
CommandRunner.commands['proxy'][:description].should be_an_instance_of(String)
|
69
|
-
end
|
70
|
-
end
|