Search in sources :

Example 16 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldCreateDeploymentWithMultipleResourcesAndWorkflows.

@Test
public void shouldCreateDeploymentWithMultipleResourcesAndWorkflows() throws IOException {
    // given
    final WorkflowDefinition singleWorkflow = Bpmn.createExecutableWorkflow("singleProcess").startEvent().done();
    final InputStream multipleWorkflowsResource = getClass().getResourceAsStream("/workflows/collaboration.bpmn");
    final List<Map<String, Object>> resources = Arrays.asList(deploymentResource(bpmnXml(singleWorkflow), "process1.bpmn"), deploymentResource(StreamUtil.read(multipleWorkflowsResource), "collaboration.bpmn"));
    // when
    final ExecuteCommandResponse resp = apiRule.createCmdRequest().partitionId(Protocol.SYSTEM_PARTITION).eventType(EventType.DEPLOYMENT_EVENT).command().put(PROP_STATE, "CREATE").put("topicName", ClientApiRule.DEFAULT_TOPIC_NAME).put("resources", resources).done().sendAndAwait();
    // then
    assertThat(resp.getEvent()).containsEntry(PROP_STATE, "CREATED");
    final List<SubscribedEvent> workflowEvents = apiRule.topic().receiveEvents(workflowEvents("CREATED")).limit(3).collect(toList());
    assertThat(workflowEvents).extracting(s -> s.event().get(PROP_WORKFLOW_BPMN_PROCESS_ID)).contains("singleProcess", "process1", "process2");
}
Also used : TestTopicClient.workflowEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.workflowEvents) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) Bpmn(io.zeebe.model.bpmn.Bpmn) Protocol(io.zeebe.protocol.Protocol) ArrayList(java.util.ArrayList) ResourceType(io.zeebe.broker.workflow.data.ResourceType) Map(java.util.Map) PROP_WORKFLOW_VERSION(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_WORKFLOW_VERSION) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) UTF_8(java.nio.charset.StandardCharsets.UTF_8) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) RuleChain(org.junit.rules.RuleChain) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) StreamUtil(io.zeebe.util.StreamUtil) PROP_STATE(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_STATE) EventType(io.zeebe.protocol.clientapi.EventType) PROP_WORKFLOW_BPMN_PROCESS_ID(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_WORKFLOW_BPMN_PROCESS_ID) Files(org.assertj.core.util.Files) Collections(java.util.Collections) InputStream(java.io.InputStream) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) InputStream(java.io.InputStream) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) HashMap(java.util.HashMap) Map(java.util.Map) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 17 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldCreateDeploymentWithMultipleResources.

@Test
public void shouldCreateDeploymentWithMultipleResources() {
    // given
    final WorkflowDefinition definition1 = Bpmn.createExecutableWorkflow("process1").startEvent().done();
    final WorkflowDefinition definition2 = Bpmn.createExecutableWorkflow("process2").startEvent().done();
    final List<Map<String, Object>> resources = Arrays.asList(deploymentResource(bpmnXml(definition1), "process1.bpmn"), deploymentResource(bpmnXml(definition2), "process2.bpmn"));
    // when
    final ExecuteCommandResponse resp = apiRule.createCmdRequest().partitionId(Protocol.SYSTEM_PARTITION).eventType(EventType.DEPLOYMENT_EVENT).command().put(PROP_STATE, "CREATE").put("topicName", ClientApiRule.DEFAULT_TOPIC_NAME).put("resources", resources).done().sendAndAwait();
    // then
    assertThat(resp.getEvent()).containsEntry(PROP_STATE, "CREATED");
    final List<SubscribedEvent> workflowEvents = apiRule.topic().receiveEvents(workflowEvents("CREATED")).limit(2).collect(toList());
    assertThat(workflowEvents).extracting(s -> s.event().get(PROP_WORKFLOW_BPMN_PROCESS_ID)).contains("process1", "process2");
}
Also used : TestTopicClient.workflowEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.workflowEvents) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) Bpmn(io.zeebe.model.bpmn.Bpmn) Protocol(io.zeebe.protocol.Protocol) ArrayList(java.util.ArrayList) ResourceType(io.zeebe.broker.workflow.data.ResourceType) Map(java.util.Map) PROP_WORKFLOW_VERSION(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_WORKFLOW_VERSION) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) UTF_8(java.nio.charset.StandardCharsets.UTF_8) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) RuleChain(org.junit.rules.RuleChain) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Rule(org.junit.Rule) StreamUtil(io.zeebe.util.StreamUtil) PROP_STATE(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_STATE) EventType(io.zeebe.protocol.clientapi.EventType) PROP_WORKFLOW_BPMN_PROCESS_ID(io.zeebe.broker.workflow.data.WorkflowInstanceEvent.PROP_WORKFLOW_BPMN_PROCESS_ID) Files(org.assertj.core.util.Files) Collections(java.util.Collections) InputStream(java.io.InputStream) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) HashMap(java.util.HashMap) Map(java.util.Map) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 18 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class TopicSubscriptionAcknowledgementTest method shouldResumeAtTailOnLongMaxAckPosition.

