Search in sources :

Example 1 with Event

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));
}
Also used : Event(io.zeebe.client.event.Event)

Example 2 with Event

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");
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Event(io.zeebe.client.event.Event) Test(org.junit.Test) Protocol(io.zeebe.protocol.Protocol) Assertions.entry(org.assertj.core.api.Assertions.entry) ExecuteCommandRequestEncoder(io.zeebe.protocol.clientapi.ExecuteCommandRequestEncoder) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ExpectedException(org.junit.rules.ExpectedException) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Event(io.zeebe.client.event.Event) Test(org.junit.Test)

Example 3 with Event

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");
}
Also used : TopicsClient(io.zeebe.client.TopicsClient) TaskEvent(io.zeebe.client.event.TaskEvent) Event(io.zeebe.client.event.Event) Test(org.junit.Test)

Aggregations

Event (io.zeebe.client.event.Event)3 Test (org.junit.Test)2 TopicsClient (io.zeebe.client.TopicsClient)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 TaskEvent (io.zeebe.client.event.TaskEvent)1 ClientRule (io.zeebe.client.util.ClientRule)1 Protocol (io.zeebe.protocol.Protocol)1 EventType (io.zeebe.protocol.clientapi.EventType)1 ExecuteCommandRequestEncoder (io.zeebe.protocol.clientapi.ExecuteCommandRequestEncoder)1 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)1 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 RuleChain (org.junit.rules.RuleChain)1