![JAR search and dependency download from the Maven repository](/logo.png)
io.camunda.zeebe.qa.util.cluster.TestGateway Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Zeebe Community License 1.1. You may not use this file
* except in compliance with the Zeebe Community License 1.1.
*/
package io.camunda.zeebe.qa.util.cluster;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.ZeebeClientBuilder;
import io.camunda.zeebe.gateway.impl.configuration.GatewayCfg;
import io.camunda.zeebe.qa.util.actuator.GatewayHealthActuator;
import io.camunda.zeebe.qa.util.actuator.HealthActuator;
import io.camunda.zeebe.test.util.asserts.TopologyAssert;
import java.net.URI;
import java.time.Duration;
import java.util.function.Consumer;
import org.awaitility.Awaitility;
/**
* Represents a Zeebe gateway, either standalone or embedded.
*
* @param the concrete type of the implementation
*/
public interface TestGateway> extends TestApplication {
/**
* Returns the address used by clients to interact with the gateway.
*
* You can build your client like this:
*
*
@{code
* ZeebeClient.newClientBuilder()
* .gatewayAddress(gateway.gatewayAddress())
* .usePlaintext()
* .build();
* }
*
* @return the address for the gRPC gateway
*/
default URI grpcAddress() {
final var scheme = gatewayConfig().getSecurity().isEnabled() ? "https" : "http";
return uri(scheme, TestZeebePort.GATEWAY);
}
/**
* Returns the address used by clients to interact with the gateway.
*
* You can build your client like this:
*
*
@{code
* ZeebeClient.newClientBuilder()
* .restAddress(gateway.restAddress())
* .usePlaintext()
* .build();
* }
*
* @return the REST gateway address
*/
default URI restAddress() {
final var basePath = property("spring.webflux.base-path", String.class, "");
final var sslEnabled = property("server.ssl.enabled", Boolean.class, false);
return uri(sslEnabled ? "https" : "http", TestZeebePort.REST, basePath);
}
/**
* Returns the health actuator for this gateway. You can use this to check for liveness,
* readiness, and startup.
*/
default GatewayHealthActuator gatewayHealth() {
return GatewayHealthActuator.of(this);
}
@Override
default HealthActuator healthActuator() {
return gatewayHealth();
}
@Override
default boolean isGateway() {
return true;
}
/**
* Allows modifying the gateway configuration. Changes will not take effect until the node is
* restarted.
*/
T withGatewayConfig(final Consumer modifier);
/** Returns the gateway configuration for this node. */
GatewayCfg gatewayConfig();
/** Returns a new pre-configured client builder for this gateway */
default ZeebeClientBuilder newClientBuilder() {
final var builder =
ZeebeClient.newClientBuilder().grpcAddress(grpcAddress()).restAddress(restAddress());
final var security = gatewayConfig().getSecurity();
final var restSSL = property("server.ssl.enabled", Boolean.class, false);
if (security.isEnabled() || restSSL) {
builder.caCertificatePath(security.getCertificateChainPath().getAbsolutePath());
} else {
builder.usePlaintext();
}
return builder;
}
/**
* Blocks until the topology is complete. See {@link TopologyAssert#isComplete(int, int, int)} for
* semantics.
*
* @return itself for chaining
* @see TopologyAssert#isComplete(int, int, int)
*/
default T awaitCompleteTopology(
final int clusterSize,
final int partitionCount,
final int replicationFactor,
final Duration timeout) {
try (final var client = newClientBuilder().build()) {
Awaitility.await("until cluster topology is complete")
.atMost(timeout)
.untilAsserted(
() ->
TopologyAssert.assertThat(client.newTopologyRequest().send().join())
.isComplete(clusterSize, partitionCount, replicationFactor));
}
return self();
}
/**
* Convenience method to await complete topology of single node clusters.
*
* @return itself for chaining
*/
default T awaitCompleteTopology() {
return awaitCompleteTopology(1, 1, 1, Duration.ofSeconds(30));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy