Search in sources :

Example 11 with TaskEventImpl

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

the class ZeebeClientTest method shouldReleaseRequestsOnTimeout.

@Test
public void shouldReleaseRequestsOnTimeout() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").doNotRespond();
    // given
    final List<Future<TaskEvent>> futures = new ArrayList<>();
    for (int i = 0; i < clientMaxRequests; i++) {
        futures.add(client.tasks().complete(baseEvent).executeAsync());
    }
    // when
    for (Future<TaskEvent> future : futures) {
        try {
            future.get();
            fail("exception expected");
        } catch (Exception e) {
        // expected
        }
    }
    // then
    for (int i = 0; i < clientMaxRequests; i++) {
        futures.add(client.tasks().complete(baseEvent).executeAsync());
    }
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) ClientException(io.zeebe.client.cmd.ClientException) Test(org.junit.Test)

Example 12 with TaskEventImpl

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

the class ZeebeClientTest method shouldThrowExceptionOnTimeout.

@Test
public void shouldThrowExceptionOnTimeout() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").doNotRespond();
    // then
    exception.expect(ClientException.class);
    exception.expectMessage("Request timed out (PT3S). " + "Request was: [ topic = default-topic, partition = 99, event type = TASK, state = COMPLETE ]");
    // when
    client.tasks().complete(baseEvent).execute();
}
Also used : TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 13 with TaskEventImpl

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

the class ZeebeClientTest method shouldIncludeCallingFrameInExceptionStacktrace.

@Test
public void shouldIncludeCallingFrameInExceptionStacktrace() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETE_REJECTED").done().register();
    // when
    try {
        client.tasks().complete(baseEvent).execute();
        fail("should throw exception");
    } catch (ClientCommandRejectedException e) {
        // then
        assertThat(e.getStackTrace()).anySatisfy(frame -> {
            assertThat(frame.getClassName()).isEqualTo(this.getClass().getName());
            assertThat(frame.getMethodName()).isEqualTo(testContext.getMethodName());
        });
    }
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) java.util(java.util) Events(io.zeebe.client.util.Events) TransportListener(io.zeebe.transport.TransportListener) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) ClientTopologyManager(io.zeebe.client.clustering.impl.ClientTopologyManager) Protocol(io.zeebe.protocol.Protocol) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) TopicSubscription(io.zeebe.client.event.TopicSubscription) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RemoteAddress(io.zeebe.transport.RemoteAddress) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestName(org.junit.rules.TestName) After(org.junit.After) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) java.util.concurrent(java.util.concurrent) ServerTransport(io.zeebe.transport.ServerTransport) Test(org.junit.Test) ClientTransport(io.zeebe.transport.ClientTransport) Assertions.fail(org.assertj.core.api.Assertions.fail) Rule(org.junit.Rule) ClientException(io.zeebe.client.cmd.ClientException) EventType(io.zeebe.protocol.clientapi.EventType) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 14 with TaskEventImpl

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

the class ZeebeClientTopologyTimeoutTest method shouldFailRequestIfTopologyCannotBeRefreshed.

@Test
public void shouldFailRequestIfTopologyCannotBeRefreshed() {
    // given
    broker.onTopologyRequest().doNotRespond();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").doNotRespond();
    final TaskEventImpl baseEvent = Events.exampleTask();
    final ZeebeClient client = buildClient();
    // then
    exception.expect(ClientException.class);
    exception.expectMessage("Request timed out (PT1S). " + "Request was: [ topic = default-topic, partition = 99, event type = TASK, state = COMPLETE ]");
    // when
    client.tasks().complete(baseEvent).execute();
}
Also used : TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Example 15 with TaskEventImpl

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

the class ZeebeObjectMapperTest method convertTaskEntityFromToJson.

@Test
public void convertTaskEntityFromToJson() throws IOException {
    final Map<String, Object> headers = new HashMap<>();
    headers.put("activityId", "task_doSomething");
    headers.put("workflowKey", 4294975304L);
    headers.put("workflowInstanceKey", 4294975520L);
    headers.put("bpmnProcessId", "process_dummy");
    headers.put("activityInstanceKey", 4294976512L);
    headers.put("workflowDefinitionVersion", 1);
    final Map<String, Object> customHeaders = new HashMap<>();
    customHeaders.put("some", "value");
    final TaskEventImpl task = new TaskEventImpl("CREATED", objectMapper.getMsgPackConverter());
    task.setTopicName("topic");
    task.setPartitionId(1);
    task.setEventPosition(10L);
    task.setKey(20L);
    task.setType("type");
    task.setRetries(3);
    task.setPayload("{\"foo\":\"bar\"}");
    task.setLockTime(1000L);
    task.setHeaders(headers);
    task.setLockOwner("owner");
    task.setCustomHeaders(customHeaders);
    final byte[] json = objectMapper.writeValueAsBytes(task);
    // since equals/hashcode is not implemented on taskEvent, use the comparision of toString
    assertThat(objectMapper.readValue(json, TaskEventImpl.class).toString()).isEqualTo(task.toString());
}
Also used : HashMap(java.util.HashMap) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

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