use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PollableTopicSubscriptionTest method shouldOpenSubscriptionAndForceStart.
@Test
public void shouldOpenSubscriptionAndForceStart() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.getClient().topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().forcedStart().name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
assertThat(subscribeRequest.getCommand()).containsEntry("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PollableTopicSubscriptionTest method shouldOpenSubscription.
@Test
public void shouldOpenSubscription() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
assertThat(subscribeRequest.getCommand()).containsEntry("state", "SUBSCRIBE").containsEntry("startPosition", 0).containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldOpenSubscriptionAndForceStart.
@Test
public void shouldOpenSubscriptionAndForceStart() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().forcedStart().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("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TopicSubscriptionTest method shouldOpenPollableSubscription.
@Test
public void shouldOpenPollableSubscription() {
// given
broker.stubTopicSubscriptionApi(123L);
// when
clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
// then
final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
assertThat(subscribeRequest.getCommand()).containsEntry("state", "SUBSCRIBE").containsEntry("startPosition", 0).containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldCompleteTask.
@Test
public void shouldCompleteTask() {
// 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();
final String updatedPayload = "{\"fruit\":\"cherry\"}";
// when
final TaskEvent taskEvent = clientRule.tasks().complete(baseEvent).payload(updatedPayload).execute();
// then
final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
assertThat(request.eventType()).isEqualTo(EventType.TASK_EVENT);
assertThat(request.partitionId()).isEqualTo(StubBrokerRule.TEST_PARTITION_ID);
assertThat(request.position()).isEqualTo(baseEvent.getMetadata().getPosition());
assertThat(request.getCommand()).containsOnly(entry("state", "COMPLETE"), entry("lockTime", baseEvent.getLockExpirationTime().toEpochMilli()), entry("lockOwner", baseEvent.getLockOwner()), entry("retries", baseEvent.getRetries()), entry("type", baseEvent.getType()), entry("headers", baseEvent.getHeaders()), entry("customHeaders", baseEvent.getCustomHeaders()), entry("payload", converter.convertToMsgPack(updatedPayload)));
assertThat(taskEvent.getMetadata().getKey()).isEqualTo(123L);
assertThat(taskEvent.getMetadata().getTopicName()).isEqualTo(StubBrokerRule.TEST_TOPIC_NAME);
assertThat(taskEvent.getMetadata().getPartitionId()).isEqualTo(StubBrokerRule.TEST_PARTITION_ID);
assertThat(taskEvent.getState()).isEqualTo("COMPLETED");
assertThat(taskEvent.getHeaders()).isEqualTo(baseEvent.getHeaders());
assertThat(taskEvent.getLockExpirationTime()).isEqualTo(baseEvent.getLockExpirationTime());
assertThat(taskEvent.getLockOwner()).isEqualTo(baseEvent.getLockOwner());
assertThat(taskEvent.getRetries()).isEqualTo(baseEvent.getRetries());
assertThat(taskEvent.getType()).isEqualTo(baseEvent.getType());
assertThat(taskEvent.getPayload()).isEqualTo(updatedPayload);
}
Aggregations