@Test
public void shouldResumeAtTailOnLongMaxAckPosition() {
    // given
    apiRule.createCmdRequest().eventTypeSubscription().command().put("name", SUBSCRIPTION_NAME).put("state", "ACKNOWLEDGE").put("ackPosition", Long.MAX_VALUE).done().sendAndAwait();
    closeSubscription();
    apiRule.moveMessageStreamToTail();
    // when
    openSubscription();
    // and
    final ExecuteCommandResponse response = apiRule.createCmdRequest().eventTypeTask().command().put("state", "CREATE").put("type", "theTaskType").done().sendAndAwait();
    final long taskKey = response.key();
    // then
    final Optional<SubscribedEvent> firstEvent = apiRule.subscribedEvents().findFirst();
    assertThat(firstEvent).isPresent();
    assertThat(firstEvent.get().key()).isEqualTo(taskKey);
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 19 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class FailTaskTest method shouldFailTask.

@Test
public void shouldFailTask() {
    // given
    client.createTask(TASK_TYPE);
    apiRule.openTaskSubscription(TASK_TYPE).await();
    final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
    // when
    final ExecuteCommandResponse response = client.failTask(subscribedEvent.key(), subscribedEvent.event());
    // then
    final Map<String, Object> expectedEvent = new HashMap<>(subscribedEvent.event());
    expectedEvent.put("state", "FAILED");
    assertThat(response.getEvent()).containsAllEntriesOf(expectedEvent);
    // and the task is published again
    final SubscribedEvent republishedEvent = receiveSingleSubscribedEvent();
    assertThat(republishedEvent.key()).isEqualTo(subscribedEvent.key());
    assertThat(republishedEvent.position()).isNotEqualTo(subscribedEvent.position());
    // and the task lifecycle is correct
    apiRule.openTopicSubscription("foo", 0).await();
    final int expectedTopicEvents = 8;
    final List<SubscribedEvent> taskEvents = doRepeatedly(() -> apiRule.moveMessageStreamToHead().subscribedEvents().filter(e -> e.subscriptionType() == SubscriptionType.TOPIC_SUBSCRIPTION).limit(expectedTopicEvents).collect(Collectors.toList())).until(e -> e.size() == expectedTopicEvents);
    assertThat(taskEvents).extracting(e -> e.event().get("state")).containsExactly("CREATE", "CREATED", "LOCK", "LOCKED", "FAIL", "FAILED", "LOCK", "LOCKED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TestTopicClient(io.zeebe.test.broker.protocol.clientapi.TestTopicClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) HashMap(java.util.HashMap) Test(org.junit.Test) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) Collectors(java.util.stream.Collectors) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) Duration(java.time.Duration) Map(java.util.Map) Before(org.junit.Before) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) HashMap(java.util.HashMap) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 20 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class TaskUpdateRetriesTest method shouldRejectUpdateRetriesIfRetriesLessThanZero.

@Test
public void shouldRejectUpdateRetriesIfRetriesLessThanZero() {
    // given
    client.createTask(TASK_TYPE);
    apiRule.openTaskSubscription(TASK_TYPE).await();
    final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
    Map<String, Object> event = subscribedEvent.event();
    event.put("retries", 0);
    final ExecuteCommandResponse failResponse = client.failTask(subscribedEvent.key(), event);
    event = failResponse.getEvent();
    event.put("retries", -1);
    // when
    final ExecuteCommandResponse response = client.updateTaskRetries(subscribedEvent.key(), event);
    // then
    assertThat(response.getEvent()).containsEntry("state", "UPDATE_RETRIES_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Aggregations

SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)57 Test (org.junit.Test)55 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)28 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)13 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 RuleChain (org.junit.rules.RuleChain)13 IOException (java.io.IOException)11 EventType (io.zeebe.protocol.clientapi.EventType)10 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)10 Bpmn (io.zeebe.model.bpmn.Bpmn)9 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)9 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)8 List (java.util.List)7 Map (java.util.Map)7 ErrorType (io.zeebe.broker.incident.data.ErrorType)6 JSON_MAPPER (io.zeebe.broker.test.MsgPackUtil.JSON_MAPPER)6