use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldApplyStartPositionPerSubscriber.
@Test
public void shouldApplyStartPositionPerSubscriber() {
// given
broker1.stubTopicSubscriptionApi(456);
broker2.stubTopicSubscriptionApi(789);
final int position1 = 987;
final int position2 = 546;
// when
client.topics().newSubscription(TOPIC).name("hohoho").startAtPosition(PARTITION_1, position1).startAtPosition(PARTITION_2, position2).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", position2);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class PartitionedTopicSubscriptionTest method shouldApplyStartPositionPerSubscriberForPollableSubscription.
@Test
public void shouldApplyStartPositionPerSubscriberForPollableSubscription() {
// given
broker1.stubTopicSubscriptionApi(456);
broker2.stubTopicSubscriptionApi(789);
final int position1 = 987;
final int position2 = 546;
// when
client.topics().newPollableSubscription(TOPIC).name("hohoho").startAtPosition(PARTITION_1, position1).startAtPosition(PARTITION_2, position2).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", position2);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class UpdateTaskRetriesTest method shouldUpdateRetries.
@Test
public void shouldUpdateRetries() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "UPDATE_RETRIES").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "RETRIES_UPDATED").done().register();
// when
final TaskEvent taskEvent = clientRule.tasks().updateRetries(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", "UPDATE_RETRIES"), 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("RETRIES_UPDATED");
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 TaskSubscriptionTest method shouldSetPayloadAndCompleteTask.
@Test
public void shouldSetPayloadAndCompleteTask() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> c.complete(t).payload("{\"a\": 1}").execute()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress eventSource = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(eventSource, 123L, 4L, 5L, "foo", "bar");
// then
final ExecuteCommandRequest taskRequest = TestUtil.doRepeatedly(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.TASK_EVENT).findFirst()).until(r -> r.isPresent()).get();
assertThat(taskRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
assertThat(taskRequest.key()).isEqualTo(4L);
assertThat(taskRequest.getCommand()).containsEntry("state", "COMPLETE").containsEntry("type", "bar").containsEntry("lockOwner", "foo").containsEntry("payload", msgPackConverter.convertToMsgPack("{\"a\": 1}"));
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldDeployResourceAsXmlFile.
@SuppressWarnings("unchecked")
@Test
public void shouldDeployResourceAsXmlFile() throws Exception {
// given
stubDeploymentRequest();
// when
final String filePath = getClass().getResource("/workflows/one-task-process.bpmn").toURI().getPath();
clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addResourceFile(filePath).execute();
// then
assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
final List<Map<String, Object>> resources = (List<Map<String, Object>>) commandRequest.getCommand().get("resources");
assertThat(resources).hasSize(1);
assertThat(resources.get(0)).containsKey("resource").containsEntry("resourceName", filePath).containsEntry("resourceType", "BPMN_XML");
final byte[] resource = (byte[]) resources.get(0).get("resource");
assertThat(new File(filePath)).hasBinaryContent(resource);
}
Aggregations