use of io.zeebe.client.event.Event in project zeebe by zeebe-io.
the class ClusteringRule method createTopic.
/**
* Creates a topic with the given partition count in the cluster.
*
* This method returns to the user, if the topic and the partitions are created
* and the replication factor was reached for each partition.
* Besides that the topic request needs to be return the created topic.
*
* The replication factor is per default {@link #DEFAULT_REPLICATION_FACTOR}, but can be modified with
* {@link #setReplicationFactor(int)}.
*
* @param topicName
* @param partitionCount
* @return
*/
public Topic createTopic(String topicName, int partitionCount) {
final Event topicEvent = zeebeClient.topics().create(topicName, partitionCount).execute();
assertThat(topicEvent.getState()).isEqualTo("CREATED");
waitForTopicPartitionReplicationFactor(topicName, partitionCount, replicationFactor);
return waitForSpreading(() -> waitForTopicAvailability(topicName));
}
use of io.zeebe.client.event.Event in project zeebe by zeebe-io.
the class CreateTopicTest method shouldCreateTopic.
@Test
public void shouldCreateTopic() {
// given
brokerRule.onExecuteCommandRequest(Protocol.SYSTEM_PARTITION, EventType.TOPIC_EVENT, "CREATE").respondWith().key(123).position(456).event().allOf((r) -> r.getCommand()).put("state", "CREATED").done().register();
// when
final Event responseEvent = clientRule.topics().create("newTopic", 14).execute();
// then
final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
assertThat(request.eventType()).isEqualTo(EventType.TOPIC_EVENT);
assertThat(request.partitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
assertThat(request.position()).isEqualTo(ExecuteCommandRequestEncoder.positionNullValue());
assertThat(request.getCommand()).containsOnly(entry("state", "CREATE"), entry("name", "newTopic"), entry("partitions", 14));
assertThat(responseEvent.getMetadata().getKey()).isEqualTo(123L);
assertThat(responseEvent.getMetadata().getTopicName()).isEqualTo(Protocol.SYSTEM_TOPIC);
assertThat(responseEvent.getMetadata().getPartitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
assertThat(responseEvent.getMetadata().getPosition()).isEqualTo(456);
assertThat(responseEvent.getState()).isEqualTo("CREATED");
}
use of io.zeebe.client.event.Event in project zeebe by zeebe-io.
the class CreateTopicTest method shouldCreateMultipleTopicsInParallel.
@Test
public void shouldCreateMultipleTopicsInParallel() throws Exception {
// given
final TopicsClient topics = clientRule.topics();
// when
final Future<Event> foo = topics.create("foo", 2).executeAsync();
final Future<Event> bar = topics.create("bar", 2).executeAsync();
// then
assertThat(bar.get(10, TimeUnit.SECONDS).getState()).isEqualTo("CREATED");
assertThat(foo.get(10, TimeUnit.SECONDS).getState()).isEqualTo("CREATED");
}
Aggregations