当前位置: 首页>>代码示例>>Java>>正文


Java GenericContainer.start方法代码示例

本文整理汇总了Java中org.testcontainers.containers.GenericContainer.start方法的典型用法代码示例。如果您正苦于以下问题:Java GenericContainer.start方法的具体用法?Java GenericContainer.start怎么用?Java GenericContainer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.testcontainers.containers.GenericContainer的用法示例。


在下文中一共展示了GenericContainer.start方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: simpleRecursiveFileTest

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
@Test
public void simpleRecursiveFileTest() throws TimeoutException {

    WaitingConsumer wait = new WaitingConsumer();

    final ToStringConsumer toString = new ToStringConsumer();

    GenericContainer container = new GenericContainer(
            new ImageFromDockerfile()
                    .withDockerfileFromBuilder(builder ->
                            builder.from("alpine:3.3")
                                    .copy("/tmp/foo", "/foo")
                                    .cmd("cat /foo/src/test/resources/test-recursive-file.txt")
                                    .build()
                    ).withFileFromFile("/tmp/foo", new File(".")))  // '.' is expected to be the project base directory, so all source code/resources should be copied in
            .withStartupCheckStrategy(new OneShotStartupCheckStrategy())
            .withLogConsumer(wait.andThen(toString));

    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);

    final String results = toString.toUtf8String();

    assertTrue("The container has a file that was copied in via a recursive copy", results.contains("Used for DirectoryTarResourceTest"));
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:26,代码来源:DirectoryTarResourceTest.java

示例2: testFixedHostPortMapping

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
@Test
    public void testFixedHostPortMapping() throws IOException {
        // first find a free port on the docker host that will work for testing
        GenericContainer portDiscoveryRedis = new GenericContainer("redis:3.0.2").withExposedPorts(REDIS_PORT);
        portDiscoveryRedis.start();
        Integer freePort = portDiscoveryRedis.getMappedPort(REDIS_PORT);
        portDiscoveryRedis.stop();


        // Set up a FixedHostPortGenericContainer as if this were a @Rule
        FixedHostPortGenericContainer redis = new FixedHostPortGenericContainer("redis:3.0.2").withFixedExposedPort(freePort, REDIS_PORT);
        redis.start();

//        Config redisConfig = new Config();
//        redisConfig.useSingleServer().setAddress(redis.getContainerIpAddress() + ":" + freePort);
//        Redisson redisson = Redisson.create(redisConfig);
//
//        redisson.getBucket("test").set("foo");
//
//        assertEquals("The bucket content was successfully set", "foo", redisson.getBucket("test").get());
//        assertEquals("The container returns the fixed port from getMappedPort(...)", freePort, redis.getMappedPort(REDIS_PORT));
    }
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:23,代码来源:FixedHostPortContainerTest.java

示例3: registerInstance

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
/**
 * Method which observes {@link ContainerRegistry}. Gets called by Arquillian at startup time.
 * 
 * @param registry
 *           contains containers defined in arquillian.xml
 * @param serviceLoader
 */
