Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JdbcDatabaseContainer#getDriverClassName public #743

Merged
merged 2 commits into from Jun 22, 2018
Merged

Make JdbcDatabaseContainer#getDriverClassName public #743

merged 2 commits into from Jun 22, 2018

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Jun 12, 2018

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

@vpavic
Copy link
Contributor Author

vpavic commented Jun 12, 2018

Also see the remark from the HikariCP's documentation on configuration essentials:

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

@bsideup
Copy link
Member

bsideup commented Jun 14, 2018

@vpavic do you have any clue why the tests are failing? o_O

@vpavic
Copy link
Contributor Author

vpavic commented Jun 14, 2018

It could be due to the upgraded MySQL JDBC driver. I'll look into it, wanted to see if the proposed change is OK for you first.

@vpavic
Copy link
Contributor Author

vpavic commented Jun 14, 2018

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.

Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll merge it.
We might need to look into the MySQL JDBC driver version 8.0.11 in the future though.

@kiview kiview merged commit f0e2072 into testcontainers:master Jun 22, 2018
@vpavic vpavic deleted the driver-class-name-visibility branch June 22, 2018 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants