Search in sources :

Example 26 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldCreateDeployment.

@Test
public void shouldCreateDeployment() {
    // given
    final List<Map<String, Object>> deployedWorkflows = new ArrayList<>();
    Map<String, Object> deployedWorkflow = new HashMap<>();
    deployedWorkflow.put("bpmnProcessId", "foo");
    deployedWorkflow.put("version", 1);
    deployedWorkflows.add(deployedWorkflow);
    deployedWorkflow = new HashMap<>();
    deployedWorkflow.put("bpmnProcessId", "bar");
    deployedWorkflow.put("version", 2);
    deployedWorkflows.add(deployedWorkflow);
    brokerRule.onExecuteCommandRequest(r -> r.eventType() == DEPLOYMENT_EVENT).respondWith().key(2L).event().put("state", "CREATED").put("deployedWorkflows", deployedWorkflows).done().register();
    // when
    final DeploymentEvent deployment = clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addWorkflowModel(WORKFLOW_MODEL, "model.bpmn").execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.key()).isEqualTo(-1);
    assertThat(commandRequest.getCommand()).containsEntry("state", "CREATE");
    assertThat(deployment.getMetadata().getKey()).isEqualTo(2L);
    assertThat(deployment.getDeployedWorkflows()).hasSize(2);
    assertThat(deployment.getDeployedWorkflows()).extracting("bpmnProcessId").contains("foo", "bar");
    assertThat(deployment.getDeployedWorkflows()).extracting("version").contains(1, 2);
}
Also used : DEPLOYMENT_EVENT(io.zeebe.protocol.clientapi.EventType.DEPLOYMENT_EVENT) java.util(java.util) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) Protocol(io.zeebe.protocol.Protocol) File(java.io.File) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) org.junit(org.junit) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) ExpectedException(org.junit.rules.ExpectedException) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 27 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldDeployResourceAsString.

@SuppressWarnings("unchecked")
@Test
public void shouldDeployResourceAsString() {
    // given
    stubDeploymentRequest();
    // when
    clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addResourceStringUtf8(Bpmn.convertToString(WORKFLOW_MODEL), "workflow.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)).containsEntry("resource", WORKFLOW_AS_BYTES).containsEntry("resourceName", "workflow.bpmn").containsEntry("resourceType", "BPMN_XML");
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)

Example 28 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldSendDeploymentRequestToSystemTopic.

@Test
public void shouldSendDeploymentRequestToSystemTopic() {
    // given
    brokerRule.onExecuteCommandRequest(Protocol.SYSTEM_PARTITION, DEPLOYMENT_EVENT, "CREATE").respondWith().key(2L).event().put("state", "CREATED").done().register();
    // when
    final DeploymentEvent deployment = clientRule.workflows().deploy("test-topic").addWorkflowModel(WORKFLOW_MODEL, "model.bpmn").execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.partitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
    assertThat(commandRequest.getCommand()).containsEntry("topicName", "test-topic");
    assertThat(deployment.getMetadata().getTopicName()).isEqualTo(Protocol.SYSTEM_TOPIC);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 29 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class UpdatePayloadTest method shouldUpdatePayload.

@Test
public void shouldUpdatePayload() {
    // given
    final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
    event.setKey(2L);
    event.setWorkflowInstanceKey(1L);
    brokerRule.onExecuteCommandRequest().respondWith().key(r -> r.key()).event().put("state", "PAYLOAD_UPDATED").done().register();
    // when
    workflowTopicClient.updatePayload(event).payload(PAYLOAD).execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.eventType()).isEqualTo(EventType.WORKFLOW_INSTANCE_EVENT);
    assertThat(request.key()).isEqualTo(2L);
    assertThat(request.getCommand()).containsEntry("state", "UPDATE_PAYLOAD").containsEntry("workflowInstanceKey", 1).containsEntry("payload", ENCODED_PAYLOAD);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test)

Example 30 with ExecuteCommandRequest

use of io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest in project zeebe by zeebe-io.

the class PartitionedTopicSubscriptionTest method shouldReopenIndividualSubscriptions.

@Test
public void shouldReopenIndividualSubscriptions() {
    // given
    broker1.stubTopicSubscriptionApi(456);
    broker2.stubTopicSubscriptionApi(789);
    final String subscriptionName = "hohoho";
    final TopicSubscription subscription = client.topics().newSubscription(TOPIC).handler(new RecordingEventHandler()).name(subscriptionName).open();
    // when
    broker1.interruptAllServerChannels();
    // then
    final List<ExecuteCommandRequest> subscribeRequestsBroker1 = doRepeatedly(() -> getSubscribeRequests(broker1)).until(r -> r.size() == 2);
    assertThat(subscription.isOpen()).isTrue();
    final ExecuteCommandRequest request1 = subscribeRequestsBroker1.get(0);
    assertThat(request1.partitionId()).isEqualTo(PARTITION_1);
    assertThat(request1.getCommand().get("name")).isEqualTo(subscriptionName);
    final ExecuteCommandRequest request2 = subscribeRequestsBroker1.get(1);
    assertThat(request2.partitionId()).isEqualTo(PARTITION_1);
    assertThat(request2.getCommand().get("name")).isEqualTo(subscriptionName);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Aggregations

ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)41 Test (org.junit.Test)30 ClientRule (io.zeebe.client.util.ClientRule)15 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)15 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)15 ExpectedException (org.junit.rules.ExpectedException)15 RuleChain (org.junit.rules.RuleChain)15 EventType (io.zeebe.protocol.clientapi.EventType)14 Rule (org.junit.Rule)14 Assertions.entry (org.assertj.core.api.Assertions.entry)12 TaskEvent (io.zeebe.client.event.TaskEvent)11 Before (org.junit.Before)11 ZeebeClient (io.zeebe.client.ZeebeClient)10 TasksClient (io.zeebe.client.TasksClient)9 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)9 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)6 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)6 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)6