testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.02k stars 1.65k forks source link

Image Pulled, Container doesn't start #310

Closed LiamMaru closed 7 years ago

LiamMaru commented 7 years ago

Love the sound of this tool but I can't get it to work. Given the following test:

public class ApnicLdapStorageProviderTestIT extends TestCase {

    @ClassRule
    public static GenericContainer redis =
        new GenericContainer("redis:3.0.2")
                .withExposedPorts(6379);

    @Test
    public void testSomething() throws Exception {
        String addr = String.format("%s:%s", redis.getContainerIpAddress(), redis.getMappedPort(6379));
        assertTrue(!addr.equals("not this"));
    }       
}

I receive receive:

testSomething(org.apnic.keycloak.ApnicLdapStorageProviderTestIT)  Time elapsed: 0.006 sec  <<< ERROR!
java.lang.IllegalStateException: Mapped port can only be obtained after the container is started
    at org.apnic.keycloak.ApnicLdapStorageProviderTestIT.testSomething(ApnicLdapStorageProviderTestIT.java:24)

The image is being pulled but not run. Any ideas?

bsideup commented 7 years ago

extends TestCase

Are you sure you use JUnit 4?

LiamMaru commented 7 years ago

@bsideup

Yes, version 4.1.2.

bsideup commented 7 years ago

@LiamMaru may I ask you to provide a full log?

rnorth commented 7 years ago

I was going to ask the same thing. I'm also wondering, perhaps, if there could be a dependency clash (i.e. more than one JUnit JAR on the classpath).

rnorth commented 7 years ago

@LiamMaru did you manage to get any further with this? Please let us know if we can help.

LiamMaru commented 7 years ago

Hey @rnorth, apologies re. delay. Having some digging, I've found and correct a dependency clash that's resolved this issue. Thanks for you help guys.

rnorth commented 7 years ago

Great! Glad to hear you were able to solve it. I'll close this ticket then.