Search in sources :

Example 1 with Startable

use of org.testcontainers.lifecycle.Startable in project testcontainers-java by testcontainers.

the class TestcontainersExtension method getContainerInstance.

private static StoreAdapter getContainerInstance(final Object testInstance, final Field field) {
    try {
        field.setAccessible(true);
        Startable containerInstance = Preconditions.notNull((Startable) field.get(testInstance), "Container " + field.getName() + " needs to be initialized");
        return new StoreAdapter(field.getDeclaringClass(), field.getName(), containerInstance);
    } catch (IllegalAccessException e) {
        throw new ExtensionConfigurationException("Can not access container defined in field " + field.getName());
    }
}
Also used : ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) Startable(org.testcontainers.lifecycle.Startable)

Example 2 with Startable

use of org.testcontainers.lifecycle.Startable in project zeebe by camunda-cloud.

the class GatewayHealthProbeIntegrationTest method shouldReportLivenessUpIfConnectedToBroker.

@Test
public void shouldReportLivenessUpIfConnectedToBroker() {
    // --- given ---------------------------------------
    // create a broker and a standalone gateway
    final ZeebeBrokerContainer broker = new ZeebeBrokerContainer(ZeebeTestContainerDefaults.defaultTestImage());
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withNetwork(broker.getNetwork()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress());
    gateway.addExposedPorts(ZeebePort.MONITORING.getPort());
    // start both containers
    Stream.of(gateway, broker).parallel().forEach(Startable::start);
    final Integer actuatorPort = gateway.getMappedPort(ZeebePort.MONITORING.getPort());
    final String containerIPAddress = gateway.getExternalHost();
    final RequestSpecification gatewayServerSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).setBaseUri("http://" + containerIPAddress).setPort(actuatorPort).addFilter(new ResponseLoggingFilter()).addFilter(new RequestLoggingFilter()).build();
    // gateway finds the broker
    try {
        Awaitility.await("wait until status turns UP").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200));
    } catch (final ConditionTimeoutException e) {
        // it can happen that a single request takes too long and causes awaitility to timeout,
        // in which case we want to try a second time to run the request without timeout
        given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200);
    }
    // --- shutdown ------------------------------------------
    Stream.of(gateway, broker).parallel().forEach(Startable::stop);
}
Also used : Startable(org.testcontainers.lifecycle.Startable) RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) ZeebeBrokerContainer(io.zeebe.containers.ZeebeBrokerContainer) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 3 with Startable

use of org.testcontainers.lifecycle.Startable in project hermes by allegro.

the class HermesIntegrationEnvironment method prepareEnvironment.

@BeforeSuite
public void prepareEnvironment(ITestContext context) throws Exception {
    try {
        Stream.of(kafkaClusterOne, kafkaClusterTwo, hermesZookeeperOne, hermesZookeeperTwo, googlePubSubEmulator).parallel().forEach(Startable::start);
        schemaRegistry.start();
        for (Starter<?> starter : STARTERS.values()) {
            starter.start();
        }
        managementStarter = HermesManagementInstance.starter().port(MANAGEMENT_PORT).addKafkaCluster(DC1, kafkaClusterOne.getBootstrapServersForExternalClients()).addZookeeperCluster(DC1, hermesZookeeperOne.getConnectionString()).schemaRegistry(schemaRegistry.getUrl()).replicationFactor(kafkaClusterOne.getAllBrokers().size()).uncleanLeaderElectionEnabled(false).start();
        zookeeper = startZookeeperClient();
        ConsumersStarter consumersStarter = new ConsumersStarter();
        consumersStarter.overrideProperty(Configs.KAFKA_AUTHORIZATION_ENABLED, false);
        consumersStarter.overrideProperty(Configs.KAFKA_CLUSTER_NAME, PRIMARY_KAFKA_CLUSTER_NAME);
        consumersStarter.overrideProperty(Configs.KAFKA_BROKER_LIST, kafkaClusterOne.getBootstrapServersForExternalClients());
        consumersStarter.overrideProperty(Configs.ZOOKEEPER_CONNECT_STRING, hermesZookeeperOne.getConnectionString());
        consumersStarter.overrideProperty(Configs.SCHEMA_REPOSITORY_SERVER_URL, schemaRegistry.getUrl());
        consumersStarter.overrideProperty(Configs.GOOGLE_PUBSUB_TRANSPORT_CHANNEL_PROVIDER_ADDRESS, googlePubSubEmulator.getEmulatorEndpoint());
        consumersStarter.start();
        FrontendStarter frontendStarter = FrontendStarter.withCommonIntegrationTestConfig(FRONTEND_PORT);
        frontendStarter.overrideProperty(Configs.KAFKA_AUTHORIZATION_ENABLED, false);
        frontendStarter.overrideProperty(Configs.KAFKA_BROKER_LIST, kafkaClusterOne.getBootstrapServersForExternalClients());
        frontendStarter.overrideProperty(Configs.ZOOKEEPER_CONNECT_STRING, hermesZookeeperOne.getConnectionString());
        frontendStarter.overrideProperty(Configs.SCHEMA_REPOSITORY_SERVER_URL, schemaRegistry.getUrl());
        frontendStarter.start();
        for (ITestNGMethod method : context.getAllTestMethods()) {
            method.setRetryAnalyzerClass(Retry.class);
        }
        SharedServices.initialize(STARTERS, zookeeper);
        logger.info("Environment was prepared");
    } catch (Exception e) {
        throw new RuntimeException("Exception during environment preparation", e);
    }
}
Also used : Startable(org.testcontainers.lifecycle.Startable) ITestNGMethod(org.testng.ITestNGMethod) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 4 with Startable

