Search in sources :

Example 6 with ExecuteCommandRequest

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

the class FailTaskTest method shouldFailTask.

@Test
public void shouldFailTask() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "FAIL").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "FAILED").done().register();
    // when
    final TaskEvent taskEvent = clientRule.tasks().fail(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", "FAIL"), 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("FAILED");
    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);
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) TaskEvent(io.zeebe.client.event.TaskEvent) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 7 with ExecuteCommandRequest

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

the class CreateTopicTest method shouldCreateTopic.

@Test
public void shouldCreateTopic() {
    // given
    brokerRule.onExecuteCommandRequest(Protocol.SYSTEM_PARTITION, EventType.TOPIC_EVENT, "CREATE").respondWith().key(123).position(456).event().allOf((r) -> r.getCommand()).put("state", "CREATED").done().register();
    // when
    final Event responseEvent = clientRule.topics().create("newTopic", 14).execute();
    // then
    final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(request.eventType()).isEqualTo(EventType.TOPIC_EVENT);
    assertThat(request.partitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
    assertThat(request.position()).isEqualTo(ExecuteCommandRequestEncoder.positionNullValue());
    assertThat(request.getCommand()).containsOnly(entry("state", "CREATE"), entry("name", "newTopic"), entry("partitions", 14));
    assertThat(responseEvent.getMetadata().getKey()).isEqualTo(123L);
    assertThat(responseEvent.getMetadata().getTopicName()).isEqualTo(Protocol.SYSTEM_TOPIC);
    assertThat(responseEvent.getMetadata().getPartitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
    assertThat(responseEvent.getMetadata().getPosition()).isEqualTo(456);
    assertThat(responseEvent.getState()).isEqualTo("CREATED");
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Event(io.zeebe.client.event.Event) Test(org.junit.Test) Protocol(io.zeebe.protocol.Protocol) Assertions.entry(org.assertj.core.api.Assertions.entry) ExecuteCommandRequestEncoder(io.zeebe.protocol.clientapi.ExecuteCommandRequestEncoder) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ExpectedException(org.junit.rules.ExpectedException) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Event(io.zeebe.client.event.Event) Test(org.junit.Test)

Example 8 with ExecuteCommandRequest

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

the class CancelWorkflowInstanceTest method shouldCancelWorkflowInstance.

@Test
public void shouldCancelWorkflowInstance() {
    // given
    final WorkflowInstanceEventImpl event = Events.exampleWorfklowInstance();
    event.setKey(2L);
    brokerRule.onWorkflowRequestRespondWith(2L).put("state", "WORKFLOW_INSTANCE_CANCELED").done().register();
    // when
    clientRule.workflows().cancel(event).execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.getCommand()).containsEntry("state", "CANCEL_WORKFLOW_INSTANCE");
    assertThat(commandRequest.key()).isEqualTo(2L);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) Test(org.junit.Test)

Example 9 with ExecuteCommandRequest

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

the class PartitionedTopicSubscriptionTest method shouldOverrideDefaultStartPosition.

@Test
public void shouldOverrideDefaultStartPosition() {
    // given
    broker1.stubTopicSubscriptionApi(456);
    broker2.stubTopicSubscriptionApi(789);
    final int position1 = 987;
    // when
    client.topics().newSubscription(TOPIC).name("hohoho").startAtTailOfTopic().startAtPosition(PARTITION_1, position1).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", -1);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 10 with ExecuteCommandRequest

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

the class PartitionedTopicSubscriptionTest method shouldSubscribeToMultiplePartitionsOfATopic.

@Test
public void shouldSubscribeToMultiplePartitionsOfATopic() {
    // given
    broker1.stubTopicSubscriptionApi(456);
    broker2.stubTopicSubscriptionApi(789);
    // when
    final TopicSubscription subscription = client.topics().newSubscription(TOPIC).handler(new RecordingEventHandler()).name("hohoho").open();
    // then
    assertThat(subscription.isOpen()).isTrue();
    final List<ExecuteCommandRequest> subscribeRequestsBroker1 = getSubscribeRequests(broker1);
    assertThat(subscribeRequestsBroker1).hasSize(1);
    final ExecuteCommandRequest request1 = subscribeRequestsBroker1.get(0);
    assertThat(request1.partitionId()).isEqualTo(PARTITION_1);
    final List<ExecuteCommandRequest> subscribeRequestsBroker2 = getSubscribeRequests(broker2);
    assertThat(subscribeRequestsBroker2).hasSize(1);
    final ExecuteCommandRequest request2 = subscribeRequestsBroker2.get(0);
    assertThat(request2.partitionId()).isEqualTo(PARTITION_2);
}
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