Search in sources :

Example 1 with MsgPackConverter

use of io.zeebe.client.impl.data.MsgPackConverter in project zeebe by zeebe-io.

the class ZeebeClientTest method shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined.

@Test
public void shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined() {
    // when
    final int nonExistingPartition = 999;
    final TaskEventImpl taskEvent = new TaskEventImpl("CREATED", new MsgPackConverter());
    taskEvent.setPartitionId(nonExistingPartition);
    assertThatThrownBy(() -> {
        client.tasks().complete(taskEvent).execute();
    });
    // +2 (one for the extra request when client is started)
    final long requestTimeout = Long.parseLong(client.getInitializationProperties().getProperty(ClientProperties.CLIENT_REQUEST_TIMEOUT_SEC));
    final long requestTimeoutMs = TimeUnit.SECONDS.toMillis(requestTimeout);
    final long expectedMaximumTopologyRequests = (requestTimeoutMs / ClientTopologyManager.MIN_REFRESH_INTERVAL_MILLIS.toMillis()) + 2;
    final long actualTopologyRequests = broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_TOPOLOGY).count();
    assertThat(actualTopologyRequests).isLessThanOrEqualTo(expectedMaximumTopologyRequests);
}
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) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Test(org.junit.Test)

Example 2 with MsgPackConverter

use of io.zeebe.client.impl.data.MsgPackConverter 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 3 with MsgPackConverter

use of io.zeebe.client.impl.data.MsgPackConverter in project zeebe by zeebe-io.

the class Events method exampleWorfklowInstance.

public static WorkflowInstanceEventImpl exampleWorfklowInstance() {
    final WorkflowInstanceEventImpl baseEvent = new WorkflowInstanceEventImpl("CREATED", new MsgPackConverter());
    baseEvent.setActivityId("some_activity");
    baseEvent.setBpmnProcessId("some_proceess");
    baseEvent.setKey(89);
    baseEvent.setPayloadAsJson("{\"key\":\"val\"}");
    baseEvent.setPartitionId(StubBrokerRule.TEST_PARTITION_ID);
    baseEvent.setTopicName(ClientApiRule.DEFAULT_TOPIC_NAME);
    baseEvent.setVersion(123);
    baseEvent.setWorkflowInstanceKey(456L);
    baseEvent.setWorkflowKey(789L);
    return baseEvent;
}
Also used : WorkflowInstanceEventImpl(io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter)

Aggregations

MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)3 TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)2 ClientTopologyManager (io.zeebe.client.clustering.impl.ClientTopologyManager)1 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)1 ClientException (io.zeebe.client.cmd.ClientException)1 TaskEvent (io.zeebe.client.event.TaskEvent)1 TopicSubscription (io.zeebe.client.event.TopicSubscription)1 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)1 Events (io.zeebe.client.util.Events)1 WorkflowInstanceEventImpl (io.zeebe.client.workflow.impl.WorkflowInstanceEventImpl)1 Protocol (io.zeebe.protocol.Protocol)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 EventType (io.zeebe.protocol.clientapi.EventType)1 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)1 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)1 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)1 ClientTransport (io.zeebe.transport.ClientTransport)1 RemoteAddress (io.zeebe.transport.RemoteAddress)1 ServerTransport (io.zeebe.transport.ServerTransport)1 TransportListener (io.zeebe.transport.TransportListener)1