use of org.testcontainers.lifecycle.Startable in project zeebe by zeebe-io.

the class GatewayHealthProbeIntegrationTest method shouldReportLivenessUpIfConnectedToBroker.

@Test
public void shouldReportLivenessUpIfConnectedToBroker() {
    // --- given ---------------------------------------
    // create a broker and a standalone gateway
    final ZeebeBrokerContainer broker = new ZeebeBrokerContainer(ZeebeTestContainerDefaults.defaultTestImage());
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withNetwork(broker.getNetwork()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress());
    gateway.addExposedPorts(ZeebePort.MONITORING.getPort());
    // start both containers
    Stream.of(gateway, broker).parallel().forEach(Startable::start);
    final Integer actuatorPort = gateway.getMappedPort(ZeebePort.MONITORING.getPort());
    final String containerIPAddress = gateway.getExternalHost();
    final RequestSpecification gatewayServerSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).setBaseUri("http://" + containerIPAddress).setPort(actuatorPort).addFilter(new ResponseLoggingFilter()).addFilter(new RequestLoggingFilter()).build();
    // gateway finds the broker
    try {
        Awaitility.await("wait until status turns UP").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200));
    } catch (final ConditionTimeoutException e) {
        // it can happen that a single request takes too long and causes awaitility to timeout,
        // in which case we want to try a second time to run the request without timeout
        given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200);
    }
    // --- shutdown ------------------------------------------
    Stream.of(gateway, broker).parallel().forEach(Startable::stop);
}
Also used : Startable(org.testcontainers.lifecycle.Startable) RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) ZeebeBrokerContainer(io.zeebe.containers.ZeebeBrokerContainer) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 5 with Startable

use of org.testcontainers.lifecycle.Startable in project zeebe by camunda.

the class GatewayHealthProbeIntegrationTest method shouldReportLivenessUpIfConnectedToBroker.

@Test
public void shouldReportLivenessUpIfConnectedToBroker() {
    // --- given ---------------------------------------
    // create a broker and a standalone gateway
    final ZeebeBrokerContainer broker = new ZeebeBrokerContainer(ZeebeTestContainerDefaults.defaultTestImage());
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withNetwork(broker.getNetwork()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress());
    gateway.addExposedPorts(ZeebePort.MONITORING.getPort());
    // start both containers
    Stream.of(gateway, broker).parallel().forEach(Startable::start);
    final Integer actuatorPort = gateway.getMappedPort(ZeebePort.MONITORING.getPort());
    final String containerIPAddress = gateway.getExternalHost();
    final RequestSpecification gatewayServerSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).setBaseUri("http://" + containerIPAddress).setPort(actuatorPort).addFilter(new ResponseLoggingFilter()).addFilter(new RequestLoggingFilter()).build();
    // gateway finds the broker
    try {
        Awaitility.await("wait until status turns UP").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200));
    } catch (final ConditionTimeoutException e) {
        // it can happen that a single request takes too long and causes awaitility to timeout,
        // in which case we want to try a second time to run the request without timeout
        given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(200);
    }
    // --- shutdown ------------------------------------------
    Stream.of(gateway, broker).parallel().forEach(Startable::stop);
}
Also used : Startable(org.testcontainers.lifecycle.Startable) RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) ZeebeBrokerContainer(io.zeebe.containers.ZeebeBrokerContainer) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Aggregations

Startable (org.testcontainers.lifecycle.Startable)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)3 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)3 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)3 RequestSpecification (io.restassured.specification.RequestSpecification)3 ZeebeBrokerContainer (io.zeebe.containers.ZeebeBrokerContainer)3 ZeebeGatewayContainer (io.zeebe.containers.ZeebeGatewayContainer)3 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)3 Test (org.junit.Test)3 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)1 ITestNGMethod (org.testng.ITestNGMethod)1 BeforeSuite (org.testng.annotations.BeforeSuite)1