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


Java GenericContainer类代码示例

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


GenericContainer类属于org.testcontainers.containers包,在下文中一共展示了GenericContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: whenDockerClientCantBeCreatedAnAssumptionExceptionIsThrown

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Test
public void whenDockerClientCantBeCreatedAnAssumptionExceptionIsThrown() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {
    destroyDockerClientFactoryInstance();
    GenericContainerRule genericContainerRule = new GenericContainerRule(() -> new GenericContainer()).assumeDockerIsPresent();
    boolean assumptionExceptionOccurred = false;
    try {
        genericContainerRule.apply(null,null).evaluate();
    } catch (AssumptionViolatedException ave) {
        assumptionExceptionOccurred = true;
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    } finally {
        unDestroyDockerClientFactoryInstance();
    }
    assertThat(assumptionExceptionOccurred).isTrue().as("AssumptionException was thrown");
}
 
开发者ID:npetzall,项目名称:testcontainers-junit,代码行数:17,代码来源:GenericContainerRuleIT.java

示例3: configureArquillianForRemoteWildfly

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
private void configureArquillianForRemoteWildfly(GenericContainer dockerContainer, ContainerRegistry registry) {
   Integer wildflyHttpPort = dockerContainer.getMappedPort(WILDFLY_HTTP_PORT);
   Integer wildflyManagementPort = dockerContainer.getMappedPort(WILDFLY_MANAGEMENT_PORT);

   String containerIpAddress = dockerContainer.getContainerIpAddress();
   Container arquillianContainer = registry.getContainers().iterator().next();
   ContainerDef containerConfiguration = arquillianContainer.getContainerConfiguration();
   containerConfiguration.property(ContainerConfiguration.MANAGEMENT_ADDRESS_KEY, containerIpAddress);
   containerConfiguration.property(ContainerConfiguration.MANAGEMENT_PORT_KEY,
      String.valueOf(wildflyManagementPort));
   containerConfiguration.property(ContainerConfiguration.USERNAME_KEY, "admin");
   containerConfiguration.property(ContainerConfiguration.PASSWORD_KEY, "Admin#007");

   ProtocolDef protocolConfiguration = arquillianContainer
      .getProtocolConfiguration(new ProtocolDescription(ServletProtocolDefinition.NAME));
   protocolConfiguration.property(ServletProtocolDefinition.HOST_KEY, containerIpAddress);
   protocolConfiguration.property(ServletProtocolDefinition.PORT_KEY, String.valueOf(wildflyHttpPort));
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:19,代码来源:WildflyMariaDBDockerExtension.java

示例4: compute

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Override protected ElasticsearchHttpStorage compute() {
  try {
    container = new GenericContainer(image)
        .withExposedPorts(9200)
        .withEnv("ES_JAVA_OPTS", "-Dmapper.allow_dots_in_name=true -Xms512m -Xmx512m")
        .waitingFor(new HttpWaitStrategy().forPath("/"));
    container.start();
    if (Boolean.valueOf(System.getenv("ES_DEBUG"))) {
      container.followOutput(new Slf4jLogConsumer(LoggerFactory.getLogger(image)));
    }
    System.out.println("Starting docker image " + image);
  } catch (RuntimeException e) {
    // Ignore
  }

  ElasticsearchHttpStorage result = computeStorageBuilder().build();
  CheckResult check = result.check();
  if (check.ok()) {
    return result;
  } else {
    throw new AssumptionViolatedException(check.error().getMessage(), check.error());
  }
}
 
开发者ID:openzipkin,项目名称:zipkin-dependencies,代码行数:24,代码来源:LazyElasticsearchHttpStorage.java

示例5: ParameterizedDockerfileContainerTest

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
public ParameterizedDockerfileContainerTest(String baseImage, String expectedVersion) {
    container = new GenericContainer(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> {
            builder
                    .from(baseImage)
                    // Could potentially customise the image here, e.g. adding files, running
                    //  commands, etc.
                    .build();
        })).withCommand("top");
    this.expectedVersion = expectedVersion;
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:11,代码来源:ParameterizedDockerfileContainerTest.java

示例6: createContainerCmdHookTest

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Test
public void createContainerCmdHookTest() {
    // Use random name to avoid the conflicts between the tests
    String randomName = Base58.randomString(5);
    try(
            GenericContainer container = new GenericContainer<>("redis:3.0.2")
                    .withCommand("redis-server", "--help")
                    .withCreateContainerCmdModifier(cmd -> cmd.withName("overrideMe"))
                    // Preserves the order
                    .withCreateContainerCmdModifier(cmd -> cmd.withName(randomName))
                    // Allows to override pre-configured values by GenericContainer
                    .withCreateContainerCmdModifier(cmd -> cmd.withCmd("redis-server", "--port", "6379"))
    ) {
        container.start();

        assertEquals("Name is configured", "/" + randomName, container.getContainerInfo().getName());
        assertEquals("Command is configured", "[redis-server, --port, 6379]", Arrays.toString(container.getContainerInfo().getConfig().getCmd()));
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:20,代码来源:GenericContainerRuleTest.java

示例7: copyToContainerTest

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Test
public void copyToContainerTest() throws Exception {
    final File tempResultFolder = Files.createTempDir();

    try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
                .withCommand("top")){
        
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt",
                tempResultFolder.getAbsolutePath() + "/test_copy_to_container.txt");

        File expectedFile = new File(mountableFile.getResolvedPath());
        File actualFile = new File(tempResultFolder.getAbsolutePath() + "/test_copy_to_container.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile,actualFile));
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:19,代码来源:GenericContainerRuleTest.java

示例8: shouldCopyFileFromContainerTest

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Test
public void shouldCopyFileFromContainerTest() throws IOException, InterruptedException {
    final File tempResultFolder = Files.createTempDir();

    try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")) {

        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt",
                tempResultFolder.getAbsolutePath() + "/test_copy_from_container.txt");

        File expectedFile = new File(mountableFile.getResolvedPath());
        File actualFile = new File(tempResultFolder.getAbsolutePath() + "/test_copy_from_container.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile,actualFile));
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:19,代码来源:GenericContainerRuleTest.java

示例9: 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

示例10: redisContainer

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Bean(initMethod = "start")
public GenericContainer redisContainer() {
	return new GenericContainer(REDIS_DOCKER_IMAGE) {

		@Override
		public void close() {
			super.close();
			try {
				this.dockerClient.close();
			}
			catch (IOException ignored) {
			}
		}

	}.withExposedPorts(6379);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:17,代码来源:EmbeddedRedisConfig.java

示例11: before

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@BeforeClass
void before() throws Exception {
  String gitlabVersion = System.getenv("GITLAB_VERSION");
  if (gitlabVersion == null)
    gitlabVersion = "9.3.3-ce.0";

  final int gitlabPort = 80;

  gitlab = new GenericContainer<>("gitlab/gitlab-ce:" + gitlabVersion)
      .withEnv("GITLAB_ROOT_PASSWORD", rootPassword)
      .withExposedPorts(gitlabPort)
      .waitingFor(Wait.forHttp("/users/sign_in")
          .withStartupTimeout(Duration.of(10, ChronoUnit.MINUTES)));
  gitlab.start();
  gitlabUrl = "http://" + gitlab.getContainerIpAddress() + ":" + gitlab.getMappedPort(gitlabPort);

  rootToken = createToken(root, rootPassword, true);

  final GitlabAPI rootAPI = GitLabContext.connect(gitlabUrl, rootToken);

  final GitlabUser gitlabUser = rootAPI.createUser("[email protected]", userPassword, user, user, null, null, null, null, null, null, null, null, false, null, true);
  Assert.assertNotNull(gitlabUser);

  final GitlabGroup group = rootAPI.createGroup("testGroup");
  Assert.assertNotNull(group);

  Assert.assertNotNull(rootAPI.addGroupMember(group.getId(), gitlabUser.getId(), GitlabAccessLevel.Developer));

  gitlabProject = createGitlabProject(rootAPI, group, "test", false);
  gitlabPublicProject = createGitlabProject(rootAPI, group, "publik", true);
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:32,代码来源:GitLabIntegrationTest.java

示例12: startConsulTestContainer

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@BeforeClass
public static void startConsulTestContainer() {
    consulContainer = new GenericContainer("quay.io/coreos/etcd:v3.2.4")
            .withExposedPorts(2379)
            .withCommand("etcd",
                    "--advertise-client-urls", "http://0.0.0.0:2379",
                    "--listen-client-urls", "http://0.0.0.0:2379"
            );

    consulContainer.start();
    consulContainer.followOutput(new Slf4jLogConsumer(logger).withPrefix("etcd"));
}
 
开发者ID:conf4j,项目名称:conf4j,代码行数:13,代码来源:EtcdFileConfigurationSourceTest.java

示例13: readSecondSecretPathWithCli

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@Test
public void readSecondSecretPathWithCli() throws IOException, InterruptedException {
    GenericContainer.ExecResult result = vaultContainer.execInContainer("vault",
            "read", "secret/testing2");
    String output = result.getStdout();
    assertThat(output, containsString("password1"));
    assertThat(output, containsString("password2"));
    assertThat(output, containsString("password3"));
    assertThat(output, containsString("password4"));
}
 
开发者ID:testcontainers,项目名称:testcontainers-java-module-vault,代码行数:11,代码来源:VaultContainerTest.java

示例14: beforeClass

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
  network = Network.newNetwork();
  elasticsearch = new GenericContainer<>("docker.elastic.co/elasticsearch/elasticsearch:5.6.1")
      .withNetwork(network)
      .withNetworkAliases("elasticsearch")
      .waitingFor(Wait.forHttp("/"))
      .withExposedPorts(9200, 9300)
      .withEnv("xpack.security.enabled", "false")
      .withEnv("discovery.type", "single-node")
      .withEnv("network.bind_host", "elasticsearch")
      .withEnv("network.host", "_site_")
      .withEnv("network.publish_host", "_local_");
  elasticsearch.start();

  jaegerCollector = new GenericContainer<>("jaegertracing/jaeger-collector:latest")
      .withNetwork(network)
      .withEnv("SPAN_STORAGE_TYPE", "elasticsearch")
      .withEnv("ES_SERVER_URLS", "http://elasticsearch:9200")
      .withEnv("COLLECTOR_ZIPKIN_HTTP_PORT", "9411")
      .withEnv("COLLECTOR_QUEUE_SIZE", "100000")
      .waitingFor(Wait.forHttp("/").forStatusCode(204))
      // the first one is health check
      .withExposedPorts(14269, 14268, 9411);
  jaegerCollector.start();

  jaegerQuery = new GenericContainer<>("jaegertracing/jaeger-query:latest")
      .withEnv("SPAN_STORAGE_TYPE", "elasticsearch")
      .withEnv("ES_SERVER_URLS", "http://elasticsearch:9200")
      .withNetwork(network)
      .waitingFor(Wait.forHttp("/").forStatusCode(204))
      .withExposedPorts(16687, 16686);
  jaegerQuery.start();

  collectorUrl = String.format("http://%s:%d", jaegerCollector.getContainerIpAddress(), jaegerCollector.getMappedPort(14268));
  zipkinCollectorUrl = String.format("http://%s:%d", jaegerCollector.getContainerIpAddress(), jaegerCollector.getMappedPort(9411));
  queryUrl = String.format("http://%s:%d", jaegerQuery.getContainerIpAddress(), jaegerQuery.getMappedPort(16686));
}
 
开发者ID:jaegertracing,项目名称:spark-dependencies,代码行数:39,代码来源:ElasticsearchDependenciesJobTest.java

示例15: afterClass

import org.testcontainers.containers.GenericContainer; //导入依赖的package包/类
@AfterClass
public static void afterClass() {
  Optional.of(jaegerCollector).ifPresent(GenericContainer::close);
  Optional.of(jaegerQuery).ifPresent(GenericContainer::close);
  Optional.of(elasticsearch).ifPresent(GenericContainer::close);
  Optional.of(network).ifPresent(Network::close);
}
 
开发者ID:jaegertracing,项目名称:spark-dependencies,代码行数:8,代码来源:ElasticsearchDependenciesJobTest.java


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