public void registerInstance(@Observes ContainerRegistry registry, ServiceLoader serviceLoader) {
   GenericContainer dockerContainer = new GenericContainer(DOCKER_IMAGE)
      .withExposedPorts(WILDFLY_MANAGEMENT_PORT);
   dockerContainer.start();

   configureArquillianForRemoteWildfly(dockerContainer, registry);

   setupDb(dockerContainer);
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:17,代码来源:WildflyMariaDBDockerExtension.java

示例4: verifyImage

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
protected void verifyImage(ImageFromDockerfile image) {
    GenericContainer container = new GenericContainer(image);

    try {
        container.start();

        pass("Should start from Dockerfile");
    } finally {
        container.stop();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:12,代码来源:DockerfileTest.java

示例5: waitUntilReadyAndSucceed

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
/**
 * Expects that the WaitStrategy returns successfully after connection to a container with a listening port.
 *
 * @param shellCommand the shell command to execute
 */
protected void waitUntilReadyAndSucceed(String shellCommand) {
    final GenericContainer container = startContainerWithCommand(shellCommand);

    // start() blocks until successful or timeout
    container.start();

    assertTrue(String.format("Expected container to be ready after timeout of %sms",
            WAIT_TIMEOUT_MILLIS), ready.get());
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:15,代码来源:AbstractWaitStrategyTest.java

示例6: simpleRecursiveFileWithPermissionTest

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
@Test
public void simpleRecursiveFileWithPermissionTest() throws TimeoutException {

    WaitingConsumer wait = new WaitingConsumer();

    final ToStringConsumer toString = new ToStringConsumer();

    GenericContainer container = new GenericContainer(
            new ImageFromDockerfile()
                    .withDockerfileFromBuilder(builder ->
                            builder.from("alpine:3.3")
                                    .copy("/tmp/foo", "/foo")
                                    .cmd("ls", "-al", "/")
                                    .build()
                    ).withFileFromFile("/tmp/foo", new File("/mappable-resource/test-resource.txt"),
                    0754))
            .withStartupCheckStrategy(new OneShotStartupCheckStrategy())
            .withLogConsumer(wait.andThen(toString));

    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);

    String listing = toString.toUtf8String();

    assertThat("Listing shows that file is copied with mode requested.",
            Arrays.asList(listing.split("\\n")),
            exactlyNItems(1, allOf(containsString("-rwxr-xr--"), containsString("foo"))));
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:29,代码来源:DirectoryTarResourceTest.java

示例7: simpleRecursiveClasspathResourceTest

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
@Test
public void simpleRecursiveClasspathResourceTest() throws TimeoutException {
    // This test combines the copying of classpath resources from JAR files with the recursive TAR approach, to allow JARed classpath resources to be copied in to an image

    WaitingConsumer wait = new WaitingConsumer();

    final ToStringConsumer toString = new ToStringConsumer();

    GenericContainer container = new GenericContainer(
            new ImageFromDockerfile()
                    .withDockerfileFromBuilder(builder ->
                            builder.from("alpine:3.3")
                                    .copy("/tmp/foo", "/foo")
                                    .cmd("ls -lRt /foo")
                                    .build()
                    ).withFileFromClasspath("/tmp/foo", "/recursive/dir"))          // here we use /org/junit as a directory that really should exist on the classpath
            .withStartupCheckStrategy(new OneShotStartupCheckStrategy())
            .withLogConsumer(wait.andThen(toString));

    container.start();
    wait.waitUntilEnd(60, TimeUnit.SECONDS);

    final String results = toString.toUtf8String();

    // ExternalResource.class is known to exist in a subdirectory of /org/junit so should be successfully copied in
    assertTrue("The container has a file that was copied in via a recursive copy from a JAR resource", results.contains("content.txt"));
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:28,代码来源:DirectoryTarResourceTest.java

示例8: filePermissions

import org.testcontainers.containers.GenericContainer; //导入方法依赖的package包/类
@Test
public void filePermissions() throws TimeoutException {

    WaitingConsumer consumer = new WaitingConsumer();

    ImageFromDockerfile image = new ImageFromDockerfile()
            .withFileFromTransferable("/someFile.txt", new Transferable() {
                @Override
                public long getSize() {
                    return 0;
                }

                @Override
                public byte[] getBytes() {
                    return new byte[0];
                }

                @Override
                public String getDescription() {
                    return "test file";
                }

                @Override
                public int getFileMode() {
                    return 0123;
                }


            })
            .withDockerfileFromBuilder(builder -> builder
                    .from("alpine:3.2")
                    .copy("someFile.txt", "/someFile.txt")
                    .cmd("stat -c \"%a\" /someFile.txt")
            );

    GenericContainer container = new GenericContainer(image)
            .withStartupCheckStrategy(new OneShotStartupCheckStrategy())
            .withLogConsumer(consumer);

    try {
        container.start();

        consumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("123"), 5, TimeUnit.SECONDS);
    } finally {
        container.stop();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:48,代码来源:DockerfileTest.java


注:本文中的org.testcontainers.containers.GenericContainer.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。