• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Slf4jLogConsumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Slf4jLogConsumer类属于org.testcontainers.containers.output包,在下文中一共展示了Slf4jLogConsumer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSimple

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Test
public void testSimple() throws SQLException {
    MySQLContainer mysql = (MySQLContainer) new MySQLContainer()
            .withConfigurationOverride("somepath/mysql_conf_override")
            .withLogConsumer(new Slf4jLogConsumer(logger));
    mysql.start();

    try {
        ResultSet resultSet = performQuery(mysql, "SELECT 1");
        int resultSetInt = resultSet.getInt(1);

        assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
    } finally {
        mysql.stop();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:SimpleMySQLTest.java


示例2: testSpecificVersion

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Test
public void testSpecificVersion() throws SQLException {
    MySQLContainer mysqlOldVersion = (MySQLContainer) new MySQLContainer("mysql:5.5")
            .withConfigurationOverride("somepath/mysql_conf_override")
            .withLogConsumer(new Slf4jLogConsumer(logger));
    mysqlOldVersion.start();

    try {
        ResultSet resultSet = performQuery(mysqlOldVersion, "SELECT VERSION()");
        String resultSetString = resultSet.getString(1);

        assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5"));
    } finally {
        mysqlOldVersion.stop();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:17,代码来源:SimpleMySQLTest.java


示例3: compute

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的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


示例4: configure

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Override
protected void configure() {
    super.configure();
    withLogConsumer(new Slf4jLogConsumer(log));
    withExposedPorts(5701);
    setWaitStrategy(Wait.forListeningPort());
}
 
开发者ID:gAmUssA,项目名称:testcontainers-hazelcast,代码行数:8,代码来源:HazelcastTestApp.java


示例5: start

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
public void start() {
    consulContainer.start();
    consulContainer.followOutput(new Slf4jLogConsumer(logger).withPrefix("consul"));
    await("Consul is ready")
            .atMost(10, TimeUnit.SECONDS)
            .until(() -> {
                try {
                    consul.set(Consul.builder().withUrl(getConsulUrl()).build());
                    return true;
                } catch (Exception e) {
                    logger.info("Failed to create consul client, probably consul is not ready yet", e);
                    return false;
                }
            });
}
 
开发者ID:conf4j,项目名称:conf4j,代码行数:16,代码来源:StandaloneConsul.java


示例6: startConsulTestContainer

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的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


示例7: beforeEach

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Override
//  public void beforeEach(ExtensionContext context) throws Exception {
  public void beforeEach(TestExtensionContext context) throws Exception {
    BrowserWebDriverContainer webDriverContainer
        = new BrowserWebDriverContainer()
        .withDesiredCapabilities(DesiredCapabilities.chrome()); // only one per container

    webDriverContainer.start();

    Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LoggerFactory.getLogger(this.getClass()));
    webDriverContainer.followOutput(logConsumer);

    storeTestcontainer().accept(context, webDriverContainer);
    storeWebDriver().accept(context, webDriverContainer::getWebDriver);
  }
 
开发者ID:Java-Publications,项目名称:vaadin-016-helloworld-14,代码行数:16,代码来源:TestcontainersExtension.java


示例8: tailChildContainerLogs

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
private void tailChildContainerLogs() {
    listChildContainers().forEach(container ->
            LogUtils.followOutput(dockerClient,
                    container.getId(),
                    new Slf4jLogConsumer(logger()).withPrefix(container.getNames()[0]),
                    OutputFrame.OutputType.STDOUT,
                    OutputFrame.OutputType.STDERR)
    );
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:10,代码来源:DockerComposeContainer.java


示例9: invoke

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Override
public void invoke() {
    super.start();

    this.followOutput(new Slf4jLogConsumer(logger()));

    // wait for the compose container to stop, which should only happen after it has spawned all the service containers
    logger().info("Docker Compose container is running for command: {}", Joiner.on(" ").join(this.getCommandParts()));
    while (this.isRunning()) {
        logger().trace("Compose container is still running");
        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    }
    logger().info("Docker Compose has finished running");

    AuditLogger.doComposeLog(this.getCommandParts(), this.getEnv());

    final Integer exitCode = this.dockerClient.inspectContainerCmd(containerId)
            .exec()
            .getState()
            .getExitCode();

    if (exitCode == null || exitCode != 0) {
        throw new ContainerLaunchException(
                "Containerised Docker Compose exited abnormally with code " +
                        exitCode +
                        " whilst running command: " +
                        StringUtils.join(this.getCommandParts(), ' '));
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:30,代码来源:DockerComposeContainer.java


示例10: testLogConsumer

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Test
public void testLogConsumer() throws TimeoutException {

    WaitingConsumer waitingConsumer = new WaitingConsumer();
    Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER);

    Consumer<OutputFrame> composedConsumer = logConsumer.andThen(waitingConsumer);
    container.followOutput(composedConsumer);

    waitingConsumer.waitUntil(frame -> frame.getType() == STDOUT && frame.getUtf8String().contains("seq=2"));
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:12,代码来源:OutputStreamTest.java


示例11: zookeeperUrl

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
@Test
public void zookeeperUrl() {
  zooCp.followOutput(new Slf4jLogConsumer(log));
  System.out.println(zooCp.zookeeperUrl());
}
 
开发者ID:gAmUssA,项目名称:testcontainers-java-module-confluent-platform,代码行数:6,代码来源:ZookeeperContainerTest.java


示例12: tryStart

import org.testcontainers.containers.output.Slf4jLogConsumer; //导入依赖的package包/类
private void tryStart(Profiler profiler) {
    try {
        String dockerImageName = image.get();
        logger().debug("Starting container: {}", dockerImageName);

        logger().info("Creating container for image: {}", dockerImageName);
        profiler.start("Create container");
        CreateContainerCmd createCommand = dockerClient.createContainerCmd(dockerImageName);
        applyConfiguration(createCommand);
        createContainerCmdModifiers.forEach(hook -> hook.accept(createCommand));

        containerId = createCommand.exec().getId();
        ResourceReaper.instance().registerContainerForCleanup(containerId, dockerImageName);

        logger().info("Starting container with ID: {}", containerId);
        profiler.start("Start container");
        dockerClient.startContainerCmd(containerId).exec();

        // For all registered output consumers, start following as close to container startup as possible
        this.logConsumers.forEach(this::followOutput);

        logger().info("Container {} is starting: {}", dockerImageName, containerId);

        // Tell subclasses that we're starting
        profiler.start("Inspecting container");
        containerInfo = dockerClient.inspectContainerCmd(containerId).exec();
        containerName = containerInfo.getName();
        profiler.start("Call containerIsStarting on subclasses");
        containerIsStarting(containerInfo);

        // Wait until the container is running (may not be fully started)
        profiler.start("Wait until container has started properly, or there's evidence it failed to start.");

        if (!this.startupCheckStrategy.waitUntilStartupSuccessful(dockerClient, containerId)) {
            // Bail out, don't wait for the port to start listening.
            // (Exception thrown here will be caught below and wrapped)
            throw new IllegalStateException("Container did not start correctly.");
        }

        profiler.start("Wait until container started properly");
        waitUntilContainerStarted();

        logger().info("Container {} started", dockerImageName);
        containerIsStarted(containerInfo);
    } catch (Exception e) {
        logger().error("Could not start container", e);

        // Log output if startup failed, either due to a container failure or exception (including timeout)
        logger().error("Container log output (if any) will follow:");
        FrameConsumerResultCallback resultCallback = new FrameConsumerResultCallback();
        resultCallback.addConsumer(STDOUT, new Slf4jLogConsumer(logger()));
        resultCallback.addConsumer(STDERR, new Slf4jLogConsumer(logger()));
        dockerClient.logContainerCmd(containerId).withStdOut(true).withStdErr(true).exec(resultCallback);

        // Try to ensure that container log output is shown before proceeding
        try {
            resultCallback.getCompletionLatch().await(1, TimeUnit.MINUTES);
        } catch (InterruptedException ignored) {
            // Cannot do anything at this point
        }

        throw new ContainerLaunchException("Could not create/start container", e);
    } finally {
        profiler.stop();
    }
}
 
开发者ID:testcontainers,项目名称:testcontainers-java,代码行数:67,代码来源:GenericContainer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StaticInjectionRequest类代码示例发布时间:2022-05-22
下一篇:
Java BlockInputStream类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap