use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldMarkTaskAsFailedOnExpcetion.
@Test
public void shouldMarkTaskAsFailedOnExpcetion() {
// given
broker.stubTaskSubscriptionApi(123L);
broker.onExecuteCommandRequest(isTaskFailCommand()).respondWith().event().allOf(r -> r.getCommand()).put("state", "FAILED").done().register();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> {
throw new RuntimeException("expected failure");
}).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(clientAddress, 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", "FAIL").containsEntry("type", "bar").containsEntry("lockOwner", "foo");
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCompleteTaskWithoutPayload.
@Test
public void shouldCompleteTaskWithoutPayload() {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> c.complete(t).withoutPayload().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").doesNotContainKey("payload");
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCompleteTaskWithPayload.
@Test
public void shouldCompleteTaskWithPayload() {
// 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 shouldDeployResourceAsYamlFile.
@SuppressWarnings("unchecked")
@Test
public void shouldDeployResourceAsYamlFile() throws Exception {
// given
stubDeploymentRequest();
// when
final String filePath = getClass().getResource("/workflows/simple-workflow.yaml").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", "YAML_WORKFLOW");
final byte[] resource = (byte[]) resources.get(0).get("resource");
assertThat(new File(filePath)).hasBinaryContent(resource);
}
use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldDeployResourceFromXmlClasspath.
@SuppressWarnings("unchecked")
@Test
public void shouldDeployResourceFromXmlClasspath() throws Exception {
// given
stubDeploymentRequest();
// when
clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addResourceFromClasspath("workflows/one-task-process.bpmn").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", "workflows/one-task-process.bpmn").containsEntry("resourceType", "BPMN_XML");
final byte[] resource = (byte[]) resources.get(0).get("resource");
final String filePath = getClass().getResource("/workflows/one-task-process.bpmn").toURI().getPath();
assertThat(new File(filePath)).hasBinaryContent(resource);
}
Aggregations