Search in sources :

Example 11 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class PartitionedTopicSubscriptionTest method shouldSerializeHandlerInvocationForDifferentSubscribers.

@Test
public void shouldSerializeHandlerInvocationForDifferentSubscribers() {
    // given
    final int subscriberKey1 = 456;
    broker1.stubTopicSubscriptionApi(subscriberKey1);
    final int subscriberKey2 = 789;
    broker2.stubTopicSubscriptionApi(subscriberKey2);
    final ParallelismDetectionHandler eventHandler = new ParallelismDetectionHandler(Duration.ofMillis(500));
    client.topics().newSubscription(TOPIC).name("hohoho").handler(eventHandler).open();
    final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedCommandRequests().get(0).getSource();
    final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedCommandRequests().get(0).getSource();
    // when
    broker1.pushTopicEvent(clientAddressFromBroker1, b -> b.partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(3));
    broker2.pushTopicEvent(clientAddressFromBroker2, b -> b.partitionId(PARTITION_2).subscriberKey(subscriberKey2).key(4));
    waitUntil(() -> eventHandler.numInvocations() == 2);
    // then
    assertThat(eventHandler.hasDetectedParallelism()).isFalse();
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) Test(org.junit.Test)

Example 12 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class PartitionedTopicSubscriptionTest method shouldSumWorkCountOfPollableSubscription.

@Test
public void shouldSumWorkCountOfPollableSubscription() {
    // given
    final int subscriberKey1 = 456;
    broker1.stubTopicSubscriptionApi(subscriberKey1);
    final int subscriberKey2 = 789;
    broker2.stubTopicSubscriptionApi(subscriberKey2);
    final RecordingEventHandler eventHandler = new RecordingEventHandler();
    final PollableTopicSubscription subscription = client.topics().newPollableSubscription(TOPIC).name("hohoho").open();
    final RemoteAddress clientAddressFromBroker1 = broker1.getReceivedCommandRequests().get(0).getSource();
    final RemoteAddress clientAddressFromBroker2 = broker2.getReceivedCommandRequests().get(0).getSource();
    broker1.pushTopicEvent(clientAddressFromBroker1, b -> b.partitionId(PARTITION_1).subscriberKey(subscriberKey1).key(3));
    broker2.pushTopicEvent(clientAddressFromBroker2, b -> b.partitionId(PARTITION_2).subscriberKey(subscriberKey2).key(4));
    waitUntil(() -> ((SubscriberGroup<?>) subscription).size() == 2);
    // when
    final int polledEvents = subscription.poll(eventHandler);
    // then
    assertThat(polledEvents).isEqualTo(2);
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) SubscriberGroup(io.zeebe.client.task.impl.subscription.SubscriberGroup) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) Test(org.junit.Test)

Example 13 with RemoteAddress

use of io.zeebe.transport.RemoteAddress 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 14 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldInvokeTaskHandlerForPollableSubscription.

@Test
public void shouldInvokeTaskHandlerForPollableSubscription() {
    // given
    broker.stubTaskSubscriptionApi(123L);
    stubTaskCompleteRequest();
    final RecordingTaskHandler handler = new RecordingTaskHandler();
    final PollableTaskSubscription subscription = clientRule.tasks().newPollableTaskSubscription(clientRule.getDefaultTopicName()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
    final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
    broker.pushLockedTask(clientAddress, 123L, 4L, 5L, "foo", "type");
    // when
    final Integer handledTasks = TestUtil.doRepeatedly(() -> subscription.poll(handler)).until(numTasks -> numTasks > 0);
    // then
    assertThat(handledTasks).isEqualTo(1);
    assertThat(handler.getHandledTasks()).hasSize(1);
    final TaskEvent task = handler.getHandledTasks().get(0);
    assertThat(task.getMetadata().getKey()).isEqualTo(4L);
    assertThat(task.getType()).isEqualTo("type");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemoteAddress(io.zeebe.transport.RemoteAddress) PollableTaskSubscription(io.zeebe.client.task.PollableTaskSubscription) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 15 with RemoteAddress

use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldSetPayloadAndCompleteTask.

@Test
public void shouldSetPayloadAndCompleteTask() {
    // given
    broker.stubTaskSubscriptionApi(123L);
    stubTaskCompleteRequest();
    clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> c.complete(t).payload("{\"a\": 1}").execute()).lockOwner("foo").lockTime(10000L).taskType("bar").open();
    final RemoteAddress eventSource = getSubscribeRequests().findFirst().get().getSource();
    // when
    broker.pushLockedTask(eventSource, 123L, 4L, 5L, "foo", "bar");
    // then
    final ExecuteCommandRequest taskRequest = TestUtil.doRepeatedly(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.TASK_EVENT).findFirst()).until(r -> r.isPresent()).get();
    assertThat(taskRequest.partitionId()).isEqualTo(clientRule.getDefaultPartitionId());
    assertThat(taskRequest.key()).isEqualTo(4L);
    assertThat(taskRequest.getCommand()).containsEntry("state", "COMPLETE").containsEntry("type", "bar").containsEntry("lockOwner", "foo").containsEntry("payload", msgPackConverter.convertToMsgPack("{\"a\": 1}"));
}
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) RemoteAddress(io.zeebe.transport.RemoteAddress) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) Test(org.junit.Test)

Aggregations

RemoteAddress (io.zeebe.transport.RemoteAddress)35 Test (org.junit.Test)34 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)12 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)12 ZeebeClient (io.zeebe.client.ZeebeClient)11 ClientRule (io.zeebe.client.util.ClientRule)11 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)11 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)11 EventType (io.zeebe.protocol.clientapi.EventType)11 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)11 TestUtil (io.zeebe.test.util.TestUtil)11 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)11 Duration (java.time.Duration)11 List (java.util.List)11 TimeUnit (java.util.concurrent.TimeUnit)11 Collectors (java.util.stream.Collectors)11 Stream (java.util.stream.Stream)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11