rubyrep 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +137 -0
  4. data/README.txt +37 -0
  5. data/Rakefile +30 -0
  6. data/bin/rubyrep +8 -0
  7. data/config/hoe.rb +72 -0
  8. data/config/mysql_config.rb +25 -0
  9. data/config/postgres_config.rb +21 -0
  10. data/config/proxied_test_config.rb +14 -0
  11. data/config/redmine_config.rb +17 -0
  12. data/config/rep_config.rb +20 -0
  13. data/config/requirements.rb +32 -0
  14. data/config/test_config.rb +20 -0
  15. data/lib/rubyrep/base_runner.rb +195 -0
  16. data/lib/rubyrep/command_runner.rb +144 -0
  17. data/lib/rubyrep/committers/buffered_committer.rb +140 -0
  18. data/lib/rubyrep/committers/committers.rb +146 -0
  19. data/lib/rubyrep/configuration.rb +240 -0
  20. data/lib/rubyrep/connection_extenders/connection_extenders.rb +133 -0
  21. data/lib/rubyrep/connection_extenders/jdbc_extender.rb +284 -0
  22. data/lib/rubyrep/connection_extenders/mysql_extender.rb +168 -0
  23. data/lib/rubyrep/connection_extenders/postgresql_extender.rb +261 -0
  24. data/lib/rubyrep/database_proxy.rb +52 -0
  25. data/lib/rubyrep/direct_table_scan.rb +75 -0
  26. data/lib/rubyrep/generate_runner.rb +105 -0
  27. data/lib/rubyrep/initializer.rb +39 -0
  28. data/lib/rubyrep/logged_change.rb +326 -0
  29. data/lib/rubyrep/proxied_table_scan.rb +171 -0
  30. data/lib/rubyrep/proxy_block_cursor.rb +145 -0
  31. data/lib/rubyrep/proxy_connection.rb +318 -0
  32. data/lib/rubyrep/proxy_cursor.rb +44 -0
  33. data/lib/rubyrep/proxy_row_cursor.rb +43 -0
  34. data/lib/rubyrep/proxy_runner.rb +89 -0
  35. data/lib/rubyrep/replication_difference.rb +91 -0
  36. data/lib/rubyrep/replication_extenders/mysql_replication.rb +271 -0
  37. data/lib/rubyrep/replication_extenders/postgresql_replication.rb +204 -0
  38. data/lib/rubyrep/replication_extenders/replication_extenders.rb +26 -0
  39. data/lib/rubyrep/replication_helper.rb +104 -0
  40. data/lib/rubyrep/replication_initializer.rb +307 -0
  41. data/lib/rubyrep/replication_run.rb +48 -0
  42. data/lib/rubyrep/replication_runner.rb +138 -0
  43. data/lib/rubyrep/replicators/replicators.rb +37 -0
  44. data/lib/rubyrep/replicators/two_way_replicator.rb +334 -0
  45. data/lib/rubyrep/scan_progress_printers/progress_bar.rb +65 -0
  46. data/lib/rubyrep/scan_progress_printers/scan_progress_printers.rb +65 -0
  47. data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +111 -0
  48. data/lib/rubyrep/scan_report_printers/scan_report_printers.rb +67 -0
  49. data/lib/rubyrep/scan_report_printers/scan_summary_reporter.rb +75 -0
  50. data/lib/rubyrep/scan_runner.rb +25 -0
  51. data/lib/rubyrep/session.rb +177 -0
  52. data/lib/rubyrep/sync_helper.rb +111 -0
  53. data/lib/rubyrep/sync_runner.rb +31 -0
  54. data/lib/rubyrep/syncers/syncers.rb +112 -0
  55. data/lib/rubyrep/syncers/two_way_syncer.rb +174 -0
  56. data/lib/rubyrep/table_scan.rb +54 -0
  57. data/lib/rubyrep/table_scan_helper.rb +38 -0
  58. data/lib/rubyrep/table_sorter.rb +70 -0
  59. data/lib/rubyrep/table_spec_resolver.rb +136 -0
  60. data/lib/rubyrep/table_sync.rb +68 -0
  61. data/lib/rubyrep/trigger_mode_switcher.rb +63 -0
  62. data/lib/rubyrep/type_casting_cursor.rb +31 -0
  63. data/lib/rubyrep/uninstall_runner.rb +92 -0
  64. data/lib/rubyrep/version.rb +9 -0
  65. data/lib/rubyrep.rb +68 -0
  66. data/script/destroy +14 -0
  67. data/script/generate +14 -0
  68. data/script/txt2html +74 -0
  69. data/setup.rb +1585 -0
  70. data/sims/performance/big_rep_spec.rb +100 -0
  71. data/sims/performance/big_scan_spec.rb +57 -0
  72. data/sims/performance/big_sync_spec.rb +141 -0
  73. data/sims/performance/performance.rake +228 -0
  74. data/sims/sim_helper.rb +24 -0
  75. data/spec/base_runner_spec.rb +218 -0
  76. data/spec/buffered_committer_spec.rb +271 -0
  77. data/spec/command_runner_spec.rb +145 -0
  78. data/spec/committers_spec.rb +174 -0
  79. data/spec/configuration_spec.rb +198 -0
  80. data/spec/connection_extender_interface_spec.rb +138 -0
  81. data/spec/connection_extenders_registration_spec.rb +129 -0
  82. data/spec/database_proxy_spec.rb +48 -0
  83. data/spec/database_rake_spec.rb +40 -0
  84. data/spec/db_specific_connection_extenders_spec.rb +34 -0
  85. data/spec/db_specific_replication_extenders_spec.rb +38 -0
  86. data/spec/direct_table_scan_spec.rb +61 -0
  87. data/spec/generate_runner_spec.rb +84 -0
  88. data/spec/initializer_spec.rb +46 -0
  89. data/spec/logged_change_spec.rb +480 -0
  90. data/spec/postgresql_replication_spec.rb +48 -0
  91. data/spec/postgresql_support_spec.rb +57 -0
  92. data/spec/progress_bar_spec.rb +77 -0
  93. data/spec/proxied_table_scan_spec.rb +151 -0
  94. data/spec/proxy_block_cursor_spec.rb +197 -0
  95. data/spec/proxy_connection_spec.rb +399 -0
  96. data/spec/proxy_cursor_spec.rb +56 -0
  97. data/spec/proxy_row_cursor_spec.rb +66 -0
  98. data/spec/proxy_runner_spec.rb +70 -0
  99. data/spec/replication_difference_spec.rb +160 -0
  100. data/spec/replication_extender_interface_spec.rb +365 -0
  101. data/spec/replication_extenders_spec.rb +32 -0
  102. data/spec/replication_helper_spec.rb +121 -0
  103. data/spec/replication_initializer_spec.rb +477 -0
  104. data/spec/replication_run_spec.rb +166 -0
  105. data/spec/replication_runner_spec.rb +213 -0
  106. data/spec/replicators_spec.rb +31 -0
  107. data/spec/rubyrep_spec.rb +8 -0
  108. data/spec/scan_detail_reporter_spec.rb +119 -0
  109. data/spec/scan_progress_printers_spec.rb +68 -0
  110. data/spec/scan_report_printers_spec.rb +67 -0
  111. data/spec/scan_runner_spec.rb +50 -0
  112. data/spec/scan_summary_reporter_spec.rb +61 -0
  113. data/spec/session_spec.rb +212 -0
  114. data/spec/spec.opts +1 -0
  115. data/spec/spec_helper.rb +295 -0
  116. data/spec/sync_helper_spec.rb +157 -0
  117. data/spec/sync_runner_spec.rb +78 -0
  118. data/spec/syncers_spec.rb +171 -0
  119. data/spec/table_scan_helper_spec.rb +29 -0
  120. data/spec/table_scan_spec.rb +49 -0
  121. data/spec/table_sorter_spec.rb +31 -0
  122. data/spec/table_spec_resolver_spec.rb +102 -0
  123. data/spec/table_sync_spec.rb +84 -0
  124. data/spec/trigger_mode_switcher_spec.rb +83 -0
  125. data/spec/two_way_replicator_spec.rb +551 -0
  126. data/spec/two_way_syncer_spec.rb +256 -0
  127. data/spec/type_casting_cursor_spec.rb +50 -0
  128. data/spec/uninstall_runner_spec.rb +86 -0
  129. data/tasks/database.rake +439 -0
  130. data/tasks/deployment.rake +29 -0
  131. data/tasks/environment.rake +9 -0
  132. data/tasks/java.rake +37 -0
  133. data/tasks/redmine_test.rake +47 -0
  134. data/tasks/rspec.rake +68 -0
  135. data/tasks/rubyrep.tailor +18 -0
  136. data/tasks/stats.rake +19 -0
  137. data/tasks/task_helper.rb +20 -0
  138. data.tar.gz.sig +0 -0
  139. metadata +243 -0
  140. metadata.gz.sig +0 -0
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ load File.dirname(__FILE__) + '/../tasks/database.rake'
3
+
4
+ describe "database.rake" do
5
+ before(:each) do
6
+ end
7
+
8
+ it "create_database should create a non-existing database" do
9
+ RR::ConnectionExtenders.should_receive(:db_connect).and_raise("something")
10
+ should_receive("`").with("createdb \"dummy\" -E utf8")
11
+
12
+ create_database :adapter => "postgresql", :database => "dummy"
13
+ end
14
+
15
+ it "create_database should not try to create existing databases" do
16
+ RR::ConnectionExtenders.should_receive(:db_connect)
17
+ should_receive(:puts).with("database existing_db already exists")
18
+
19
+ create_database :adapter => 'postgresql', :database => "existing_db"
20
+ end
21
+
22
+ it "create_database should complain about unsupported adapters" do
23
+ should_receive(:puts).with("adapter unsupported_adapter not supported")
24
+
25
+ create_database :adapter => "unsupported_adapter"
26
+ end
27
+
28
+ it "drop_database should drop a PostgreSQL database" do
29
+ should_receive("`").with("dropdb \"dummy\"")
30
+
31
+ drop_database :adapter => "postgresql", :database => "dummy"
32
+ end
33
+
34
+ it "drop_database should complain about unsupported adapters" do
35
+ should_receive(:puts).with("adapter unsupported_adapter not supported")
36
+
37
+ drop_database :adapter => "unsupported_adapter"
38
+ end
39
+ end
40
+
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+
4
+ include RR
5
+
6
+ extenders = [:mysql, :postgres]
7
+
8
+ extenders.each do |extender|
9
+ describe "#{extender.to_s.capitalize} Replication Extender" do
10
+ before(:each) do
11
+ @org_test_db = ENV['RR_TEST_DB']
12
+ ENV['RR_TEST_DB'] = extender.to_s
13
+ Initializer.configuration = standard_config
14
+ end
15
+
16
+ after(:each) do
17
+ ENV['RR_TEST_DB'] = @org_test_db
18
+ end
19
+
20
+ begin
21
+ if ENV['RR_TEST_DB'] != @org_test_db.to_s
22
+ # If the current adapter is *not* the adapter for the standard tests
23
+ # (meaning the adapter which is used to run all other tests)
24
+ # then only run the extender spec if the database connection is available
25
+ Session.new read_config(extender)
26
+ end
27
+ it_should_behave_like "ConnectionExtender"
28
+ rescue Exception => e
29
+ at_exit do
30
+ puts "#{__FILE__}:#{__LINE__}: DB Connection failed with '#{e}' ==> #{extender.to_s.capitalize} connection extender not tested"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require 'yaml'
3
+
4
+ require 'replication_extender_interface_spec.rb'
5
+ require 'postgresql_replication_spec.rb'
6
+
7
+ include RR
8
+
9
+ extenders = [:postgres, :mysql]
10
+
11
+ extenders.each do |extender|
12
+ describe "#{extender.to_s.capitalize} Replication Extender" do
13
+ before(:each) do
14
+ @org_test_db = ENV['RR_TEST_DB']
15
+ ENV['RR_TEST_DB'] = extender.to_s
16
+ Initializer.configuration = standard_config
17
+ end
18
+
19
+ after(:each) do
20
+ ENV['RR_TEST_DB'] = @org_test_db
21
+ end
22
+
23
+ begin
24
+ if ENV['RR_TEST_DB'] != @org_test_db.to_s
25
+ # If the current adapter is *not* the adapter for the standard tests
26
+ # (meaning the adapter which is used to run all other tests)
27
+ # then only run the extender spec if the database connection is available
28
+ Session.new read_config(extender)
29
+ end
30
+ it_should_behave_like "ReplicationExtender"
31
+ it_should_behave_like "PostgreSQLReplication" if extender == :postgres
32
+ rescue Exception => e
33
+ at_exit do
34
+ puts "#{__FILE__}:#{__LINE__}: DB Connection failed with '#{e}' ==> #{extender.to_s.capitalize} replication extender not tested"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ include RR
4
+
5
+ describe DirectTableScan do
6
+ before(:each) do
7
+ Initializer.configuration = standard_config
8
+ end
9
+
10
+ it "run should compare all the records in the table" do
11
+ session = Session.new
12
+ scan = DirectTableScan.new session, 'scanner_records'
13
+ diff = []
14
+ scan.run do |type, row|
15
+ diff.push [type, row]
16
+ end
17
+ # in this scenario the right table has the 'highest' data,
18
+ # so 'right-sided' data are already implicitely tested here
19
+ diff.should == [
20
+ [:conflict, [
21
+ {'id' => 2, 'name' => 'Bob - left database version'},
22
+ {'id' => 2, 'name' => 'Bob - right database version'}]],
23
+ [:left, {'id' => 3, 'name' => 'Charlie - exists in left database only'}],
24
+ [:right, {'id' => 4, 'name' => 'Dave - exists in right database only'}],
25
+ [:left, {'id' => 5, 'name' => 'Eve - exists in left database only'}],
26
+ [:right, {'id' => 6, 'name' => 'Fred - exists in right database only'}]
27
+ ]
28
+ end
29
+
30
+ it "run should handle one-sided data" do
31
+ # separate test case for left-sided data; right-sided data are already covered in the general test
32
+ session = Session.new
33
+ scan = DirectTableScan.new session, 'scanner_left_records_only'
34
+ diff = []
35
+ scan.run do |type, row|
36
+ diff.push [type, row]
37
+ end
38
+ diff.should == [
39
+ [:left, {'id' => 1, 'name' => 'Alice'}],
40
+ [:left, {'id' => 2, 'name' => 'Bob'}]
41
+ ]
42
+ end
43
+
44
+ it "run should update the progress" do
45
+ session = Session.new
46
+ scan = DirectTableScan.new session, 'scanner_records'
47
+ number_steps = 0
48
+ scan.should_receive(:update_progress).any_number_of_times do |steps|
49
+ number_steps += steps
50
+ end
51
+ scan.run {|_, _|}
52
+ number_steps.should == 8
53
+ end
54
+
55
+ it "run should update the progress even if there are no records" do
56
+ # it should do that to ensure the progress bar is printed
57
+ scan = DirectTableScan.new Session.new, 'extender_no_record'
58
+ scan.should_receive(:update_progress).at_least(:once)
59
+ scan.run {|_, _|}
60
+ end
61
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ include RR
4
+
5
+ describe GenerateRunner do
6
+ before(:each) do
7
+ end
8
+
9
+ it "should register itself with CommandRunner" do
10
+ CommandRunner.commands['generate'][:command].should == GenerateRunner
11
+ CommandRunner.commands['generate'][:description].should be_an_instance_of(String)
12
+ end
13
+
14
+ it "process_options should make options as nil and teturn status as 1 if command line parameters are unknown" do
15
+ # also verify that an error message is printed
16
+ $stderr.should_receive(:puts).any_number_of_times
17
+ runner = GenerateRunner.new
18
+ status = runner.process_options ["--nonsense"]
19
+ runner.options.should == nil
20
+ status.should == 1
21
+ end
22
+
23
+ it "process_options should make options as nil and return status as 1 if file name is not given" do
24
+ # also verify that an error message is printed
25
+ $stderr.should_receive(:puts).any_number_of_times
26
+ runner = GenerateRunner.new
27
+ status = runner.process_options []
28
+ runner.options.should == nil
29
+ status.should == 1
30
+ end
31
+
32
+ it "process_options should make options as nil and return status as 0 if command line includes '--help'" do
33
+ # also verify that the help message is printed
34
+ $stderr.should_receive(:puts)
35
+ runner = GenerateRunner.new
36
+ status = runner.process_options ["--help"]
37
+ runner.options.should == nil
38
+ status.should == 0
39
+ end
40
+
41
+ it "process_options should set the correct options" do
42
+ runner = GenerateRunner.new
43
+ runner.process_options ["my_file_name"]
44
+ runner.options[:file_name].should == 'my_file_name'
45
+ end
46
+
47
+ it "run should not start the generate command if the command line is invalid" do
48
+ $stderr.should_receive(:puts).any_number_of_times
49
+ GenerateRunner.any_instance_should_not_receive(:execute) {
50
+ GenerateRunner.run(["--nonsense"])
51
+ }
52
+ end
53
+
54
+ it "run should start an uninstall if the command line is correct" do
55
+ GenerateRunner.any_instance_should_receive(:execute) {
56
+ GenerateRunner.run(["my_file_name"])
57
+ }
58
+ end
59
+
60
+ it "execute should refuse to overwrite an existing file" do
61
+ begin
62
+ File.open("my_config_template", 'w') do |f|
63
+ f.write 'bla'
64
+ end
65
+ runner = GenerateRunner.new
66
+ runner.options = {:file_name => 'my_config_template'}
67
+ lambda {runner.execute}.should raise_error(/refuse/)
68
+ ensure
69
+ File.delete('my_config_template') rescue nil
70
+ end
71
+ end
72
+
73
+ it "execute should create the configuration template under the specified name" do
74
+ begin
75
+ runner = GenerateRunner.new
76
+ runner.options = {:file_name => 'my_config_template'}
77
+ runner.execute
78
+ File.exists?('my_config_template').should be_true
79
+ ensure
80
+ File.delete 'my_config_template' rescue nil
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ include RR
4
+
5
+ describe Initializer do
6
+ it "should have an empty configuration" do
7
+ Initializer::configuration.should be_an_instance_of(Configuration)
8
+ end
9
+ end
10
+
11
+ describe Initializer do
12
+ before(:each) do
13
+ Initializer::reset
14
+ end
15
+
16
+ it "run should yield the configuration object" do
17
+ Initializer::run do |config|
18
+ config.should be_an_instance_of(Configuration)
19
+ end
20
+ end
21
+
22
+ def make_dummy_configuration_change
23
+ Initializer::run do |config|
24
+ config.left = :dummy
25
+ end
26
+ end
27
+
28
+ it "configuration should return the current configuration" do
29
+ make_dummy_configuration_change
30
+ Initializer::configuration.should be_an_instance_of(Configuration)
31
+ Initializer::configuration.left.should == :dummy
32
+ end
33
+
34
+ it "configuration= should set a new configuration" do
35
+ make_dummy_configuration_change
36
+ Initializer::configuration = :dummy_config
37
+ Initializer::configuration.should == :dummy_config
38
+ end
39
+
40
+ it "reset should clear the configuration" do
41
+ make_dummy_configuration_change
42
+ Initializer::reset
43
+ Initializer::configuration.left.should {}
44
+ end
45
+ end
46
+