use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldRetryWithMoreTasksThanSubscriptionCapacity.
/**
* This tests a case that should not occur under normal circumstances, but might occur
* in case of inconsistencies between broker and client state (e.g. due to bugs in either of them)
*/
@Test
public void shouldRetryWithMoreTasksThanSubscriptionCapacity() throws InterruptedException {
// given
broker.stubTaskSubscriptionApi(123L);
broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key((r) -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
final WaitingTaskHandler handler = new WaitingTaskHandler();
final Properties clientProperties = ((ZeebeClientImpl) client).getInitializationProperties();
final int numExecutionThreads = Integer.parseInt(clientProperties.getProperty(ClientProperties.CLIENT_SUBSCRIPTION_EXECUTION_THREADS));
final int taskCapacity = 4;
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler).lockOwner("owner").lockTime(1000L).taskFetchSize(taskCapacity).taskType("foo").open();
final RemoteAddress clientAddress = broker.getReceivedControlMessageRequests().get(0).getSource();
for (int i = 0; i < taskCapacity + numExecutionThreads; i++) {
broker.pushLockedTask(clientAddress, 123L, i, i, "owner", "foo");
}
TestUtil.waitUntil(() -> handler.numWaitingThreads.get() > 0);
// pushing one more event, exceeding client capacity
broker.pushLockedTask(clientAddress, 123L, Integer.MAX_VALUE, Integer.MAX_VALUE, "owner", "foo");
// waiting for the client to receive all pending tasks
Thread.sleep(500L);
// when
handler.shouldWait = false;
continueTaskHandlingThreads();
// then the additional event is handled nevertheless (i.e. client applies backpressure)
TestUtil.waitUntil(() -> handler.numHandledEvents.get() == taskCapacity + numExecutionThreads + 1);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class CreateTopicTest method shouldRejectPartitionCreationAndNotBreak.
@Test
public void shouldRejectPartitionCreationAndNotBreak() {
// given
final ClientTransport transport = apiRule.getTransport();
final RemoteAddress remoteAddress = transport.registerRemoteAndAwaitChannel(BROKER_MGMT_ADDRESS);
final ClientOutput output = transport.getOutput();
final CreatePartitionRequest partitionMessage = new CreatePartitionRequest();
final DirectBuffer topicName = BufferUtil.wrapString("foo");
final int partition1 = 142;
final int partition2 = 143;
partitionMessage.topicName(topicName);
partitionMessage.partitionId(partition1);
// => should create partition
doRepeatedly(() -> output.sendRequest(remoteAddress, partitionMessage)).until(r -> r != null);
// => should be rejected/ignored
doRepeatedly(() -> output.sendRequest(remoteAddress, partitionMessage)).until(r -> r != null);
// when creating another partition
partitionMessage.partitionId(partition2);
doRepeatedly(() -> output.sendRequest(remoteAddress, partitionMessage)).until(r -> r != null);
// then this should be successful (i.e. the rejected request should not have jammed the broker)
waitUntil(() -> arePublished(partition1, partition2));
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class RemoteWorkflowsManager method sendMessage.
private boolean sendMessage(final BufferWriter message, final SocketAddress addr) {
final RemoteAddress remoteAddress = managementClient.registerRemoteAddress(addr);
transportMessage.remoteAddress(remoteAddress).writer(message);
return output.sendMessage(transportMessage);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldInvokeTaskHandler.
@Test
public void shouldInvokeTaskHandler() throws JsonParseException, JsonMappingException, IOException {
// given
broker.stubTaskSubscriptionApi(123L);
stubTaskCompleteRequest();
final RecordingTaskHandler handler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler).lockOwner("owner").lockTime(10000L).taskType("type").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
final MsgPackHelper msgPackHelper = new MsgPackHelper();
final Map<String, Object> taskPayload = new HashMap<>();
taskPayload.put("payloadKey", "payloadValue");
final Map<String, Object> taskHeaders = new HashMap<>();
taskPayload.put("headerKey", "headerValue");
final long lockTime = System.currentTimeMillis();
// when
broker.newSubscribedEvent().partitionId(StubBrokerRule.TEST_PARTITION_ID).key(4L).position(5L).eventType(EventType.TASK_EVENT).subscriberKey(123L).subscriptionType(SubscriptionType.TASK_SUBSCRIPTION).event().put("type", "type").put("lockTime", lockTime).put("retries", 3).put("payload", msgPackHelper.encodeAsMsgPack(taskPayload)).put("headers", taskHeaders).done().push(clientAddress);
// then
TestUtil.waitUntil(() -> !handler.getHandledTasks().isEmpty());
assertThat(handler.getHandledTasks()).hasSize(1);
final TaskEvent task = handler.getHandledTasks().get(0);
assertThat(task.getMetadata().getKey()).isEqualTo(4L);
assertThat(task.getType()).isEqualTo("type");
assertThat(task.getHeaders()).isEqualTo(taskHeaders);
assertThat(task.getLockExpirationTime()).isEqualTo(Instant.ofEpochMilli(lockTime));
final ObjectMapper objectMapper = new ObjectMapper();
@SuppressWarnings("unchecked") final Map<String, Object> receivedPayload = objectMapper.readValue(task.getPayload(), Map.class);
assertThat(receivedPayload).isEqualTo(taskPayload);
}
use of io.zeebe.transport.RemoteAddress in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldMarkTaskAsFailedOnExpcetion.
@Test
public void shouldMarkTaskAsFailedOnExpcetion() {
// given
broker.stubTaskSubscriptionApi(123L);
broker.onExecuteCommandRequest(isTaskFailCommand()).respondWith().event().allOf(r -> r.getCommand()).put("state", "FAILED").done().register();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler((c, t) -> {
throw new RuntimeException("expected failure");
}).lockOwner("foo").lockTime(10000L).taskType("bar").open();
final RemoteAddress clientAddress = getSubscribeRequests().findFirst().get().getSource();
// when
broker.pushLockedTask(clientAddress, 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", "FAIL").containsEntry("type", "bar").containsEntry("lockOwner", "foo");
}
Aggregations