You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are use cases which require configuring the actual JDBC driverClassName on DataSource pool implementation. One such example that I ran into recently is using a HikariCP pool with MySQL 8 Testcontainer (related #736).
This PR changes the visibility of JdbcDatabaseContainer#getDriverClassName method to public. With this change, the driverClassName of the container can be reused when configuring the DataSource, rather than having to manually specify it.
There's an additional commit that adds a test to demonstrate the described problem - without setting driverClassName on HikariConfig this test fails (due to wrong driver being used implicitly) with the following stacktrace:
com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:544)
at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
at org.testcontainers.junit.SimpleMySQLTest.performQuery(SimpleMySQLTest.java:139)
at org.testcontainers.junit.SimpleMySQLTest.testMySQL8(SimpleMySQLTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.sql.SQLException: Unknown system variable 'tx_isolation'
Query is : SELECT @@tx_isolation
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:136)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
at org.mariadb.jdbc.MariaDbStatement.executeQueryEpilog(MariaDbStatement.java:242)
at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:270)
at org.mariadb.jdbc.MariaDbStatement.executeQuery(MariaDbStatement.java:383)
at org.mariadb.jdbc.MariaDbConnection.getTransactionIsolation(MariaDbConnection.java:767)
at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:446)
at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542)
... 28 more
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Unknown system variable 'tx_isolation'
Query is : SELECT @@tx_isolation
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:939)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:604)
at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:261)
... 32 more
jdbcUrl
This property directs HikariCP to use "DriverManager-based" configuration. We feel that DataSource-based configuration (above) is superior for a variety of reasons (see below), but for many deployments there is little significant difference. When using this property with "old" drivers, you may also need to set the driverClassName property, but try it first without. Note that if this property is used, you may still use DataSource properties to configure your driver and is in fact recommended over driver parameters specified in the URL itself. Default: none
It was due to the upgraded MySQL JDBC driver. I've just reverted it to originally used 5.1.45 as MySQL 8 appears to work with it just fine and the test now are passing, at least for me locally.
It appears that the new MySQL JDBC driver (8.0.11) is more strict and doesn't like dummy URL elements like ;TEST=TOMCAT_WITH_CLASSNAME which are used throughout the JDBCDriverWithPoolTest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are use cases which require configuring the actual JDBC
driverClassNameonDataSourcepool implementation. One such example that I ran into recently is using a HikariCP pool with MySQL 8 Testcontainer (related #736).This PR changes the visibility of
JdbcDatabaseContainer#getDriverClassNamemethod topublic. With this change, thedriverClassNameof the container can be reused when configuring theDataSource, rather than having to manually specify it.There's an additional commit that adds a test to demonstrate the described problem - without setting
driverClassNameonHikariConfigthis test fails (due to wrong driver being used implicitly) with the following stacktrace: