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
@@ -66,9 +66,27 @@ module RR
|
|
66
66
|
end
|
67
67
|
|
68
68
|
self.rows = connection.select_all query
|
69
|
+
|
70
|
+
###############
|
71
|
+
# Below approach can only be used starting with activerecord version 5.
|
72
|
+
# And as of 2017-05-18 jruby (i.e. version 9.1.7.0) supports only up to activerecord version 4.2.
|
73
|
+
###############
|
74
|
+
# result = connection.select_all(query)
|
75
|
+
# column_types = result.column_types
|
76
|
+
# columns = result.columns
|
77
|
+
# identity_type = ActiveRecord::Type::Value.new
|
78
|
+
# types = columns.map { |name| column_types.fetch(name, identity_type) }
|
79
|
+
# self.rows = result.rows.map do |values|
|
80
|
+
# row = {}
|
81
|
+
# columns.zip(types, values).each do |name, type, value|
|
82
|
+
# row[name] = type.deserialize(value)
|
83
|
+
# end
|
84
|
+
# row
|
85
|
+
# end
|
86
|
+
|
69
87
|
self.current_row_index = 0
|
70
88
|
end
|
71
|
-
self.current_row_index < self.rows.
|
89
|
+
self.current_row_index < self.rows.length
|
72
90
|
end
|
73
91
|
|
74
92
|
# Returns the row as a column => value hash and moves the cursor to the next row.
|
@@ -77,7 +95,7 @@ module RR
|
|
77
95
|
self.last_row = self.rows[self.current_row_index]
|
78
96
|
self.current_row_index += 1
|
79
97
|
|
80
|
-
if self.current_row_index == self.rows.
|
98
|
+
if self.current_row_index == self.rows.length
|
81
99
|
self.rows = nil
|
82
100
|
end
|
83
101
|
|
@@ -184,20 +202,12 @@ module RR
|
|
184
202
|
# * first build the query based on options forwarded to #table_select_query
|
185
203
|
# +options+ is a hash with
|
186
204
|
# * :+query+: executes the given query
|
187
|
-
# * :+type_cast+:
|
188
|
-
# Unless explicitely disabled with +false+, build type casting cursor
|
189
|
-
# around result.
|
190
|
-
# * :+table+:
|
191
|
-
# Name of the table from which to read data.
|
192
|
-
# Required unless type casting is disabled.
|
193
205
|
# * further options as taken by #table_select_query to build the query
|
194
206
|
# * :+row_buffer_size+:
|
195
207
|
# Integer controlling how many rows a read into memory at one time.
|
196
208
|
def select_cursor(options)
|
197
209
|
cursor = ResultFetcher.new(self, options)
|
198
|
-
|
199
|
-
cursor = TypeCastingCursor.new(self, options[:table], cursor)
|
200
|
-
end
|
210
|
+
cursor = TypeCastingCursor.new(self, options[:table], cursor)
|
201
211
|
cursor
|
202
212
|
end
|
203
213
|
|
@@ -255,7 +265,7 @@ module RR
|
|
255
265
|
table_columns[table] = {}
|
256
266
|
columns(table).each {|c| table_columns[table][c.name] = c}
|
257
267
|
end
|
258
|
-
connection.
|
268
|
+
connection.column_aware_quote value, table_columns[table][column.to_s]
|
259
269
|
end
|
260
270
|
|
261
271
|
# Create a cursor for the given table.
|
@@ -93,7 +93,7 @@ module RR
|
|
93
93
|
|
94
94
|
# Prevents session and change loaders from going into YAML output
|
95
95
|
def to_yaml_properties
|
96
|
-
instance_variables.sort.reject {|var_name| ['@session', '@loaders'].include? var_name}
|
96
|
+
instance_variables.sort.reject {|var_name| [:'@session', :'@loaders'].include? var_name}
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
@@ -3,7 +3,7 @@ module RR
|
|
3
3
|
|
4
4
|
# Provides Mysql specific functionality for database replication
|
5
5
|
module MysqlReplication
|
6
|
-
RR::ReplicationExtenders.register :
|
6
|
+
RR::ReplicationExtenders.register :mysql2 => self
|
7
7
|
|
8
8
|
# Creates or replaces the replication trigger function.
|
9
9
|
# See #create_replication_trigger for a descriptions of the +params+ hash.
|
@@ -92,7 +92,7 @@ module RR
|
|
92
92
|
columns = @table_columns[table]
|
93
93
|
type_casted_row = {}
|
94
94
|
row.each_pair do |column_name, value|
|
95
|
-
type_casted_row[column_name] = columns[column_name]
|
95
|
+
type_casted_row[column_name] = session.left.connection.fixed_type_cast value, columns[column_name]
|
96
96
|
end
|
97
97
|
type_casted_row
|
98
98
|
end
|
@@ -128,10 +128,19 @@ EOS
|
|
128
128
|
raise e
|
129
129
|
end
|
130
130
|
|
131
|
+
# For testing: will be called after replication preparation is finished
|
132
|
+
def replication_preparation_finished
|
133
|
+
end
|
134
|
+
|
135
|
+
# For testing: will be called after a replication run is finished
|
136
|
+
def replication_run_finished
|
137
|
+
end
|
138
|
+
|
131
139
|
# Executes an endless loop of replication runs
|
132
140
|
def execute
|
133
141
|
init_waiter
|
134
142
|
prepare_replication
|
143
|
+
replication_preparation_finished
|
135
144
|
|
136
145
|
until termination_requested do
|
137
146
|
begin
|
@@ -145,6 +154,7 @@ EOS
|
|
145
154
|
end
|
146
155
|
end
|
147
156
|
pause_replication
|
157
|
+
replication_run_finished
|
148
158
|
end
|
149
159
|
end
|
150
160
|
|
@@ -16,7 +16,7 @@ module RR::ScanReportPrinters
|
|
16
16
|
"The 'mode' argument determines how the row differences are printed:",
|
17
17
|
" * full shows the full records",
|
18
18
|
" * keys shows the primary key columns only",
|
19
|
-
" * diff shows the primary key and differing
|
19
|
+
" * diff shows the primary key and differing columns only"
|
20
20
|
|
21
21
|
# The current Session object
|
22
22
|
attr_accessor :session
|
@@ -88,7 +88,7 @@ module RR
|
|
88
88
|
case table_spec
|
89
89
|
when /^\/.*\/$/ # matches e. g. '/^user/'
|
90
90
|
table_spec = table_spec.sub(/^\/(.*)\/$/,'\1') # remove leading and trailing slash
|
91
|
-
matching_tables = tables(:left).grep(Regexp.new(table_spec, Regexp::IGNORECASE
|
91
|
+
matching_tables = tables(:left).grep(Regexp.new(table_spec, Regexp::IGNORECASE))
|
92
92
|
matching_tables.each do |table|
|
93
93
|
if !verify or tables(:right).include? table
|
94
94
|
table_pairs << {:left => table, :right => table}
|
@@ -6,13 +6,15 @@ module RR
|
|
6
6
|
# Delegate the uninteresting methods to the original cursor
|
7
7
|
def next?; org_cursor.next? end
|
8
8
|
def clear; org_cursor.clear end
|
9
|
-
|
10
|
-
|
9
|
+
def connection; org_cursor.connection end
|
10
|
+
def options; org_cursor.options end
|
11
|
+
|
12
|
+
# @return [ResultFetcher] the original cursor
|
11
13
|
attr_accessor :org_cursor
|
12
14
|
|
13
15
|
# A column_name => Column cache
|
14
16
|
attr_accessor :columns
|
15
|
-
|
17
|
+
|
16
18
|
# Creates a new TypeCastingCursor based on provided database connection and table name
|
17
19
|
# for the provided database query cursor
|
18
20
|
def initialize(connection, table, cursor)
|
@@ -24,7 +26,9 @@ module RR
|
|
24
26
|
# Reads the next row from the original cursor and returns the row with the type casted row values.
|
25
27
|
def next_row
|
26
28
|
row = org_cursor.next_row
|
27
|
-
row.each
|
29
|
+
row.each do |column, value|
|
30
|
+
row[column] = connection.connection.fixed_type_cast value, columns[column]
|
31
|
+
end
|
28
32
|
row
|
29
33
|
end
|
30
34
|
end
|
data/lib/rubyrep/version.rb
CHANGED
data/lib/rubyrep.rb
CHANGED
@@ -4,8 +4,10 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/rubyrep"
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
-
gem 'activerecord', '>=
|
7
|
+
gem 'activerecord', '>= 4.2', '< 5'
|
8
8
|
require 'active_record'
|
9
|
+
require 'activerecord-jdbc-adapter' if RUBY_PLATFORM == 'java'
|
10
|
+
require 'ap'
|
9
11
|
|
10
12
|
require 'version'
|
11
13
|
require 'configuration'
|
@@ -56,8 +58,7 @@ require 'generate_runner'
|
|
56
58
|
require 'noisy_connection'
|
57
59
|
|
58
60
|
Dir["#{File.dirname(__FILE__)}/rubyrep/connection_extenders/*.rb"].each do |extender|
|
59
|
-
|
60
|
-
require extender unless extender =~ /jdbc/ and not RUBY_PLATFORM =~ /java/
|
61
|
+
require extender
|
61
62
|
end
|
62
63
|
|
63
64
|
require 'replication_initializer'
|
data/rubyrep
CHANGED
@@ -5,4 +5,8 @@ script_dir="`dirname \"$0\"`"
|
|
5
5
|
jruby_path="$script_dir"/jruby/bin/jruby
|
6
6
|
rubyrep_path="$script_dir"/bin/rubyrep
|
7
7
|
|
8
|
+
# ensure isolation from rvm or other possible existing ruby installations
|
9
|
+
unset GEM_HOME
|
10
|
+
unset GEM_PATH
|
11
|
+
|
8
12
|
$jruby_path --server $rubyrep_path $*
|
data/rubyrep.bat
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
@echo off
|
2
|
+
|
3
|
+
REM ensure isolation from rvm or other possibly existing ruby installations
|
4
|
+
set GEM_HOME=
|
5
|
+
set GEM_PATH=
|
6
|
+
|
2
7
|
set jruby_path=%~dp0jruby\bin\jruby.bat
|
3
8
|
set rubyrep_path=%~dp0bin\rubyrep
|
4
9
|
%jruby_path% --server %rubyrep_path% %1 %2 %3 %4 %5 %6 %7 %8 %9
|
data/rubyrep.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubyrep/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubyrep"
|
8
|
+
spec.version = RR::VERSION
|
9
|
+
spec.authors = ["Arndt Lehmann"]
|
10
|
+
spec.email = ["arndtlehmann@arndtlehmann.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Open-source solution for asynchronous, master-master replication of relational databases.}
|
13
|
+
spec.homepage = "http://www.rubyrep.org"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "activerecord", "~> 4.2"
|
28
|
+
spec.add_runtime_dependency "awesome_print"
|
29
|
+
end
|
@@ -34,6 +34,18 @@ describe "Big Rep" do
|
|
34
34
|
record_quantity(session, :right, 'rr_pending_changes')
|
35
35
|
end
|
36
36
|
|
37
|
+
# Removes test data
|
38
|
+
#
|
39
|
+
# @param [Session] session the target session
|
40
|
+
# @param [Initializer] initializer the target initializer
|
41
|
+
def cleanup(session, initializer)
|
42
|
+
[:left, :right].each do |database|
|
43
|
+
initializer.drop_trigger database, 'big_rep' if initializer.trigger_exists? database, 'big_rep'
|
44
|
+
session.send(database).execute "delete from big_rep"
|
45
|
+
session.send(database).execute "delete from rr_pending_changes"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
# Runs a replication of the big_rep table.
|
38
50
|
def run_rep
|
39
51
|
config = deep_copy(Initializer.configuration)
|
@@ -41,32 +53,41 @@ describe "Big Rep" do
|
|
41
53
|
:committer => :buffered_commit,
|
42
54
|
:replication_conflict_handling => :later_wins,
|
43
55
|
}
|
56
|
+
config.options[:event_filter] = filter = {}
|
44
57
|
|
45
58
|
session = Session.new config
|
46
59
|
initializer = ReplicationInitializer.new session
|
47
60
|
begin
|
61
|
+
cleanup session, initializer
|
48
62
|
[:left, :right].each do |database|
|
49
63
|
session.send(database).execute "insert into big_rep select * from big_rep_backup"
|
50
64
|
session.send(database).execute "insert into rr_pending_changes select * from big_rep_pending_changes"
|
51
65
|
initializer.create_trigger database, 'big_rep'
|
52
66
|
end
|
53
67
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
progress_bar.step remaining_changes - new_remaining_changes
|
63
|
-
remaining_changes = new_remaining_changes
|
68
|
+
filter[:number_changes] = lambda { number_changes(session)}
|
69
|
+
def filter.before_replicate(*args)
|
70
|
+
if self[:last_check].nil? || self[:last_check] < 1.second.ago || args.empty?
|
71
|
+
self[:last_check] = Time.now
|
72
|
+
new_remaining_changes = self[:number_changes].call
|
73
|
+
steps = self[:remaining_changes] - new_remaining_changes
|
74
|
+
self[:progress_bar].step steps
|
75
|
+
self[:remaining_changes] = new_remaining_changes
|
64
76
|
end
|
77
|
+
true
|
65
78
|
end
|
79
|
+
filter[:remaining_changes] = filter[:number_changes].call
|
80
|
+
filter[:progress_bar] = ScanProgressPrinters::ProgressBar.new(
|
81
|
+
filter[:remaining_changes],
|
82
|
+
session,
|
83
|
+
'big_rep',
|
84
|
+
'big_re'
|
85
|
+
)
|
86
|
+
|
87
|
+
puts "\nReplicating (#{session.proxied? ? :proxied : :direct}) table big_rep (#{number_changes(session)} changes)"
|
66
88
|
|
67
89
|
run = ReplicationRun.new session, TaskSweeper.new(5)
|
68
|
-
benchmark = Benchmark.measure { run.run }
|
69
|
-
t.join 10
|
90
|
+
benchmark = Benchmark.measure { run.run; filter.before_replicate }
|
70
91
|
puts "\n time required: #{benchmark}"
|
71
92
|
|
72
93
|
left_fingerprint = {
|
@@ -79,11 +100,7 @@ describe "Big Rep" do
|
|
79
100
|
}
|
80
101
|
left_fingerprint.should == right_fingerprint
|
81
102
|
ensure
|
82
|
-
|
83
|
-
initializer.drop_trigger database, 'big_rep'
|
84
|
-
session.send(database).execute "delete from big_rep"
|
85
|
-
session.send(database).execute "delete from rr_pending_changes"
|
86
|
-
end
|
103
|
+
cleanup session, initializer
|
87
104
|
end
|
88
105
|
end
|
89
106
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'rake'
|
3
3
|
require 'benchmark'
|
4
4
|
|
5
|
-
require File.dirname(__FILE__) + '/../sim_helper'
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/../sim_helper')
|
6
6
|
|
7
7
|
# Prepares the database schema for the performance tests.
|
8
8
|
def prepare_schema
|
@@ -32,20 +32,20 @@ BIG_SCAN_MODIFIED = BIG_SCAN_SAME + 3
|
|
32
32
|
BIG_SCAN_LEFT_ONLY = BIG_SCAN_MODIFIED + 1 # difference to 100% will be right_only records
|
33
33
|
|
34
34
|
def big_scan_columns
|
35
|
-
|
36
|
-
unless
|
35
|
+
@big_scan_columns ||= nil
|
36
|
+
unless @big_scan_columns
|
37
37
|
session = RR::Session.new
|
38
|
-
|
38
|
+
@big_scan_columns = session.left.column_names('big_scan')
|
39
39
|
end
|
40
|
-
|
40
|
+
@big_scan_columns
|
41
41
|
end
|
42
42
|
|
43
43
|
def text_columns
|
44
|
-
|
44
|
+
@text_columns ||= big_scan_columns.select {|column_name| column_name =~ /^text/}
|
45
45
|
end
|
46
46
|
|
47
47
|
def number_columns
|
48
|
-
|
48
|
+
@number_columns ||= big_scan_columns.select {|column_name| column_name =~ /^number/}
|
49
49
|
end
|
50
50
|
|
51
51
|
def random_attributes
|
@@ -193,37 +193,17 @@ namespace :sims do
|
|
193
193
|
|
194
194
|
desc "Runs the big_scan simulation"
|
195
195
|
task :scan do
|
196
|
-
|
197
|
-
Spec::Runner::OptionParser.parse(
|
198
|
-
['--options', "spec/spec.opts", "./sims/performance/big_scan_spec.rb"],
|
199
|
-
$stdout, $stderr))
|
196
|
+
system "rspec sims/performance/big_scan_spec.rb"
|
200
197
|
end
|
201
198
|
|
202
199
|
desc "Runs the big_sync simulation"
|
203
200
|
task :sync do
|
204
|
-
|
205
|
-
Spec::Runner::OptionParser.parse(
|
206
|
-
['--options', "spec/spec.opts", "./sims/performance/big_sync_spec.rb"],
|
207
|
-
$stdout, $stderr))
|
201
|
+
system "rspec sims/performance/big_sync_spec.rb"
|
208
202
|
end
|
209
203
|
|
210
204
|
desc "Runs the big_rep simulation"
|
211
205
|
task :rep do
|
212
|
-
|
213
|
-
Spec::Runner::OptionParser.parse(
|
214
|
-
['--options', "spec/spec.opts", "./sims/performance/big_rep_spec.rb"],
|
215
|
-
$stdout, $stderr))
|
216
|
-
end
|
217
|
-
|
218
|
-
begin
|
219
|
-
require 'ruby-prof/task'
|
220
|
-
RubyProf::ProfileTask.new do |t|
|
221
|
-
t.test_files = FileList["./sims/performance/*_spec.rb"]
|
222
|
-
t.output_dir = 'profile'
|
223
|
-
t.printer = :flat
|
224
|
-
t.min_percent = 1
|
225
|
-
end
|
226
|
-
rescue LoadError
|
206
|
+
system "rspec sims/performance/big_rep_spec.rb"
|
227
207
|
end
|
228
208
|
end
|
229
|
-
end
|
209
|
+
end
|
data/tasks/database.rake
CHANGED
@@ -2,19 +2,19 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "../lib/rubyrep"
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rubyrep'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require_relative 'task_helper.rb'
|
6
|
+
require_relative '../config/test_config'
|
7
|
+
require_relative '../spec/spec_helper'
|
8
8
|
|
9
9
|
# Creates the databases for the given configuration hash
|
10
10
|
def create_database(config)
|
11
11
|
begin
|
12
12
|
RR::ConnectionExtenders.db_connect(config)
|
13
|
-
rescue
|
13
|
+
rescue StandardError, LoadError
|
14
14
|
case config[:adapter]
|
15
15
|
when 'postgresql'
|
16
16
|
`createdb "#{config[:database]}" -E utf8`
|
17
|
-
when '
|
17
|
+
when 'mysql2'
|
18
18
|
@charset = ENV['CHARSET'] || 'utf8'
|
19
19
|
@collation = ENV['COLLATION'] || 'utf8_general_ci'
|
20
20
|
begin
|
@@ -62,11 +62,11 @@ def create_postgres_schema(config)
|
|
62
62
|
end
|
63
63
|
execute "insert into rr_simple(id, name) values(1, 'bla')"
|
64
64
|
|
65
|
-
create_table :rr_referenced
|
65
|
+
create_table :rr_referenced do |t|
|
66
66
|
t.column :name, :string
|
67
67
|
end
|
68
68
|
|
69
|
-
create_table :rr_referencing
|
69
|
+
create_table :rr_referencing do |t|
|
70
70
|
t.column :rr_referenced_id, :integer
|
71
71
|
end
|
72
72
|
|
@@ -166,11 +166,11 @@ def create_sample_schema(database, config)
|
|
166
166
|
PRIMARY KEY (first_id, second_id)
|
167
167
|
end_sql
|
168
168
|
|
169
|
-
create_table :referenced_table2
|
169
|
+
create_table :referenced_table2 do |t|
|
170
170
|
t.column :name, :string
|
171
171
|
end
|
172
172
|
|
173
|
-
create_table :referencing_table
|
173
|
+
create_table :referencing_table do |t|
|
174
174
|
t.column :first_fk, :integer
|
175
175
|
t.column :second_fk, :integer
|
176
176
|
t.column :third_fk, :integer
|
@@ -367,7 +367,7 @@ def drop_sample_schema(config)
|
|
367
367
|
end
|
368
368
|
|
369
369
|
class ExtenderCombinedKey < ActiveRecord::Base
|
370
|
-
|
370
|
+
self.table_name = "extender_combined_key"
|
371
371
|
include CreateWithKey
|
372
372
|
end
|
373
373
|
|
@@ -376,17 +376,17 @@ class ScannerRecords < ActiveRecord::Base
|
|
376
376
|
end
|
377
377
|
|
378
378
|
class ScannerLeftRecordsOnly < ActiveRecord::Base
|
379
|
-
|
379
|
+
self.table_name = "scanner_left_records_only"
|
380
380
|
include CreateWithKey
|
381
381
|
end
|
382
382
|
|
383
383
|
class ExtenderOneRecord < ActiveRecord::Base
|
384
|
-
|
384
|
+
self.table_name = "extender_one_record"
|
385
385
|
include CreateWithKey
|
386
386
|
end
|
387
387
|
|
388
388
|
class ExtenderTypeCheck < ActiveRecord::Base
|
389
|
-
|
389
|
+
self.table_name = "extender_type_check"
|
390
390
|
include CreateWithKey
|
391
391
|
end
|
392
392
|
|
@@ -516,4 +516,4 @@ namespace :db do
|
|
516
516
|
end
|
517
517
|
end
|
518
518
|
end
|
519
|
-
end
|
519
|
+
end
|
data/tasks/java.rake
CHANGED
@@ -2,15 +2,28 @@ namespace :deploy do
|
|
2
2
|
|
3
3
|
desc "Create the java installation package"
|
4
4
|
task :java do
|
5
|
-
|
5
|
+
jruby_version='9.1.10.0'
|
6
|
+
pkg_name = "rubyrep-#{RR::VERSION}"
|
6
7
|
|
7
8
|
system "rm -rf /tmp/#{pkg_name}"
|
8
9
|
system "mkdir /tmp/#{pkg_name}"
|
9
10
|
system "git archive master |tar -x -C /tmp/#{pkg_name}"
|
10
|
-
system "
|
11
|
-
system "
|
12
|
-
system "
|
13
|
-
system "
|
11
|
+
system "curl -o /tmp/#{pkg_name}/jruby.tar.gz https://s3.amazonaws.com/jruby.org/downloads/#{jruby_version}/jruby-bin-#{jruby_version}.tar.gz"
|
12
|
+
system "tar -C /tmp/#{pkg_name} -xzf /tmp/#{pkg_name}/jruby.tar.gz"
|
13
|
+
system "mv /tmp/#{pkg_name}/jruby-#{jruby_version} /tmp/#{pkg_name}/jruby"
|
14
|
+
system "rm /tmp/#{pkg_name}/jruby.tar.gz"
|
15
|
+
system %[
|
16
|
+
cd /tmp/#{pkg_name}
|
17
|
+
export PATH=`pwd`/jruby/bin:$PATH
|
18
|
+
unset GEM_HOME
|
19
|
+
unset GEM_PATH
|
20
|
+
gem install activerecord -v 4.2.8
|
21
|
+
gem install jdbc-mysql -v 5.1.42
|
22
|
+
gem install jdbc-postgres -v 9.4.1206
|
23
|
+
gem install activerecord-jdbcmysql-adapter -v 1.3.23
|
24
|
+
gem install activerecord-jdbcpostgresql-adapter -v 1.3.23
|
25
|
+
gem install awesome_print -v 1.7.0
|
26
|
+
]
|
14
27
|
system "cd /tmp; rm -f #{pkg_name}.zip; zip -r #{pkg_name}.zip #{pkg_name} >/dev/null"
|
15
28
|
system "mkdir -p pkg"
|
16
29
|
system "cp /tmp/#{pkg_name}.zip pkg"
|
data/tasks/rspec.rake
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'rspec'
|
3
3
|
rescue LoadError
|
4
4
|
require 'rubygems'
|
5
|
-
require '
|
5
|
+
require 'rspec'
|
6
6
|
end
|
7
7
|
begin
|
8
|
-
|
8
|
+
require 'rspec/core/rake_task'
|
9
9
|
rescue LoadError
|
10
10
|
puts <<-EOS
|
11
11
|
To use rspec for testing you must install rspec gem:
|
@@ -14,51 +14,31 @@ To use rspec for testing you must install rspec gem:
|
|
14
14
|
exit(0)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
17
|
+
task :spec do
|
18
|
+
system "rspec spec"
|
21
19
|
end
|
22
20
|
|
23
21
|
namespace :spec do
|
24
22
|
desc "Generate specdocs for examples for inclusion in RDoc"
|
25
|
-
|
26
|
-
|
27
|
-
t.spec_opts = ["--format", "specdoc"]
|
23
|
+
task :docs do
|
24
|
+
system 'rspec --format documentation spec'
|
28
25
|
end
|
29
26
|
|
30
|
-
desc "Run the specs with
|
31
|
-
|
32
|
-
|
33
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
34
|
-
t.rcov = true
|
35
|
-
t.rcov_opts = [
|
36
|
-
'--exclude', 'tasks/,spec/,gems/\(?!rubyrep\)',
|
37
|
-
'--xrefs'
|
38
|
-
]
|
27
|
+
desc "Run the specs with coverage"
|
28
|
+
task :cov do
|
29
|
+
system 'COVERAGE=true rspec spec'
|
39
30
|
end
|
40
|
-
|
31
|
+
|
41
32
|
desc "Run the specs for all supported databases"
|
42
33
|
task :all_dbs do
|
43
34
|
[:postgres, :mysql].each do |test_db|
|
44
35
|
puts "Running specs for #{test_db}"
|
45
|
-
system "bash -c 'RR_TEST_DB=#{test_db}
|
36
|
+
system "bash -c 'RR_TEST_DB=#{test_db} rspec spec'"
|
46
37
|
end
|
47
38
|
end
|
48
39
|
|
49
40
|
desc "Run the specs for all supported databases and ruby platforms"
|
50
41
|
task :all_rubies do
|
51
|
-
system %(rvm
|
52
|
-
end
|
53
|
-
|
54
|
-
begin
|
55
|
-
require 'ruby-prof/task'
|
56
|
-
RubyProf::ProfileTask.new do |t|
|
57
|
-
t.test_files = FileList['spec/*_spec.rb']
|
58
|
-
t.output_dir = 'profile'
|
59
|
-
t.printer = :flat
|
60
|
-
t.min_percent = 1
|
61
|
-
end
|
62
|
-
rescue LoadError
|
42
|
+
system %(rvm ruby@rubyrep,jruby@rubyrep do bash -c 'for db in postgres mysql; do echo "`rvm current` - $db:"; RR_TEST_DB=$db rspec spec; done')
|
63
43
|
end
|
64
|
-
end
|
44
|
+
end
|
data/tasks/stats.rake
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
require 'code_statistics' #
|
3
|
-
desc "Report code statistics (KLOCs, etc)"
|
4
|
-
task :stats do
|
5
|
-
STATS_DIRECTORIES = [
|
6
|
-
%w(Libraries lib/),
|
7
|
-
%w(Unit\ tests spec/),
|
8
|
-
%w(Integration\ tests sims/)
|
9
|
-
].collect { |name, dir| [ name, "#{File.dirname(__FILE__)}/../#{dir}" ] }.select { |name, dir| File.directory?(dir) }
|
10
|
-
|
11
|
-
desc "Report code statistics (KLOCs, etc) from the application"
|
12
|
-
task :stats do
|
13
|
-
require 'code_statistics'
|
14
|
-
CodeStatistics.new(*STATS_DIRECTORIES).to_s
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
2
|
+
require 'code_statistics' # install this gem to get a task 'stats'
|
18
3
|
rescue LoadError
|
19
4
|
end
|