Last active
September 6, 2019 07:04
-
-
Save errandir/ba9b8273874bc43cea37046d5980bfdc to your computer and use it in GitHub Desktop.
testcontainers-java/issues/572
This file contains 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
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure | |
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) | |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) | |
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) | |
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) | |
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990) | |
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342) | |
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2197) | |
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230) | |
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025) | |
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778) | |
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) | |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) | |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) | |
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) | |
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) | |
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386) | |
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330) | |
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:428) | |
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:136) | |
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:107) | |
at my.test.TestClass.basic(TestClass.java:23) | |
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.runners.Suite.runChild(Suite.java:128) | |
at org.junit.runners.Suite.runChild(Suite.java:27) | |
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.net.ConnectException: Connection refused (Connection refused) | |
at java.net.PlainSocketImpl.socketConnect(Native Method) | |
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) | |
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) | |
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) | |
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) | |
at java.net.Socket.connect(Socket.java:589) | |
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211) | |
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301) | |
... 46 more |
This file contains 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
17:57:53,821 INFO [org.testcontainers.dockerclient.DockerClientProviderStrategy] Loaded org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy from ~/.testcontainers.properties, will try it first | |
17:57:53,855 INFO [org.testcontainers.dockerclient.DockerClientProviderStrategy] Will use 'okhttp' transport | |
17:57:54,403 INFO [org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy] Found docker client settings from environment | |
17:57:54,418 INFO [org.testcontainers.dockerclient.DockerClientProviderStrategy] Found Docker environment with Environment variables, system properties and defaults. Resolved: | |
dockerHost=unix:///var/run/docker.sock | |
apiVersion='{UNKNOWN_VERSION}' | |
registryUrl='https://index.docker.io/v1/' | |
registryUsername='errandir' | |
registryPassword='null' | |
registryEmail='null' | |
dockerConfig='DefaultDockerClientConfig[dockerHost=unix:///var/run/docker.sock,registryUsername=errandir,registryPassword=<null>,registryEmail=<null>,registryUrl=https://index.docker.io/v1/,dockerConfigPath=/home/errandir/.docker,sslConfig=<null>,apiVersion={UNKNOWN_VERSION},dockerConfig=<null>]' | |
17:57:54,420 INFO [org.testcontainers.DockerClientFactory] Docker host IP address is localhost | |
17:57:54,780 INFO [org.testcontainers.DockerClientFactory] Connected to docker: | |
Server Version: 18.06.1-ce | |
API Version: 1.38 | |
Operating System: Ubuntu Core 16 | |
Total Memory: 15934 MB | |
17:57:56,354 INFO [org.testcontainers.DockerClientFactory] Ryuk started - will monitor and terminate Testcontainers containers on JVM exit | |
ℹ︎ Checking the system... | |
✔ Docker version should be at least 1.6.0 | |
✔ Docker environment should have more than 2GB free disk space | |
17:57:56,652 INFO [🐳 [mysql:5.7.22]] Creating container for image: mysql:5.7.22 | |
17:57:56,769 INFO [🐳 [mysql:5.7.22]] Starting container with ID: 1d14a4ee9fce353a9f8e4bced5f968f257647716ac2b314df45040a70d78dd3c | |
17:57:57,172 INFO [🐳 [mysql:5.7.22]] Container mysql:5.7.22 is starting: 1d14a4ee9fce353a9f8e4bced5f968f257647716ac2b314df45040a70d78dd3c | |
17:57:57,181 INFO [🐳 [mysql:5.7.22]] Waiting for database connection to become available at jdbc:mysql://localhost:32787/test using query 'SELECT 1' | |
17:59:57,182 INFO [🐳 [mysql:5.7.22]] Container is started (JDBC URL: jdbc:mysql://localhost:32787/test) | |
17:59:57,182 INFO [🐳 [mysql:5.7.22]] Container mysql:5.7.22 started |
This file contains 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
package my.test; | |
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; | |
import com.mysql.jdbc.log.Slf4JLogger; | |
import org.testcontainers.containers.MySQLContainer; | |
import javax.sql.DataSource; | |
import java.sql.SQLException; | |
public class TestClass { | |
public static void main(String[] args) throws SQLException { | |
MySQLContainer container = new MySQLContainer() {{ | |
start(); | |
}}; | |
DataSource testDataSource = new MysqlDataSource() {{ | |
setURL(container.getJdbcUrl()); | |
setUser(container.getUsername()); | |
setPassword(container.getPassword()); | |
setLoggerClassName(Slf4JLogger.class.getName()); | |
setUseSSL(false); | |
}}; | |
testDataSource.getConnection(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment