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();
}
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);
}
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);
}
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");
}
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}"));
}
Aggregations