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);
}
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");
}
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);
}
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);
}
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);
}
Aggregations