Search in sources :

Example 1 with ZeebeGatewayContainer

use of io.zeebe.containers.ZeebeGatewayContainer in project zeebe by zeebe-io.

the class GatewayHealthProbeIntegrationTest method shouldReportReadinessUpIfNotAvailable.

@Test
public void shouldReportReadinessUpIfNotAvailable() throws IOException, InterruptedException {
    // given
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withExposedPorts(ZeebePort.MONITORING.getPort()).withoutTopologyCheck().withStartupCheckStrategy(new IsRunningStartupCheckStrategy());
    gateway.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();
    // when
    // we are trying to kill process to make application unavailable
    gateway.execInContainer("killbyname", "java");
    // gateway finds the broker
    try {
        Awaitility.await("wait until status turns DOWN").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> given().spec(gatewayServerSpec).when().get(PATH_READINESS_PROBE).then().statusCode(503));
    } 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_READINESS_PROBE).then().statusCode(503);
    }
    // --- shutdown ------------------------------------------
    gateway.stop();
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) IsRunningStartupCheckStrategy(org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 2 with ZeebeGatewayContainer

use of io.zeebe.containers.ZeebeGatewayContainer in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterBuilder method createStandaloneGateways.

private void createStandaloneGateways() {
    final ThreadLocalRandom random = ThreadLocalRandom.current();
    for (int i = 0; i < gatewaysCount; i++) {
        final String memberId = GATEWAY_NETWORK_ALIAS_PREFIX + i;
        final ZeebeGatewayContainer gateway = createStandaloneGateway(memberId);
        gateway.withStartupTimeout(Duration.ofMinutes((long) gatewaysCount + brokersCount));
        if (brokersCount > 0) {
            final ZeebeBrokerNode<?> contactPoint = brokers.get(random.nextInt(0, brokers.size()));
            gateway.dependsOn(contactPoint.self()).withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", contactPoint.getInternalClusterAddress());
        }
    }
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer)

Example 3 with ZeebeGatewayContainer

use of io.zeebe.containers.ZeebeGatewayContainer in project zeebe by camunda.

the class GatewayHealthProbeIntegrationTest method shouldReportReadinessUpIfApplicationIsUp.

@Test
public void shouldReportReadinessUpIfApplicationIsUp() {
    // given
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withExposedPorts(ZeebePort.MONITORING.getPort()).withoutTopologyCheck().withStartupCheckStrategy(new IsRunningStartupCheckStrategy());
    gateway.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_READINESS_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_READINESS_PROBE).then().statusCode(200);
    }
    // --- shutdown ------------------------------------------
    gateway.stop();
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) IsRunningStartupCheckStrategy(org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 4 with ZeebeGatewayContainer

use of io.zeebe.containers.ZeebeGatewayContainer in project zeebe by camunda.

the class GatewayHealthProbeIntegrationTest method shouldReportReadinessUpIfNotAvailable.

@Test
public void shouldReportReadinessUpIfNotAvailable() throws IOException, InterruptedException {
    // given
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withExposedPorts(ZeebePort.MONITORING.getPort()).withoutTopologyCheck().withStartupCheckStrategy(new IsRunningStartupCheckStrategy());
    gateway.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();
    // when
    // we are trying to kill process to make application unavailable
    gateway.execInContainer("killbyname", "java");
    // gateway finds the broker
    try {
        Awaitility.await("wait until status turns DOWN").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> given().spec(gatewayServerSpec).when().get(PATH_READINESS_PROBE).then().statusCode(503));
    } 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_READINESS_PROBE).then().statusCode(503);
    }
    // --- shutdown ------------------------------------------
    gateway.stop();
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) IsRunningStartupCheckStrategy(org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Example 5 with ZeebeGatewayContainer

use of io.zeebe.containers.ZeebeGatewayContainer in project zeebe by camunda.

the class GatewayHealthProbeIntegrationTest method shouldReportLivenessDownIfNotConnectedToBroker.

@Test
public void shouldReportLivenessDownIfNotConnectedToBroker() {
    // --- given ---------------------------------------
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage()).withEnv("ZEEBE_GATEWAY_MONITORING_ENABLED", "true").withoutTopologyCheck();
    gateway.addExposedPorts(ZeebePort.MONITORING.getPort());
    gateway.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();
    // --- when + then ---------------------------------------
    given().spec(gatewayServerSpec).when().get(PATH_LIVENESS_PROBE).then().statusCode(503);
    // --- shutdown ------------------------------------------
    gateway.stop();
}
Also used : RequestSpecification(io.restassured.specification.RequestSpecification) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Test(org.junit.Test)

Aggregations

ZeebeGatewayContainer (io.zeebe.containers.ZeebeGatewayContainer)20 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)12 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)12 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)12 RequestSpecification (io.restassured.specification.RequestSpecification)12 Test (org.junit.Test)12 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)9 ZeebeBrokerContainer (io.zeebe.containers.ZeebeBrokerContainer)6 IsRunningStartupCheckStrategy (org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy)6 PartitionsActuatorClient (io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient)3 ZeebeContainer (io.zeebe.containers.ZeebeContainer)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Startable (org.testcontainers.lifecycle.Startable)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1