Search in sources :

Example 1 with TaskHandler

use of io.zeebe.client.task.TaskHandler in project zeebe by zeebe-io.

the class RecordingTaskHandler method handle.

@Override
public void handle(TasksClient client, TaskEvent task) {
    final TaskHandler handler = taskHandlers[nextTaskHandler];
    nextTaskHandler = Math.min(nextTaskHandler + 1, taskHandlers.length - 1);
    try {
        handler.handle(client, task);
    } finally {
        handledTasks.add(task);
    }
}
Also used : TaskHandler(io.zeebe.client.task.TaskHandler)

Example 2 with TaskHandler

use of io.zeebe.client.task.TaskHandler in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldNotLoseCreditsOnFailureToReportTaskFailure.

/**
 * i.e. if signalling task failure itself fails
 */
@Test
public void shouldNotLoseCreditsOnFailureToReportTaskFailure() throws InterruptedException {
    // given
    broker.stubTaskSubscriptionApi(123L);
    failTaskFailure();
    final int subscriptionCapacity = 8;
    final AtomicInteger failedTasks = new AtomicInteger(0);
    final TaskHandler taskHandler = (c, t) -> {
        failedTasks.incrementAndGet();
        throw new RuntimeException("foo");
    };
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(taskHandler).lockOwner("owner").lockTime(1000L).taskFetchSize(subscriptionCapacity).taskType("foo").open();
    final RemoteAddress clientAddress = broker.getReceivedControlMessageRequests().get(0).getSource();
    for (int i = 0; i < subscriptionCapacity; i++) {
        broker.pushLockedTask(clientAddress, 123L, i, i, "owner", "foo");
    }
    // when
    TestUtil.waitUntil(() -> failedTasks.get() == 8);
    // give the client a bit of time to submit credits; this is not coupled to any defined event, so we just sleep for a bit
    Thread.sleep(500L);
    // then
    final List<ControlMessageRequest> creditRequests = getCreditRequests().collect(Collectors.toList());
    assertThat(creditRequests).isNotEmpty();
    final int numSubmittedCredits = creditRequests.stream().mapToInt((r) -> (int) r.getData().get("credits")).sum();
    assertThat(numSubmittedCredits).isGreaterThan(0);
}
Also used : TasksClient(io.zeebe.client.TasksClient) TaskEvent(io.zeebe.client.event.TaskEvent) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) HashMap(java.util.HashMap) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) RemoteAddress(io.zeebe.transport.RemoteAddress) ClientRule(io.zeebe.client.util.ClientRule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) After(org.junit.After) ExpectedException(org.junit.rules.ExpectedException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) MsgPackHelper(io.zeebe.test.broker.protocol.MsgPackHelper) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Properties(java.util.Properties) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) TaskSubscription(io.zeebe.client.task.TaskSubscription) Instant(java.time.Instant) Assertions.entry(org.assertj.core.api.Assertions.entry) Collectors(java.util.stream.Collectors) TasksClientImpl(io.zeebe.client.impl.TasksClientImpl) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) EventType(io.zeebe.protocol.clientapi.EventType) ClientProperties(io.zeebe.client.ClientProperties) TaskHandler(io.zeebe.client.task.TaskHandler) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Subscriber(io.zeebe.client.task.impl.subscription.Subscriber) TestUtil(io.zeebe.test.util.TestUtil) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) RemoteAddress(io.zeebe.transport.RemoteAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TaskHandler(io.zeebe.client.task.TaskHandler) Test(org.junit.Test)

Example 3 with TaskHandler

use of io.zeebe.client.task.TaskHandler in project zeebe by zeebe-io.

the class RecordingTaskHandler method handle.

@Override
public void handle(TasksClient client, TaskEvent task) {
    final TaskHandler handler = taskHandlers[nextTaskHandler];
    nextTaskHandler = Math.min(nextTaskHandler + 1, taskHandlers.length - 1);
    try {
        handler.handle(client, task);
    } finally {
        handledTasks.add(task);
    }
}
Also used : TaskHandler(io.zeebe.client.task.TaskHandler)

Aggregations

TaskHandler (io.zeebe.client.task.TaskHandler)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClientProperties (io.zeebe.client.ClientProperties)1 TasksClient (io.zeebe.client.TasksClient)1 ZeebeClient (io.zeebe.client.ZeebeClient)1 TaskEvent (io.zeebe.client.event.TaskEvent)1 TasksClientImpl (io.zeebe.client.impl.TasksClientImpl)1 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)1 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)1 PollableTaskSubscription (io.zeebe.client.task.PollableTaskSubscription)1 TaskSubscription (io.zeebe.client.task.TaskSubscription)1 Subscriber (io.zeebe.client.task.impl.subscription.Subscriber)1 ClientRule (io.zeebe.client.util.ClientRule)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)1 EventType (io.zeebe.protocol.clientapi.EventType)1 SubscriptionType (io.zeebe.protocol.clientapi.SubscriptionType)1 MsgPackHelper (io.zeebe.test.broker.protocol.MsgPackHelper)1