use of io.zeebe.test.broker.protocol.MsgPackHelper in project zeebe by zeebe-io.
the class TopicSubscriptionTest method asCommandResponse.
protected static ExecuteCommandResponse asCommandResponse(RawMessage message) {
final ExecuteCommandResponse response = new ExecuteCommandResponse(new MsgPackHelper());
response.wrap(message.getMessage(), 0, message.getMessage().capacity());
return response;
}
use of io.zeebe.test.broker.protocol.MsgPackHelper 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.test.broker.protocol.MsgPackHelper in project zeebe by zeebe-io.
the class ClientApiRule method before.
@Override
protected void before() throws Throwable {
scheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(1).setActorClock(controlledActorClock).build();
scheduler.start();
sendBuffer = Dispatchers.create("clientSendBuffer").bufferSize(32 * 1024 * 1024).actorScheduler(scheduler).build();
incomingMessageCollector = new RawMessageCollector();
transport = Transports.newClientTransport().inputListener(incomingMessageCollector).scheduler(scheduler).requestPoolSize(128).sendBuffer(sendBuffer).build();
msgPackHelper = new MsgPackHelper();
streamAddress = transport.registerRemoteAddress(brokerAddress);
doRepeatedly(() -> getPartitionIds(Protocol.SYSTEM_TOPIC)).until(l -> l != null, e -> e == null);
if (createDefaultTopic) {
createTopic(DEFAULT_TOPIC_NAME, 1);
defaultPartitionId = getSinglePartitionId(DEFAULT_TOPIC_NAME);
}
}
use of io.zeebe.test.broker.protocol.MsgPackHelper in project zeebe by zeebe-io.
the class StubBrokerRule method before.
@Override
protected void before() throws Throwable {
msgPackHelper = new MsgPackHelper();
final int numThreads = 2;
scheduler = ActorScheduler.newActorScheduler().setCpuBoundActorThreadCount(numThreads).setActorClock(clock).build();
scheduler.start();
sendBuffer = Dispatchers.create("send-buffer").actorScheduler(scheduler).bufferSize(1024 * 1024).build();
channelHandler = new StubResponseChannelHandler(msgPackHelper);
bindAddr = new InetSocketAddress(host, port);
currentTopology.set(new Topology().addLeader(host, port, TEST_TOPIC_NAME, TEST_PARTITION_ID).addLeader(host, port, Protocol.SYSTEM_TOPIC, Protocol.SYSTEM_PARTITION));
stubTopologyRequest();
bindTransport();
}
Aggregations