activerecord-bogacs 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -24,6 +24,8 @@ require 'arjdbc' if defined? JRUBY_VERSION
24
24
  require 'logger'
25
25
  ActiveRecord::Base.logger = Logger.new(STDOUT)
26
26
 
27
+ puts "testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
28
+
27
29
  #shared_pool = ENV['AR_POOL_SHARED'] ? # with AR_POOL_SHARED=true use default
28
30
  # ( ENV['AR_POOL_SHARED'] == 'true' ? shared_pool : ENV['AR_POOL_SHARED'] ) :
29
31
  # shared_pool
@@ -112,13 +114,8 @@ end
112
114
  module ActiveRecord
113
115
  module Bogacs
114
116
 
115
- begin
116
- require 'concurrent/atomic/atomic_reference'
117
- Atomic = Concurrent::AtomicReference
118
- rescue LoadError
119
- require 'atomic'
120
- Atomic = ::Atomic
121
- end
117
+ require 'concurrent/atomic/atomic_reference'
118
+ Atomic = Concurrent::AtomicReference
122
119
 
123
120
  module TestHelper
124
121
 
@@ -161,7 +158,12 @@ module ActiveRecord
161
158
  module_function
162
159
 
163
160
  def current_connection_config
164
- if ActiveRecord::Base.respond_to?(:connection_config)
161
+ connected = ActiveRecord::Base.connection_pool.connected?
162
+ if ActiveRecord::Base.connection.respond_to?(:config)
163
+ ActiveRecord::Base.connection.config.tap do # always an updated config, e.g. after mysql2_connection(config)
164
+ ActiveRecord::Base.connection_pool.disconnect! unless connected # restore pool state to avoid test surprises
165
+ end
166
+ elsif ActiveRecord::Base.respond_to?(:connection_config)
165
167
  ActiveRecord::Base.connection_config
166
168
  else
167
169
  ActiveRecord::Base.connection_pool.spec.config
@@ -226,8 +228,8 @@ module ActiveRecord
226
228
  @@setup_jdbc_context = nil
227
229
 
228
230
  def setup_jdbc_context!
229
- load 'test/jars/tomcat-juli.jar'
230
- load 'test/jars/tomcat-catalina.jar'
231
+ load_jar 'test/jars/tomcat-juli.jar'
232
+ load_jar 'test/jars/tomcat-catalina.jar'
231
233
 
