rubyrep 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +18 -0
  5. data/Gemfile.lock +84 -0
  6. data/History.txt +6 -0
  7. data/README.txt +1 -1
  8. data/Rakefile +6 -27
  9. data/bin/rubyrep +1 -1
  10. data/config/mysql_config.rb +2 -2
  11. data/config/postgres_config.rb +5 -3
  12. data/lib/rubyrep/command_runner.rb +1 -1
  13. data/lib/rubyrep/connection_extenders/connection_extenders.rb +30 -44
  14. data/lib/rubyrep/connection_extenders/mysql_extender.rb +23 -1
  15. data/lib/rubyrep/connection_extenders/postgresql_extender.rb +31 -168
  16. data/lib/rubyrep/generate_runner.rb +1 -1
  17. data/lib/rubyrep/logged_change.rb +1 -1
  18. data/lib/rubyrep/proxy_connection.rb +22 -12
  19. data/lib/rubyrep/replication_difference.rb +1 -1
  20. data/lib/rubyrep/replication_extenders/mysql_replication.rb +1 -1
  21. data/lib/rubyrep/replication_helper.rb +1 -1
  22. data/lib/rubyrep/replication_runner.rb +10 -0
  23. data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +1 -1
  24. data/lib/rubyrep/table_spec_resolver.rb +1 -1
  25. data/lib/rubyrep/type_casting_cursor.rb +8 -4
  26. data/lib/rubyrep/version.rb +1 -7
  27. data/lib/rubyrep.rb +4 -3
  28. data/rubyrep +4 -0
  29. data/rubyrep.bat +5 -0
  30. data/rubyrep.gemspec +29 -0
  31. data/sims/performance/big_rep_spec.rb +34 -17
  32. data/sims/performance/performance.rake +11 -31
  33. data/tasks/database.rake +14 -14
  34. data/tasks/java.rake +18 -5
  35. data/tasks/rspec.rake +14 -34
  36. data/tasks/stats.rake +1 -16
  37. metadata +99 -162
  38. data/.gemtest +0 -0
  39. data/config/requirements.rb +0 -32
  40. data/lib/rubyrep/connection_extenders/jdbc_extender.rb +0 -65
  41. data/spec/base_runner_spec.rb +0 -218
  42. data/spec/buffered_committer_spec.rb +0 -274
  43. data/spec/command_runner_spec.rb +0 -145
  44. data/spec/committers_spec.rb +0 -178
  45. data/spec/configuration_spec.rb +0 -203
  46. data/spec/connection_extender_interface_spec.rb +0 -141
  47. data/spec/connection_extenders_registration_spec.rb +0 -164
  48. data/spec/database_proxy_spec.rb +0 -48
  49. data/spec/database_rake_spec.rb +0 -40
  50. data/spec/db_specific_connection_extenders_spec.rb +0 -34
  51. data/spec/db_specific_replication_extenders_spec.rb +0 -38
  52. data/spec/direct_table_scan_spec.rb +0 -61
  53. data/spec/dolphins.jpg +0 -0
  54. data/spec/generate_runner_spec.rb +0 -84
  55. data/spec/initializer_spec.rb +0 -46
  56. data/spec/log_helper_spec.rb +0 -39
  57. data/spec/logged_change_loader_spec.rb +0 -68
  58. data/spec/logged_change_spec.rb +0 -470
  59. data/spec/noisy_connection_spec.rb +0 -78
  60. data/spec/postgresql_replication_spec.rb +0 -48
  61. data/spec/postgresql_schema_support_spec.rb +0 -212
  62. data/spec/postgresql_support_spec.rb +0 -63
  63. data/spec/progress_bar_spec.rb +0 -77
  64. data/spec/proxied_table_scan_spec.rb +0 -151
  65. data/spec/proxy_block_cursor_spec.rb +0 -197
  66. data/spec/proxy_connection_spec.rb +0 -423
  67. data/spec/proxy_cursor_spec.rb +0 -56
  68. data/spec/proxy_row_cursor_spec.rb +0 -66
  69. data/spec/proxy_runner_spec.rb +0 -70
  70. data/spec/replication_difference_spec.rb +0 -161
  71. data/spec/replication_extender_interface_spec.rb +0 -367
  72. data/spec/replication_extenders_spec.rb +0 -32
  73. data/spec/replication_helper_spec.rb +0 -178
  74. data/spec/replication_initializer_spec.rb +0 -509
  75. data/spec/replication_run_spec.rb +0 -443
  76. data/spec/replication_runner_spec.rb +0 -254
  77. data/spec/replicators_spec.rb +0 -36
  78. data/spec/rubyrep_spec.rb +0 -8
  79. data/spec/scan_detail_reporter_spec.rb +0 -119
  80. data/spec/scan_progress_printers_spec.rb +0 -68
  81. data/spec/scan_report_printers_spec.rb +0 -67
  82. data/spec/scan_runner_spec.rb +0 -50
  83. data/spec/scan_summary_reporter_spec.rb +0 -61
  84. data/spec/session_spec.rb +0 -253
  85. data/spec/spec.opts +0 -1
  86. data/spec/spec_helper.rb +0 -305
  87. data/spec/strange_name_support_spec.rb +0 -135
  88. data/spec/sync_helper_spec.rb +0 -169
  89. data/spec/sync_runner_spec.rb +0 -78
  90. data/spec/syncers_spec.rb +0 -171
  91. data/spec/table_scan_helper_spec.rb +0 -36
  92. data/spec/table_scan_spec.rb +0 -49
  93. data/spec/table_sorter_spec.rb +0 -30
  94. data/spec/table_spec_resolver_spec.rb +0 -111
  95. data/spec/table_sync_spec.rb +0 -140
  96. data/spec/task_sweeper_spec.rb +0 -47
  97. data/spec/trigger_mode_switcher_spec.rb +0 -83
  98. data/spec/two_way_replicator_spec.rb +0 -721
  99. data/spec/two_way_syncer_spec.rb +0 -256
  100. data/spec/type_casting_cursor_spec.rb +0 -50
  101. data/spec/uninstall_runner_spec.rb +0 -93
  102. data/tasks/rubyrep.tailor +0 -18
  103. data/tasks/website.rake +0 -19
