Search in sources :

Example 1 with ExecuteCommandRequest

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

the class PollableTopicSubscriptionTest method shouldOpenSubscriptionAndForceStart.

@Test
public void shouldOpenSubscriptionAndForceStart() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.getClient().topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().forcedStart().name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).containsEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 2 with ExecuteCommandRequest

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

the class PollableTopicSubscriptionTest method shouldOpenSubscription.

@Test
public void shouldOpenSubscription() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).containsEntry("state", "SUBSCRIBE").containsEntry("startPosition", 0).containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 3 with ExecuteCommandRequest

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

the class TopicSubscriptionTest method shouldOpenSubscriptionAndForceStart.

@Test
public void shouldOpenSubscriptionAndForceStart() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().forcedStart().handler(DO_NOTHING).name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).containsEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 4 with ExecuteCommandRequest

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

the class TopicSubscriptionTest method shouldOpenPollableSubscription.

@Test
public void shouldOpenPollableSubscription() {
    // given
    broker.stubTopicSubscriptionApi(123L);
    // when
    clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
    // then
    final ExecuteCommandRequest subscribeRequest = broker.getReceivedCommandRequests().stream().filter((e) -> e.eventType() == EventType.SUBSCRIBER_EVENT).findFirst().get();
    assertThat(subscribeRequest.getCommand()).containsEntry("state", "SUBSCRIBE").containsEntry("startPosition", 0).containsEntry("prefetchCapacity", 32).containsEntry("name", SUBSCRIPTION_NAME).doesNotContainEntry("forceStart", true);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Example 5 with ExecuteCommandRequest

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

the class CompleteTaskTest method shouldCompleteTask.

@Test
public void shouldCompleteTask() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
    final String updatedPayload = "{\"fruit\":\"cherry\"}";
    // when
    final TaskEvent taskEvent = clientRule.tasks().complete(baseEvent).payload(updatedPayload).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.position()).isEqualTo(baseEvent.getMetadata().getPosition());
    assertThat(request.getCommand()).containsOnly(entry("state", "COMPLETE"), entry("lockTime", baseEvent.getLockExpirationTime().toEpochMilli()), entry("lockOwner", baseEvent.getLockOwner()), entry("retries", baseEvent.getRetries()), entry("type", baseEvent.getType()), entry("headers", baseEvent.getHeaders()), entry("customHeaders", baseEvent.getCustomHeaders()), entry("payload", converter.convertToMsgPack(updatedPayload)));
    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("COMPLETED");
    assertThat(taskEvent.getHeaders()).isEqualTo(baseEvent.getHeaders());
    assertThat(taskEvent.getLockExpirationTime()).isEqualTo(baseEvent.getLockExpirationTime());
    assertThat(taskEvent.getLockOwner()).isEqualTo(baseEvent.getLockOwner());
    assertThat(taskEvent.getRetries()).isEqualTo(baseEvent.getRetries());
    assertThat(taskEvent.getType()).isEqualTo(baseEvent.getType());
    assertThat(taskEvent.getPayload()).isEqualTo(updatedPayload);
}
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) StandardCharsets(java.nio.charset.StandardCharsets) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) Rule(org.junit.Rule) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) 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)

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