232
234
  java.lang.System.set_property(
233
235
  javax.naming.Context::INITIAL_CONTEXT_FACTORY,
@@ -251,7 +253,7 @@ module ActiveRecord
251
253
  end
252
254
 
253
255
  def build_tomcat_jdbc_data_source(ar_jdbc_config = AR_CONFIG)
254
- load 'test/jars/tomcat-jdbc.jar'
256
+ load_jar 'test/jars/tomcat-jdbc.jar'
255
257
 
256
258
  data_source = org.apache.tomcat.jdbc.pool.DataSource.new
257
259
  configure_dbcp_data_source(data_source, ar_jdbc_config)
@@ -262,7 +264,7 @@ module ActiveRecord
262
264
  end
263
265
 
264
266
  def build_tomcat_dbcp_data_source(ar_jdbc_config = AR_CONFIG)
265
- load 'test/jars/tomcat-dbcp.jar'
267
+ load_jar 'test/jars/tomcat-dbcp.jar'
266
268
 
267
269
  data_source = org.apache.tomcat.dbcp.dbcp.BasicDataSource.new
268
270
  configure_dbcp_data_source(data_source, ar_jdbc_config)
@@ -273,7 +275,7 @@ module ActiveRecord
273
275
  end
274
276
 
275
277
  def build_commons_dbcp_data_source(ar_jdbc_config = AR_CONFIG)
276
- load Dir.glob('test/jars/{commons-dbcp}*.jar').first
278
+ load_jar Dir.glob('test/jars/{commons-dbcp}*.jar').first
277
279
 
278
280
  data_source = org.apache.tomcat.dbcp.dbcp.BasicDataSource.new
279
281
  configure_dbcp_data_source(data_source, ar_jdbc_config)
@@ -299,11 +301,9 @@ module ActiveRecord
299
301
  properties.each { |name, value| db_properties.put(name, value.to_s) }
300
302
  data_source.setDbProperties db_properties
301
303
  else # Tomcat-DBCP / Commons DBCP2
302
- # format of the string must be: [propertyName=property;]
303
- connection_properties = properties.inject('') do
304
- |str, name, val| str << "[#{name}=#{val};]"; str
304
+ properties.each do |name, val|
305
+ data_source.addConnectionProperty name, val.to_s
305
306
  end
306
- data_source.setConnectionProperties connection_properties
307
307
  end
308
308
  end
309
309
  # JDBC pool tunings (some mapped from AR configuration) :
@@ -327,7 +327,7 @@ module ActiveRecord
327
327
  private :configure_dbcp_data_source
328
328
 
329
329
  def build_c3p0_data_source(ar_jdbc_config = AR_CONFIG)
330
- Dir.glob('test/jars/{c3p0,mchange-commons}*.jar').each { |jar| load jar }
330
+ Dir.glob('test/jars/{c3p0,mchange-commons}*.jar').each { |jar| load_jar jar }
331
331
 
332
332
  data_source = com.mchange.v2.c3p0.ComboPooledDataSource.new
333
333
  configure_c3p0_data_source(data_source, ar_jdbc_config)
@@ -373,15 +373,15 @@ module ActiveRecord
373
373
 
374
374
 
375
375
  def build_hikari_data_source(ar_jdbc_config = AR_CONFIG)
376
- unless hikari_jar = Dir.glob('test/jars/HikariCP*.jar').last
376
+ unless hikari_jar = Dir.glob('test/jars/HikariCP*.jar').sort.last
377
377
  raise 'HikariCP jar not found in test/jars directory'
378
378
  end
379
379
  if ( version = File.basename(hikari_jar, '.jar').match(/\-([\w\.\-]$)/) ) && version[1] < '2.3.9'
380
- Dir.glob('test/jars/{javassist,slf4j}*.jar').each { |jar| require jar }
380
+ Dir.glob('test/jars/{javassist,slf4j}*.jar').each { |jar| load_jar jar }
381
381
  else
382
- Dir.glob('test/jars/{slf4j}*.jar').each { |jar| require jar }
382
+ Dir.glob('test/jars/{slf4j}*.jar').each { |jar| load_jar jar }
383
383
  end
384
- require hikari_jar
384
+ load_jar hikari_jar
385
385
 
386
386
  configure_hikari_data_source(ar_jdbc_config)
387
387
  end
@@ -396,7 +396,12 @@ module ActiveRecord
396
396
 
397
397
  case driver
398
398
  when /mysql/i
399
- hikari_config.setDataSourceClassName 'com.mysql.jdbc.jdbc2.optional.MysqlDataSource'
399
+ data_source_class_name = if driver == 'com.mysql.cj.jdbc.Driver'
400
+ 'com.mysql.cj.jdbc.MysqlDataSource' # driver 8.0
401
+ else
402
+ 'com.mysql.jdbc.jdbc2.optional.MysqlDataSource' # old 5.x
403
+ end
404
+ hikari_config.setDataSourceClassName data_source_class_name
400
405
  hikari_config.addDataSourceProperty 'serverName', ar_jdbc_config[:host] || 'localhost'
401
406
  hikari_config.addDataSourceProperty 'databaseName', ar_jdbc_config[:database]
402
407
  hikari_config.addDataSourceProperty 'port', ar_jdbc_config[:port] if ar_jdbc_config[:port]
@@ -407,7 +412,7 @@ module ActiveRecord
407
412
  hikari_config.addDataSourceProperty 'password', ar_jdbc_config[:password]
408
413
  end
409
414
  ( ar_jdbc_config[:properties] || {} ).each do |name, val|
410
- hikari_config.addDataSourceProperty name.to_s, val.to_s
415
+ hikari_config.addDataSourceProperty name.to_s, val.to_s unless name.eql?('useLegacyDatetimeCode')
411
416
  end
412
417
  when /postgres/i
413
418
  hikari_config.setDataSourceClassName 'org.postgresql.ds.PGSimpleDataSource'
@@ -478,6 +483,16 @@ module ActiveRecord
478
483
 
479
484
  def jndi_name; 'jdbc/TestDB' end
480
485
 
486
+ private
487
+
488
+ def load_jar(jar)
489
+ abs_jar = File.expand_path(jar)
490
+ unless File.file?(abs_jar)
491
+ raise "path does not exist or is not a file: #{jar}"
492
+ end
493
+ load abs_jar
494
+ end
495
+
481
496
  end
482
497
  end
483
- end
498
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-bogacs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Bucek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2022-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "<"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.9'
19
- name: concurrent-ruby
18
+ version: '6'
19
+ name: activerecord
20
20
  prerelease: false
21
- type: :development
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.9'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '10.3'
32
+ version: '1.0'
33
+ name: concurrent-ruby
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  name: rake
34
48
  prerelease: false
35
49
  type: :development
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '10.3'
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  requirement: !ruby/object:Gem::Requirement
43
57
  requirements:
@@ -59,6 +73,7 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".github/workflows/test.yml"
62
77
  - ".gitignore"
63
78
  - ".travis.yml"
64
79
  - Gemfile
@@ -112,14 +127,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
127
  - !ruby/object:Gem::Version
113
128
  version: '0'
114
129
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.13
130
+ rubygems_version: 3.1.6
117
131
  signing_key:
118
132
  specification_version: 4
119
- summary: 'Bogacs contains several pool implementations that can be used as a replacement
120
- for ActiveRecord''s built-in pool, e.g. DefaultPool is an upstream tuned version
121
- with an API that is compatible with older AR versions. NOTE: you''ll need concurrent-ruby
122
- or thread_safe gem.'
133
+ summary: Bogacs contains several pool implementations that can be used as a replacement
134
+ for ActiveRecord's built-in pool, e.g. DefaultPool is an upstream tuned version
135
+ with an API that is compatible with older AR versions.
123
136
  test_files:
124
137
  - test/active_record/bogacs/default_pool_test.rb
125
138
  - test/active_record/bogacs/false_pool_test.rb