Search in sources :

Example 6 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl 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 7 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class UpdateTaskRetriesTest method shouldThrowExceptionOnRejection.

@Test
public void shouldThrowExceptionOnRejection() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "UPDATE_RETRIES").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "UPDATE_RETRIES_REJECTED").done().register();
    // then
    exception.expect(ClientCommandRejectedException.class);
    exception.expectMessage("Command for event with key 79 was rejected by broker (UPDATE_RETRIES_REJECTED)");
    // when
    clientRule.tasks().updateRetries(baseEvent).retries(5).execute();
}
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) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 8 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl 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)

Example 9 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class Events method exampleTask.

public static TaskEventImpl exampleTask() {
    final TaskEventImpl baseEvent = new TaskEventImpl("CREATED", new MsgPackConverter());
    baseEvent.setHeaders(Maps.newHashMap("defaultHeaderKey", "defaultHeaderVal"));
    baseEvent.setCustomHeaders(Maps.newHashMap("customHeaderKey", "customHeaderVal"));
    baseEvent.setKey(79);
    baseEvent.setLockOwner("foo");
    baseEvent.setLockTime(System.currentTimeMillis());
    baseEvent.setPartitionId(StubBrokerRule.TEST_PARTITION_ID);
    baseEvent.setPayload("{\"key\":\"val\"}");
    baseEvent.setRetries(123);
    baseEvent.setTopicName(ClientApiRule.DEFAULT_TOPIC_NAME);
    baseEvent.setType("taskTypeFoo");
    baseEvent.setEventPosition(456);
    return baseEvent;
}
Also used : TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter)

Example 10 with TaskEventImpl

use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.

the class TaskSubscriber method pollEvents.

public int pollEvents(TaskHandler taskHandler) {
    int polledEvents = pollEvents((e) -> {
        final TaskEventImpl taskEvent = msgPackMapper.convert(e.getAsMsgPack(), TaskEventImpl.class);
        taskEvent.updateMetadata(e.getMetadata());
        try {
            taskHandler.handle(taskClient, taskEvent);
        } catch (Exception handlingException) {
            LOGGER.info("An error occurred when handling task " + taskEvent.getMetadata().getKey() + ". Reporting failure to broker.", handlingException);
            try {
                taskClient.fail(taskEvent).retries(taskEvent.getRetries() - 1).execute();
            } catch (Exception failureException) {
                LOGGER.info("Could not report failure of task " + taskEvent.getMetadata().getKey() + " to broker. Continuing with next task", failureException);
            }
        }
    });
    return polledEvents;
}
Also used : TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl)

Aggregations

TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)19 Test (org.junit.Test)17 TaskEvent (io.zeebe.client.event.TaskEvent)14 ExpectedException (org.junit.rules.ExpectedException)13 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)12 Events (io.zeebe.client.util.Events)12 EventType (io.zeebe.protocol.clientapi.EventType)12 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 Rule (org.junit.Rule)12 TasksClient (io.zeebe.client.TasksClient)8 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)8 ClientRule (io.zeebe.client.util.ClientRule)8 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)8 Assertions.entry (org.assertj.core.api.Assertions.entry)8 RuleChain (org.junit.rules.RuleChain)8 Before (org.junit.Before)7 ClientException (io.zeebe.client.cmd.ClientException)5 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)4 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)4