use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class FailTaskTest method shouldFailTask.
@Test
public void shouldFailTask() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "FAIL").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "FAILED").done().register();
// when
final TaskEvent taskEvent = clientRule.tasks().fail(baseEvent).retries(4).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.getCommand()).containsOnly(entry("state", "FAIL"), entry("lockTime", baseEvent.getLockExpirationTime().toEpochMilli()), entry("lockOwner", baseEvent.getLockOwner()), entry("retries", 4), entry("type", baseEvent.getType()), entry("headers", baseEvent.getHeaders()), entry("customHeaders", baseEvent.getCustomHeaders()), entry("payload", baseEvent.getPayloadMsgPack()));
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("FAILED");
assertThat(taskEvent.getHeaders()).isEqualTo(baseEvent.getHeaders());
assertThat(taskEvent.getLockExpirationTime()).isEqualTo(baseEvent.getLockExpirationTime());
assertThat(taskEvent.getLockOwner()).isEqualTo(baseEvent.getLockOwner());
assertThat(taskEvent.getType()).isEqualTo(baseEvent.getType());
assertThat(taskEvent.getPayload()).isEqualTo(baseEvent.getPayload());
assertThat(taskEvent.getRetries()).isEqualTo(4);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest 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.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class CancelWorkflowInstanceTest method shouldCancelWorkflowInstance.
@Test
public void shouldCancelWorkflowInstance() {
// given
final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
event.setKey(2L);
brokerRule.onWorkflowRequestRespondWith(2L).put("state", "WORKFLOW_INSTANCE_CANCELED").done().register();
// when
clientRule.workflows().cancel(event).execute();
// then
assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
assertThat(commandRequest.getCommand()).containsEntry("state", "CANCEL_WORKFLOW_INSTANCE");
assertThat(commandRequest.key()).isEqualTo(2L);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldOverrideDefaultStartPosition.
@Test
public void shouldOverrideDefaultStartPosition() {
// given
broker1.stubTopicSubscriptionApi(456);
broker2.stubTopicSubscriptionApi(789);
final int position1 = 987;
// when
client.topics().newSubscription(TOPIC).name("hohoho").startAtTailOfTopic().startAtPosition(PARTITION_1, position1).handler(new RecordingEventHandler()).open();
// then
final ExecuteCommandRequest broker1Request = getSubscribeRequests(broker1).get(0);
assertThat(broker1Request.getCommand()).containsEntry("startPosition", position1);
final ExecuteCommandRequest broker2Request = getSubscribeRequests(broker2).get(0);
assertThat(broker2Request.getCommand()).containsEntry("startPosition", -1);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldSubscribeToMultiplePartitionsOfATopic.
@Test
public void shouldSubscribeToMultiplePartitionsOfATopic() {
// given
broker1.stubTopicSubscriptionApi(456);
broker2.stubTopicSubscriptionApi(789);
// when
final TopicSubscription subscription = client.topics().newSubscription(TOPIC).handler(new RecordingEventHandler()).name("hohoho").open();
// then
assertThat(subscription.isOpen()).isTrue();
final List<ExecuteCommandRequest> subscribeRequestsBroker1 = getSubscribeRequests(broker1);
assertThat(subscribeRequestsBroker1).hasSize(1);
final ExecuteCommandRequest request1 = subscribeRequestsBroker1.get(0);
assertThat(request1.partitionId()).isEqualTo(PARTITION_1);
final List<ExecuteCommandRequest> subscribeRequestsBroker2 = getSubscribeRequests(broker2);
assertThat(subscribeRequestsBroker2).hasSize(1);
final ExecuteCommandRequest request2 = subscribeRequestsBroker2.get(0);
assertThat(request2.partitionId()).isEqualTo(PARTITION_2);
}
Aggregations