Search in sources :

Example 26 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class ZeebeClientTopologyTimeoutTest method shouldRetryTopologyRequestAfterTimeout.

@Test
public void shouldRetryTopologyRequestAfterTimeout() {
    // given
    final int topologyTimeoutSeconds = 1;
    broker.onTopologyRequest().doNotRespond();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
    final TaskEventImpl baseEvent = Events.exampleTask();
    final ZeebeClient client = buildClient();
    // wait for a hanging topology request
    waitUntil(() -> broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_TOPOLOGY).count() == 1);
    // make topology available
    broker.stubTopologyRequest();
    // let request time out
    clientClock.addTime(Duration.ofSeconds(topologyTimeoutSeconds + 1));
    // when making a new request
    final TaskEvent response = client.tasks().complete(baseEvent).execute();
    // then the topology has been refreshed and the request succeeded
    assertThat(response.getState()).isEqualTo("COMPLETED");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Events(io.zeebe.client.util.Events) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Properties(java.util.Properties) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) Test(org.junit.Test) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) ControlledActorClock(io.zeebe.util.sched.clock.ControlledActorClock) Rule(org.junit.Rule) ClientException(io.zeebe.client.cmd.ClientException) EventType(io.zeebe.protocol.clientapi.EventType) Duration(java.time.Duration) After(org.junit.After) ExpectedException(org.junit.rules.ExpectedException) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) TaskEvent(io.zeebe.client.event.TaskEvent) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 27 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class ClientCommandManagerTest method testRefreshTopologyRequest.

@Test
public void testRefreshTopologyRequest() {
    // given
    // initial topology has been fetched
    waitUntil(() -> broker.getReceivedControlMessageRequests().size() == 1);
    stubCreateTaskResponse();
    // extend topology
    broker.addTopic("other-topic", 0);
    // when
    final TaskEvent taskEvent = createTaskCmd("other-topic").execute();
    // then the client has refreshed its topology
    assertThat(taskEvent).isNotNull();
    assertTopologyRefreshRequests(2);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 28 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class ClientCommandManagerTest method testRefreshTopologyWhenLeaderIsNotKnown.

@Test
public void testRefreshTopologyWhenLeaderIsNotKnown() {
    // given
    // initial topology has been fetched
    waitUntil(() -> broker.getReceivedControlMessageRequests().size() == 1);
    stubCompleteTaskResponse();
    // extend topology
    broker.addTopic("other-topic", 1);
    final TaskEventImpl task = Events.exampleTask();
    task.setTopicName("other-topic");
    task.setPartitionId(1);
    // when
    final TaskEvent result = client.tasks().complete(task).execute();
    // then the client has refreshed its topology
    assertThat(result).isNotNull();
    assertTopologyRefreshRequests(2);
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 29 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class CreateTaskTest method shouldCreateTaskWithDefaultValues.

@Test
public void shouldCreateTaskWithDefaultValues() {
    // given
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "CREATE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "CREATED").put("headers", new HashMap<>()).put("payload", MsgPackUtil.encodeMsgPack(w -> w.packNil()).byteArray()).done().register();
    // when
    final TaskEvent taskEvent = clientRule.tasks().create(clientRule.getDefaultTopicName(), "fooType").execute();
    // then
    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.getRetries()).isEqualTo(CreateTaskCommand.DEFAULT_RETRIES);
    assertThat(taskEvent.getHeaders()).isEmpty();
    assertThat(taskEvent.getPayload()).isEqualTo("null");
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) Maps(org.assertj.core.util.Maps) ActorSchedulerRule(io.zeebe.util.sched.testing.ActorSchedulerRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Test(org.junit.Test) Protocol(io.zeebe.protocol.Protocol) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) 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) MsgPackUtil(io.zeebe.test.util.MsgPackUtil) ByteArrayInputStream(java.io.ByteArrayInputStream) EventType(io.zeebe.protocol.clientapi.EventType) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) CreateTaskCommand(io.zeebe.client.task.cmd.CreateTaskCommand) HashMap(java.util.HashMap) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 30 with TaskEvent

use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.

the class UpdateTaskRetriesTest method shouldUpdateRetries.

@Test
public void shouldUpdateRetries() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "UPDATE_RETRIES").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "RETRIES_UPDATED").done().register();
    // when
    final TaskEvent taskEvent = clientRule.tasks().updateRetries(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", "UPDATE_RETRIES"), 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("RETRIES_UPDATED");
    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)

Aggregations

TaskEvent (io.zeebe.client.event.TaskEvent)47 Test (org.junit.Test)43 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)20 ExpectedException (org.junit.rules.ExpectedException)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 Rule (org.junit.Rule)9 ZeebeClient (io.zeebe.client.ZeebeClient)7 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)7 TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)7 EventType (io.zeebe.protocol.clientapi.EventType)7 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)7 RuleChain (org.junit.rules.RuleChain)7 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 ClientRule (io.zeebe.client.util.ClientRule)5 Events (io.zeebe.client.util.Events)5 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)5 SocketAddress (io.zeebe.transport.SocketAddress)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Assertions.entry (org.assertj.core.api.Assertions.entry)5 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)4