Class TestCluster
- All Implemented Interfaces:
CloseableSilently,AutoCloseable
It's recommended to use the TestClusterBuilder to build one.
As the cluster is not started automatically, the nodes can still be modified/configured beforehand. Be aware however that the replication factor and the partitions count cannot be modified: if you configure different values directly on your brokers, then you may run into issues. Keep in mind as well that the gateways and brokers should be treated as immutable collections.
Example usage:
final class MyClusteredTest {
private TestCluster cluster;
@BeforeEach
void beforeEach() {
cluster = TestCluster.builder()
.withBrokersCount(3)
.withReplicationFactor(3)
.withPartitionsCount(1)
.useEmbeddedGateway(true)
.build();
}
@AfterEach
void afterEach() {
cluster.stop();
}
@Test
void shouldConnectToCluster() {
// given
cluster.start();
cluster.awaitCompleteTopology();
// when
final Topology topology;
try (final ZeebeClient client = cluster.newClientBuilder().build()) {
topology = c.newTopologyRequest().send().join();
}
// then
assertThat(topology.getClusterSize()).isEqualTo(3);
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionTestCluster(String name, int replicationFactor, int partitionsCount, Map<MemberId, TestStandaloneBroker> brokers, Map<MemberId, TestStandaloneGateway> gateways) Creates a new cluster from the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionTestGateway<?> Returns the first gateway which is running.TestGateway<?> Returns the first gateway which can accept requests from a Zeebe client.await(TestHealthProbe probe) Convenience method forawait(TestHealthProbe, Duration)with a default timeout of 1 minute per node in the cluster.await(TestHealthProbe probe, Duration timeout) Waits until the given probe succeeds, or until the timeout expires.Convenience alias forawaitCompleteTopology(Duration)with a default value of 1 minute per brokers.awaitCompleteTopology(int clusterSize, int partitionsCount, int replicationFactor, Duration timeout) Waits until every gateway in the cluster sees a complete and healthy topology, as defined by thereplicationFactor,partitionsCount, and count ofbrokersin this cluster.awaitCompleteTopology(Duration timeout) Waits until every gateway in the cluster sees a complete and healthy topology, as defined by thereplicationFactor,partitionsCount, and count ofbrokersin this cluster.awaitHealthyTopology(Duration timeout) brokers()Returns a map of the brokers in the cluster, where the keys are the broker's nodeId, and the values the broker containers.static TestClusterBuilderbuilder()Returns a new cluster buildervoidclose()gateways()Returns a map of the gateways in the cluster, where the keys are the memberIds, and the values the gateway containers.name()Returns the cluster name.Builds a new client builder by picking a random gateway started gateway for it and disabling transport security.nodes()Returns a map of all nodes in the cluster, where the keys are the member IDs (for brokers, the node ID), and the values are the nodes.intReturns the partition count configured for the brokers; also used to check for a complete topology.intReturns the replication factor configured for the brokers; also used to check for a complete topology.shutdown()Stops all containers in the cluster.start()Starts all applications in the cluster.
-
Constructor Details
-
TestCluster
public TestCluster(String name, int replicationFactor, int partitionsCount, Map<MemberId, TestStandaloneBroker> brokers, Map<MemberId, TestStandaloneGateway> gateways) Creates a new cluster from the given parameters.- Parameters:
name- the name of the cluster (should also be configured on the nodes)replicationFactor- the replication factor of the clusterpartitionsCount- the number of partitions in the clusterbrokers- the set of broker nodes, identified by their node IDgateways- the set of gateway nodes, identified by their member ID
-
-
Method Details
-
builder
Returns a new cluster builder -
start
Starts all applications in the cluster.NOTE: This is a blocking method which returns when all applications are started from the Spring point of view. This means the broker startup has begun, but is not necessarily yet finished, such that it may not be ready.
You can use
await(TestHealthProbe, Duration)to wait until a specific probe (e.g.TestHealthProbe.READYsucceeds on all nodes, orawaitCompleteTopology(Duration)to wait until the topology is complete for all gateways. -
shutdown
Stops all containers in the cluster.NOTE: this method is blocking, and returns when all nodes are completely shut down.
-
replicationFactor
public int replicationFactor()Returns the replication factor configured for the brokers; also used to check for a complete topology. -
partitionsCount
public int partitionsCount()Returns the partition count configured for the brokers; also used to check for a complete topology. -
name
Returns the cluster name. -
availableGateway
Returns the first gateway which can accept requests from a Zeebe client.NOTE: this includes brokers with embedded gateways.
- Returns:
- a gateway ready to accept requests
- Throws:
NoSuchElementException- if there are no such gateways (e.g. none are started, or they are dead, etc.)
-
anyGateway
Returns the first gateway which is running. The gateway may not be ready to accept requests.NOTE: this includes brokers with embedded gateways.
- Returns:
- a gateway
- Throws:
NoSuchElementException- if there are no such gateways (e.g. none are started, or they are dead, etc.)
-
gateways
Returns a map of the gateways in the cluster, where the keys are the memberIds, and the values the gateway containers.NOTE: this does not include brokers which are embedded gateways.
- Returns:
- the standalone gateways in this cluster
-
brokers
Returns a map of the brokers in the cluster, where the keys are the broker's nodeId, and the values the broker containers.- Returns:
- the brokers in this cluster
-
nodes
Returns a map of all nodes in the cluster, where the keys are the member IDs (for brokers, the node ID), and the values are the nodes.- Returns:
- the nodes of this cluster
-
newClientBuilder
Builds a new client builder by picking a random gateway started gateway for it and disabling transport security.NOTE: this will properly automatically configure the security level, but will not configure authentication.
- Returns:
- a new client builder with the gateway and transport security pre-configured
- Throws:
NoSuchElementException- if there are no started gateways
-
awaitCompleteTopology
Convenience alias forawaitCompleteTopology(Duration)with a default value of 1 minute per brokers. -
awaitCompleteTopology
Waits until every gateway in the cluster sees a complete and healthy topology, as defined by thereplicationFactor,partitionsCount, and count ofbrokersin this cluster.- Parameters:
timeout- maximum time to block before failing- Throws:
org.awaitility.core.ConditionTimeoutException- if timeout expires before the topology is complete
-
awaitCompleteTopology
public TestCluster awaitCompleteTopology(int clusterSize, int partitionsCount, int replicationFactor, Duration timeout) Waits until every gateway in the cluster sees a complete and healthy topology, as defined by thereplicationFactor,partitionsCount, and count ofbrokersin this cluster.- Parameters:
clusterSize- the expected brokers countpartitionsCount- the expected partitions countreplicationFactor- the expected number of replicas per partitiontimeout- maximum time to block before failing- Throws:
org.awaitility.core.ConditionTimeoutException- if timeout expires before the topology is complete
-
awaitHealthyTopology
-
awaitHealthyTopology
-
await
Convenience method forawait(TestHealthProbe, Duration)with a default timeout of 1 minute per node in the cluster.- Parameters:
probe- the probe to wait for
-
await
Waits until the given probe succeeds, or until the timeout expires.- Parameters:
probe- the probe to checktimeout- maximum time to block
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseableSilently
-