@@ -1,203 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- include RR
4
-
5
- describe Configuration do
6
- before(:each) do
7
- end
8
-
9
- it "initialize should set #left and #right to empty hashes" do
10
- config = Configuration.new
11
- config.left.should == {}
12
- config.right.should == {}
13
- end
14
-
15
- it "initialize should set #options to the default options" do
16
- config = Configuration.new
17
- config.options.should == Configuration::DEFAULT_OPTIONS
18
- end
19
-
20
- it "options= should merge the provided into the existing options" do
21
- config = Configuration.new
22
- config.options = {:bla => :bla}
23
- config.options = {:bla => :blub}
24
- config.options[:bla].should == :blub
25
- end
26
-
27
- it "each_matching_option should yield if general option matches" do
28
- config = Configuration.new
29
- config.options = {:bla => :blub}
30
- yielded = []
31
- config.each_matching_option(:bla) {|spec, value| yielded << [spec, value]}
32
- yielded.should == [[nil, :blub]]
33
- end
34
-
35
- it "each_matching_option should yield if table specific options match" do
36
- config = Configuration.new
37
- config.options = {:a => 1}
38
- config.add_table_options 't1', :a => 2
39
- config.add_table_options 't2', :b => 3
40
- config.add_table_options 't3', :a => 4
41
- yielded = []
42
- config.each_matching_option(:a) {|spec, value| yielded << [spec, value]}
43
- yielded.should == [
44
- [nil, 1],
45
- ['t1', 2],
46
- ['t3', 4]
47
- ]
48
- end
49
-
50
- it "each_matching_option should not yield unmatching options" do
51
- config = Configuration.new
52
- config.options = {:a => :blub}
53
- config.add_table_options 'dummy_table', :b => :blub
54
- yielded = []
55
- config.each_matching_option(:c) {|spec, value| yielded << [spec, value]}
56
- yielded.should == []
57
- end
58
-
59
- it "options_for_table should return the general options if there are no table specific options at all" do
60
- config = Configuration.new
61
- config.options_for_table('b').should == \
62
- Syncers::TwoWaySyncer.default_options.clone.
63
- merge(Replicators::TwoWayReplicator.default_options.clone).
64
- merge(config.options)
65
- end
66
-
67
- it "included_table_specs should return the list of included table specifications" do
68
- config = Configuration.new
69
- config.include_tables('a', {:bla => :blub})
70
- config.include_tables('a, b')
71
- config.include_tables(/a/)
72
- config.included_table_specs.should == ['a', 'a, b', /a/]
73
- end
74
-
75
- it "included_table_specs should save the options if provided" do
76
- config = Configuration.new
77
- config.include_tables('a', {:bla => :blub})
78
- config.options_for_table('a')[:bla].should == :blub
79
- end
80
-
81
- it "include_tables should include the specified table specs" do
82
- config = Configuration.new
83
- config.include_tables('a')
84
- config.include_tables(/b/)
85
- config.included_table_specs.include?('a').should be_true
86
- config.included_table_specs.include?(/b/).should be_true
87
- end
88
-
89
- it "include_table should alias to include_tables" do
90
- config = Configuration.new
91
- config.include_table('a')
92
- config.included_table_specs.include?('a').should be_true
93
- end
94
-
95
- it "exclude_tables should exclude the specified table specs" do
96
- config = Configuration.new
97
- config.exclude_tables('a')
98
- config.exclude_tables(/b/)
99
- config.excluded_table_specs.include?('a').should be_true
100
- config.excluded_table_specs.include?(/b/).should be_true
101
- end
102
-
103
- it "exclude_table should alias to exclude_tables" do
104
- config = Configuration.new
105
- config.exclude_table('a')
106
- config.excluded_table_specs.include?('a').should be_true
107
- end
108
-
109
- it "exclude_rubyrep_tables should exclude the rubyrep infrastructure tables" do
110
- config = Configuration.new
111
- config.exclude_rubyrep_tables
112
- config.excluded_table_specs.include?(/^rr_.*/).should be_true
113
- end
114
-
115
- it "excluded_table_specs should return the list of excluded table specifications" do
116
- config = Configuration.new
117
- config.exclude_tables('a')
118
- config.exclude_tables('a, b')
119
- config.exclude_tables(/a/)
120
- config.excluded_table_specs.should == ['a', 'a, b', /a/]
121
- end
122
-
123
- it "options_for_table should return the general options if there are no matching table specific options" do
124
- config = Configuration.new
125
- config.include_tables(/a/, {:bla => :blub})
126
- config.options_for_table('b').should == \
127
- Syncers::TwoWaySyncer.default_options.clone.
128
- merge(Replicators::TwoWayReplicator.default_options.clone).
129
- merge(config.options)
130
- end
131
-
132
- it "options_for_table should return table specific options mixed in with default options" do
133
- config = Configuration.new
134
- config.include_tables(/a/, {:bla => :blub})
135
- config.options_for_table('a').should == \
136
- Syncers::TwoWaySyncer.default_options.clone.
137
- merge(Replicators::TwoWayReplicator.default_options.clone).
138
- merge(config.options).
139
- merge(:bla => :blub)
140
- end
141
-
142
- it "options_for_table should return last added version of added options for matching table spec" do
143
- config = Configuration.new
144
- config.include_tables(/a/, {:bla => :blub})
145
- config.include_tables('a', {:bla => :blok})
146
- config.include_tables(/x/, {:bla => :bar})
147
- config.include_tables('y', {:bla => :foo})
148
- config.options_for_table('a').should == \
149
- Syncers::TwoWaySyncer.default_options.clone.
150
- merge(Replicators::TwoWayReplicator.default_options.clone).
151
- merge(config.options).
152
- merge(:bla => :blok)
153
- end
154
-
155
- it "options_for_table should match against table pair specs" do
156
- config = Configuration.new
157
- config.add_table_options('a, b', {:bla => :blub})
158
- config.options_for_table('a')[:bla].should == :blub
159
- end
160
-
161
- it "options_for_table should match against regular expression specs" do
162
- config = Configuration.new
163
- config.add_table_options(/a/, {:bla => :blub})
164
- config.options_for_table('a')[:bla].should == :blub
165
- end
166
-
167
- it "options_for_table should match against pure table name specs" do
168
- config = Configuration.new
169
- config.add_table_options('a', {:bla => :blub})
170
- config.options_for_table('a')[:bla].should == :blub
171
- end
172
-
173
- it "add_table_options should not create table_spec duplicates" do
174
- config = Configuration.new
175
- config.add_table_options(/a/, {:bla => :blub})
176
- config.add_table_options(/a/, {:foo => :bar})
177
- config.options_for_table('a').should == \
178
- Syncers::TwoWaySyncer.default_options.clone.
179
- merge(Replicators::TwoWayReplicator.default_options.clone).
180
- merge(config.options).
181
- merge(:bla => :blub, :foo => :bar)
182
- end
183
-
184
- it "add_table_option should alias to add_table_options" do
185
- config = Configuration.new
186
- config.add_table_option(/a/, {:bla => :blub})
187
- config.options_for_table('a')[:bla].should == :blub
188
- end
189
-
190
- it "add_table_options should include default syncer options" do
191
- config = Configuration.new
192
- config.options = {:syncer => :one_way}
193
-
194
- # overwrite one syncer option
195
- config.add_table_options(/a/, {:delete => true})
196
-
197
- options = config.options_for_table('a')
198
- Syncers::OneWaySyncer.default_options.each do |key, value|
199
- options[key].should == value unless key == :delete
200
- end
201
- options[:delete].should == true
202
- end
203
- end
@@ -1,141 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
- require 'yaml'
3
- require 'digest/md5'
4
-
5
- include RR
6
-
7
- # All ConnectionExtenders need to pass this spec
8
- describe "ConnectionExtender", :shared => true do
9
- before(:each) do
10
- end
11
-
12
- it "primary_key_names should return primary key names ordered as per primary key index" do
13
- session = Session.new
14
- session.left.primary_key_names('extender_combined_key').should == ['first_id', 'second_id']
15
-
16
- session.left.primary_key_names('extender_inverted_combined_key') \
17
- .should == ['second_id', 'first_id']
18
- end
19
-
20
- it "primary_key_names should return an empty array for tables without any primary key" do
21
- session = Session.new
22
- session.left.primary_key_names('extender_without_key') \
23
- .should == []
24
- end
25
-
26
- it "primary_key_names called for a non-existing table should throw an exception" do
27
- session = Session.new
28
- lambda {session.left.primary_key_names('non_existing_table')} \
29
- .should raise_error(RuntimeError, /.*non_existing_table.*not exist/)
30
- end
31
-
32
- it "referenced_tables should identify the correct table dependencies" do
33
- session = Session.new
34
- referenced_tables = session.left.referenced_tables(['scanner_records', 'referencing_table'])
35
- referenced_tables.size.should == 2
36
- referenced_tables['scanner_records'].should == []
37
- referenced_tables['referencing_table'].sort.
38
- should == ["referenced_table", "referenced_table2"]
39
- end
40
-
41
- it "referenced_tables should return those tables without primary key" do
42
- session = Session.new
43
- referenced_tables = session.left.referenced_tables(['table_with_manual_key'])
44
- referenced_tables.should == {'table_with_manual_key' => []}
45
- end
46
-
47
- it "select_cursor should handle zero result queries" do
48
- session = Session.new
49
- result = session.left.select_cursor :table => 'extender_no_record'
50
- result.next?.should be_false
51
- end
52
-
53
- it "select_cursor should work if row_buffer_size is smaller than table size" do
54
- session = Session.new
55
- result = session.left.select_cursor(:table => 'scanner_records', :row_buffer_size => 2)
56
- result.next_row
57
- result.next_row
58
- result.next_row['id'].should == 3
59
- result.clear
60
- end
61
-
62
- it "select_cursor should allow iterating through records" do
63
- session = Session.new
64
- result = session.left.select_cursor :table => 'extender_one_record'
65
- result.next?.should be_true
66
- result.next_row.should == {'id' => 1, 'name' => 'Alice'}
67
- end
68
-
69
- it "select_cursor next_row should raise if there are no records" do
70
- session = Session.new
71
- result = session.left.select_cursor :table => 'extender_no_record'
72
- lambda {result.next_row}.should raise_error(RuntimeError, 'no more rows available')
73
- end
74
-
75
- it "select_cursor next_row should handle multi byte characters correctly" do
76
- session = Session.new
77
- result = session.left.select_record(:table => "extender_type_check")['multi_byte'].
78
- should == "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor."
79
- end
80
-
81
- it "select_cursor should read null values correctly" do
82
- session = Session.new
83
- result = session.left.select_record(
84
- :table => 'extender_combined_key',
85
- :row_keys => ['first_id' => 3, 'second_id' => 1]
86
- ).should == {'first_id' => 3, 'second_id' => 1, 'name' => nil}
87
- end
88
-
89
- it "should read and write binary data correctly" do
90
- session = Session.new
91
-
92
- org_data = File.new(File.dirname(__FILE__) + '/dolphins.jpg').read
93
- result_data = nil
94
- begin
95
- session.left.begin_db_transaction
96
- session.left.insert_record('extender_type_check', {'id' => 6, 'binary_test' => org_data})
97
-
98
- row = session.left.select_one(
99
- 'select md5(binary_test) as md5 from extender_type_check where id = 6'
100
- )
101
- row['md5'].should == Digest::MD5.hexdigest(org_data)
102
-
103
- result_data = session.left.select_record(
104
- :table => "extender_type_check",
105
- :row_keys => ["id" => 6]
106
- )['binary_test']
107
- Digest::MD5.hexdigest(result_data).should == Digest::MD5.hexdigest(org_data)
108
- ensure
109
- session.left.rollback_db_transaction
110
- end
111
- result_data.should == org_data
112
- end
113
-
114
- it "should read and write text data correctly" do
115
- session = Session.new
116
-
117
- org_data = "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor."
118
- result_data = nil
119
- begin
120
- session.left.begin_db_transaction
121
- sql = "insert into extender_type_check(id, text_test) values(2, '#{org_data}')"
122
- session.left.execute sql
123
-
124
- result_data = session.left.select_record(
125
- :table => "extender_type_check",
126
- :row_keys => ["id" => 2]
127
- )["text_test"]
128
- ensure
129
- session.left.rollback_db_transaction
130
- end
131
- result_data.should == org_data
132
- end
133
-
134
- it "cursors returned by select_cursor should support clear" do
135
- session = Session.new
136
- result = session.left.select_cursor :table => 'extender_one_record'
137
- result.next?.should be_true
138
- result.should respond_to(:clear)
139
- result.clear
140
- end
141
- end
@@ -1,164 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- include RR
4
-
5
- describe ConnectionExtenders do
6
- before(:each) do
7
- Initializer.configuration = standard_config
8
- end
9
-
10
- it "db_connect should install the already created logger" do
11
- configuration = deep_copy(Initializer.configuration)
12
- io = StringIO.new
13
- logger = ActiveSupport::BufferedLogger.new(io)
14
- configuration.left[:logger] = logger
15
- session = Session.new configuration
16
-
17
- session.left.connection.instance_eval {@logger}.should == logger
18
- session.right.connection.instance_eval {@logger}.should_not == logger
19
-
20
- session.left.select_one "select 'left_query'"
21
- session.right.select_one "select 'right_query'"
22
-
23
- io.string.should =~ /left_query/
24
- io.string.should_not =~ /right_query/
25
- end
26
-
27
- it "db_connect should create and install the specified logger" do
28
- configuration = deep_copy(Initializer.configuration)
29
- io = StringIO.new
30
- configuration.left[:logger] = io
31
- session = Session.new configuration
32
- session.left.select_one "select 'left_query'"
33
- session.right.select_one "select 'right_query'"
34
-
35
- io.string.should =~ /left_query/
36
- io.string.should_not =~ /right_query/
37
- end
38
- end
39
-
40
- describe ConnectionExtenders, "Registration" do
41
- before(:each) do
42
- Initializer.configuration = standard_config
43
- @@old_cache_status = ConnectionExtenders.use_db_connection_cache(false)
44
- end
45
-
46
- after(:each) do
47
- ConnectionExtenders.use_db_connection_cache(@@old_cache_status)
48
- end
49
-
50
- it "extenders should return list of registered connection extenders" do
51
- ConnectionExtenders.extenders.include?(:postgresql).should be_true
52
- end
53
-
54
- it "register should register a new connection extender" do
55
- ConnectionExtenders.register(:bla => :blub)
56
-
57
- ConnectionExtenders.extenders.include?(:bla).should be_true
58
- end
59
-
60
- it "register should replace already existing connection extenders" do
61
- ConnectionExtenders.register(:bla => :blub)
62
- ConnectionExtenders.register(:bla => :blub2)
63
-
64
- ConnectionExtenders.extenders[:bla].should == :blub2
65
- end
66
-
67
- it "initialize should establish the database connections" do
68
- mock_active_record :once
69
-
70
- ConnectionExtenders.db_connect Initializer.configuration.left
71
- end
72
-
73
- it "db_connect should use jdbc configuration adapter and extender under jruby" do
74
- fake_ruby_platform 'java' do
75
- mock_active_record :once
76
- used_extender = nil
77
- ConnectionExtenders.extenders.should_receive('[]'.to_sym).once \
78
- .and_return {|extender| used_extender = extender }
79
-
80
- configuration = deep_copy(Initializer.configuration)
81
- configuration.left[:adapter] = 'dummyadapter'
82
-
83
- ConnectionExtenders.db_connect configuration.left
84
-
85
- $used_config[:adapter].should == "jdbcdummyadapter"
86
- used_extender.should == :jdbc
87
- end
88
- end
89
-
90
- it "db_connect created connections should be alive" do
91
- connection = ConnectionExtenders.db_connect Initializer.configuration.left
92
-
93
- connection.should be_active
94
- end
95
-
96
- it "db_connect should include the connection extender into connection" do
97
- connection = ConnectionExtenders.db_connect Initializer.configuration.left
98
-
99
- connection.should respond_to(:primary_key_names)
100
- end
101
-
102
- it "db_connect should raise an Exception if no fitting connection extender is available" do
103
- # If unknown connection adapters are encountered in jruby, then we
104
- # automatically use JdbcExtender.
105
- # Means that this test only makes sense if not running on jruby
106
- if not RUBY_PLATFORM =~ /java/
107
- mock_active_record :once
108
-
109
- config = deep_copy(Initializer.configuration)
110
-
111
- config.left[:adapter] = 'dummy'
112
-
113
- lambda {ConnectionExtenders.db_connect config.left}.should raise_error(RuntimeError, /dummy/)
114
- end
115
- end
116
-
117
- it "use_db_connection_cache should set the new cache status and return the old one" do
118
- ConnectionExtenders.use_db_connection_cache :first_status
119
- first_status = ConnectionExtenders.use_db_connection_cache :second_status
120
- second_status = ConnectionExtenders.use_db_connection_cache :whatever
121
- first_status.should == :first_status
122
- second_status.should == :second_status
123
- end
124
-
125
- it "clear_db_connection_cache should clear the connection cache" do
126
- old_cache = ConnectionExtenders.connection_cache
127
- begin
128
- ConnectionExtenders.connection_cache = :dummy_cache
129
- ConnectionExtenders.clear_db_connection_cache
130
- ConnectionExtenders.connection_cache.should == {}
131
- ensure
132
- ConnectionExtenders.connection_cache = old_cache
133
- end
134
- end
135
-
136
- it "db_connect should create the database connection if not yet cached" do
137
- old_cache = ConnectionExtenders.connection_cache
138
- begin
139
- ConnectionExtenders.clear_db_connection_cache
140
- mock_active_record :once
141
- ConnectionExtenders.use_db_connection_cache true
142
- ConnectionExtenders.db_connect Initializer.configuration.left
143
- ConnectionExtenders.connection_cache.should_not be_empty
144
- ensure
145
- ConnectionExtenders.connection_cache = old_cache
146
- end
147
- end
148
-
149
- it "db_connect should not create the database connection if already cached and alive" do
150
- old_cache = ConnectionExtenders.connection_cache
151
- begin
152
- ConnectionExtenders.clear_db_connection_cache
153
- mock_active_record :once # only mocked once even though db_connect is called twice
154
- ConnectionExtenders.use_db_connection_cache true
155
- connection = ConnectionExtenders.db_connect Initializer.configuration.left
156
- connection.should_receive(:active?).and_return(:true)
157
- ConnectionExtenders.db_connect Initializer.configuration.left
158
- ensure
159
- ConnectionExtenders.connection_cache = old_cache
160
- end
161
- end
162
-
163
- end
164
-
@@ -1,48 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- include RR
4
-
5
- describe DatabaseProxy do
6
- before(:each) do
7
- Initializer.configuration = standard_config
8
- end
9
-
10
- it "initialize should create an empty session regiser" do
11
- proxy = DatabaseProxy.new
12
- proxy.session_register.should == {}
13
- end
14
-
15
- def create_proxy_and_session
16
- proxy = DatabaseProxy.new
17
- session = proxy.create_session Initializer.configuration.left
18
- return proxy, session
19
- end
20
-
21
- it "create_session should register the created session" do
22
- proxy, session = create_proxy_and_session
23
-
24
- session.should be_an_instance_of(ProxyConnection)
25
- proxy.session_register.include?(session).should == true
26
- end
27
-
28
- it "destroy_session should destroy and unregister the session" do
29
- proxy, session = create_proxy_and_session
30
- session.should_receive(:destroy)
31
-
32
- proxy.destroy_session session
33
-
34
- proxy.session_register.include?(session).should == false
35
- end
36
-
37
- it "ping should respond with 'pong'" do
38
- proxy = DatabaseProxy.new
39
- proxy.ping.should == 'pong'
40
- end
41
-
42
- it "terminate should exit the proxy" do
43
- proxy = DatabaseProxy.new
44
- Thread.main.should_receive(:raise).with(SystemExit)
45
-
46
- proxy.terminate!
47
- end
48
- end
@@ -1,40 +0,0 @@
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
-
@@ -1,34 +0,0 @@
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} Connection Extender" do
10
- before(:each) do
11
- @org_test_db = ENV['RR_TEST_DB']
12
- ENV['RR_TEST_DB'] = extender.to_s
13
- Initializer.configuration = standard_config
14
- end
15
-
16
- after(:each) do
17
- ENV['RR_TEST_DB'] = @org_test_db
18
- end
19
-
20
- begin
21
- if ENV['RR_TEST_DB'] != @org_test_db.to_s
22
- # If the current adapter is *not* the adapter for the standard tests
23
- # (meaning the adapter which is used to run all other tests)
24
- # then only run the extender spec if the database connection is available
25
- Session.new read_config(extender)
26
- end
27
- it_should_behave_like "ConnectionExtender"
28
- rescue Exception => e
29
- at_exit do
30
- puts "#{__FILE__}:#{__LINE__}: DB Connection failed with '#{e}' ==> #{extender.to_s.capitalize} connection extender not tested"
31
- end
32
- end
33
- end
34
- end
@@ -1,38 +0,0 @@
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