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());
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations