Search in sources :

Example 36 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldSendPrefetchCapacityAsDefinedInClientProperties.

@Test
public void shouldSendPrefetchCapacityAsDefinedInClientProperties() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest addSubscriptionRequest = broker.getReceivedCommandRequests().stream().filter((r) -> r.eventType() == EventType.SUBSCRIBER_EVENT && "SUBSCRIBE".equals(r.getCommand().get("state"))).findFirst().get();
    assertThat(addSubscriptionRequest.getCommand()).containsEntry("prefetchCapacity", 32);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 37 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldOpenSubscriptionAtTailOfTopic.

@Test
public void shouldOpenSubscriptionAtTailOfTopic() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtTailOfTopic().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).hasEntrySatisfying("startPosition", Conditions.isLowerThan(0)).containsEntry("state", "SUBSCRIBE").containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 38 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldOpenSubscriptionAtPosition.

@Test
public void shouldOpenSubscriptionAtPosition() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtPosition(clientRule.getDefaultPartitionId(), 654L).handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).containsEntry("startPosition", 654).containsEntry("state", "SUBSCRIBE").containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 39 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldResumeSubscriptionBeforeFailedEventAfterHandlerFailure.

@Test
public void shouldResumeSubscriptionBeforeFailedEventAfterHandlerFailure() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    final FailingHandler handler = new FailingHandler(e -> e.getMetadata().getPosition() == 2L);
    final TopicSubscription subscription = clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().handler(handler).name(SUBSCRIPTION_NAME).open();
    final RemoteAddress clientAddress = broker.getReceivedCommandRequests().get(0).getSource();
    broker.pushTopicEvent(clientAddress, 123L, 1L, 1L);
    // when
    broker.pushTopicEvent(clientAddress, 123L, 1L, 2L);
    // then
    TestUtil.waitUntil(() -> subscription.isClosed());
    final List<ExecuteCommandRequest> commandRequests = broker.getReceivedCommandRequests();
    final List<ExecuteCommandRequest> acknowledgements = commandRequests.stream().filter((c) -> c.eventType() == EventType.SUBSCRIPTION_EVENT).filter((c) -> "ACKNOWLEDGE".equals(c.getCommand().get("state"))).collect(Collectors.toList());
    assertThat(acknowledgements).isNotEmpty();
    final ExecuteCommandRequest lastAck = acknowledgements.get(acknowledgements.size() - 1);
    assertThat(lastAck.getCommand().get("name")).isEqualTo(SUBSCRIPTION_NAME);
    assertThat(lastAck.getCommand().get("ackPosition")).isEqualTo(1);
    final ControlMessageRequest removeRequest = broker.getReceivedControlMessageRequests().stream().filter((c) -> c.messageType() == ControlMessageType.REMOVE_TOPIC_SUBSCRIPTION).findFirst().get();
    final List<Object> requests = broker.getAllReceivedRequests();
    assertThat(requests).contains(lastAck);
    assertThat(requests.indexOf(lastAck)).isLessThan(requests.indexOf(removeRequest));
}
Also used : SubscriptionManager(io.zeebe.client.task.impl.subscription.SubscriptionManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) TimeoutException(java.util.concurrent.TimeoutException) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) Future(java.util.concurrent.Future) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) RemoteAddress(io.zeebe.transport.RemoteAddress) ClientRule(io.zeebe.client.util.ClientRule) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) TopicSubscriptionBuilderImpl(io.zeebe.client.event.impl.TopicSubscriptionBuilderImpl) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ResponseController(io.zeebe.test.broker.protocol.brokerapi.ResponseController) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) ActorFuture(io.zeebe.util.sched.future.ActorFuture) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) EventType(io.zeebe.protocol.clientapi.EventType) Conditions(io.zeebe.test.util.Conditions) Optional(java.util.Optional) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestUtil(io.zeebe.test.util.TestUtil) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) RemoteAddress(io.zeebe.transport.RemoteAddress) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 40 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class CompleteTaskTest method shouldClearPayload.

@Test
public void shouldClearPayload() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
    // when
    clientRule.tasks().complete(baseEvent).withoutPayload().execute();
    // then
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.getCommand()).doesNotContainKey("payload");
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Aggregations

ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)41 Test (org.junit.Test)30 ClientRule (io.zeebe.client.util.ClientRule)15 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 ExpectedException (org.junit.rules.ExpectedException)15 RuleChain (org.junit.rules.RuleChain)15 EventType (io.zeebe.protocol.clientapi.EventType)14 Rule (org.junit.Rule)14 Assertions.entry (org.assertj.core.api.Assertions.entry)12 TaskEvent (io.zeebe.client.event.TaskEvent)11 Before (org.junit.Before)11 ZeebeClient (io.zeebe.client.ZeebeClient)10 TasksClient (io.zeebe.client.TasksClient)9 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)9 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)6 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)6 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)6