Search in sources :

Example 1 with ControlMessageResponse

use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.

the class CreateTopicTest method arePublished.

protected boolean arePublished(int... partitions) {
    final ControlMessageResponse response = apiRule.createControlMessageRequest().messageType(ControlMessageType.REQUEST_TOPOLOGY).sendAndAwait();
    final Set<Integer> expectedPartitions = Arrays.stream(partitions).boxed().collect(Collectors.toSet());
    final Map<String, Object> topology = response.getData();
    final List<Map<String, Object>> brokers = (List<Map<String, Object>>) topology.get("brokers");
    for (Map<String, Object> broker : brokers) {
        final List<Map<String, Object>> brokerPartitionStates = (List<Map<String, Object>>) broker.get("partitions");
        for (Map<String, Object> brokerPartitionState : brokerPartitionStates) {
            final String state = brokerPartitionState.get("state").toString();
            if (state.equals(LEADER_STATE)) {
                expectedPartitions.remove(brokerPartitionState.get("partitionId"));
            }
        }
    }
    return expectedPartitions.isEmpty();
}
Also used : List(java.util.List) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) Map(java.util.Map)

Example 2 with ControlMessageResponse

use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.

the class RequestPartitionsTest method shouldReturnCreatedPartitionsAfterRestart.

/**
 * testing snapshotting
 */
@Test
public void shouldReturnCreatedPartitionsAfterRestart() {
    // given
    final String topicName = "foo";
    final int numPartitions = 2;
    apiRule.createTopic(topicName, 2);
    brokerRule.restartBroker();
    // when
    // have to do this multiple times as the stream processor for answering the request may not be available yet
    final ControlMessageResponse response = doRepeatedly(() -> apiRule.createControlMessageRequest().messageType(ControlMessageType.REQUEST_PARTITIONS).partitionId(Protocol.SYSTEM_PARTITION).sendAndAwait()).until(r -> r != null);
    // then
    assertResponse(response, numPartitions, topicName);
}
Also used : ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) Test(org.junit.Test)

Example 3 with ControlMessageResponse

use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.

the class RequestPartitionsTest method shouldReturnCreatedPartitions.

@Test
public void shouldReturnCreatedPartitions() {
    // given
    final String topicName = "foo";
    final int numPartitions = 2;
    apiRule.createTopic(topicName, 2);
    // when
    final ControlMessageResponse response = apiRule.createControlMessageRequest().messageType(ControlMessageType.REQUEST_PARTITIONS).partitionId(Protocol.SYSTEM_PARTITION).sendAndAwait();
    // then
    assertResponse(response, numPartitions, topicName);
}
Also used : ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) Test(org.junit.Test)

Example 4 with ControlMessageResponse

use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.

the class RequestPartitionsTest method shouldRespondWithNoPartition.

@Test
public void shouldRespondWithNoPartition() {
    // when
    final ControlMessageResponse response = doRepeatedly(() -> apiRule.createControlMessageRequest().messageType(ControlMessageType.REQUEST_PARTITIONS).partitionId(Protocol.SYSTEM_PARTITION).sendAndAwait()).until(r -> r != null);
    // then
    assertResponse(response, 0);
}
Also used : ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) Test(org.junit.Test)

Example 5 with ControlMessageResponse

use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldIgnoreCreditsRequestIfSubscriptionDoesNotExist.

@Test
public void shouldIgnoreCreditsRequestIfSubscriptionDoesNotExist() {
    // given
    final int nonExistingSubscriberKey = 444;
    final ControlMessageRequestBuilder request = apiRule.createControlMessageRequest().messageType(ControlMessageType.INCREASE_TASK_SUBSCRIPTION_CREDITS).partitionId(apiRule.getDefaultPartitionId()).data().put("subscriberKey", nonExistingSubscriberKey).put("credits", 2).put("partitionId", apiRule.getDefaultPartitionId()).done();
    // when
    final ControlMessageResponse response = request.sendAndAwait();
    // then
    assertThat(response.getData()).containsEntry("subscriberKey", nonExistingSubscriberKey);
}
Also used : ControlMessageRequestBuilder(io.zeebe.test.broker.protocol.clientapi.ControlMessageRequestBuilder) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) Test(org.junit.Test)

Aggregations

ControlMessageResponse (io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse)10 Test (org.junit.Test)9 SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)3 ControlMessageRequestBuilder (io.zeebe.test.broker.protocol.clientapi.ControlMessageRequestBuilder)2 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)2 List (java.util.List)2 Map (java.util.Map)2 TaskSubscription (io.zeebe.broker.task.processor.TaskSubscription)1 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)1 SubscriptionType (io.zeebe.protocol.clientapi.SubscriptionType)1 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)1 ErrorResponse (io.zeebe.test.broker.protocol.clientapi.ErrorResponse)1 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)1 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 SocketAddress (io.zeebe.transport.SocketAddress)1 StringUtil (io.zeebe.util.StringUtil)1 IOException (java.io.IOException)1