use of io.zeebe.protocol.impl.BrokerEventMetadata in project zeebe by zeebe-io.
the class Events method isEventOfType.
protected static boolean isEventOfType(LoggedEvent event, EventType type) {
if (event == null) {
return false;
}
final BrokerEventMetadata metadata = new BrokerEventMetadata();
event.readMetadata(metadata);
return metadata.getEventType() == type;
}
use of io.zeebe.protocol.impl.BrokerEventMetadata in project zeebe by zeebe-io.
the class ClientApiMessageHandlerTest method shouldHandleCommandRequest.
@Test
public void shouldHandleCommandRequest() throws InterruptedException, ExecutionException {
// given
final int writtenLength = writeCommandRequestToBuffer(buffer, LOG_STREAM_PARTITION_ID, null, EventType.TASK_EVENT);
// when
final boolean isHandled = messageHandler.onRequest(serverOutput, DEFAULT_ADDRESS, buffer, 0, writtenLength, REQUEST_ID);
// then
assertThat(isHandled).isTrue();
final BufferedLogStreamReader logStreamReader = new BufferedLogStreamReader(logStream, true);
waitForAvailableEvent(logStreamReader);
final LoggedEvent loggedEvent = logStreamReader.next();
final byte[] valueBuffer = new byte[TASK_EVENT.length];
loggedEvent.getValueBuffer().getBytes(loggedEvent.getValueOffset(), valueBuffer, 0, loggedEvent.getValueLength());
assertThat(loggedEvent.getValueLength()).isEqualTo(TASK_EVENT.length);
assertThat(valueBuffer).isEqualTo(TASK_EVENT);
final BrokerEventMetadata eventMetadata = new BrokerEventMetadata();
loggedEvent.readMetadata(eventMetadata);
assertThat(eventMetadata.getRequestId()).isEqualTo(REQUEST_ID);
assertThat(eventMetadata.getRequestStreamId()).isEqualTo(DEFAULT_ADDRESS.getStreamId());
}
use of io.zeebe.protocol.impl.BrokerEventMetadata in project zeebe by zeebe-io.
the class ClientApiMessageHandlerTest method shouldWriteCommandRequestProtocolVersion.
@Test
public void shouldWriteCommandRequestProtocolVersion() throws InterruptedException, ExecutionException {
// given
final short clientProtocolVersion = Protocol.PROTOCOL_VERSION - 1;
final int writtenLength = writeCommandRequestToBuffer(buffer, LOG_STREAM_PARTITION_ID, clientProtocolVersion, EventType.TASK_EVENT);
// when
final boolean isHandled = messageHandler.onRequest(serverOutput, DEFAULT_ADDRESS, buffer, 0, writtenLength, 123);
// then
assertThat(isHandled).isTrue();
final BufferedLogStreamReader logStreamReader = new BufferedLogStreamReader(logStream, true);
waitForAvailableEvent(logStreamReader);
final LoggedEvent loggedEvent = logStreamReader.next();
final BrokerEventMetadata eventMetadata = new BrokerEventMetadata();
loggedEvent.readMetadata(eventMetadata);
assertThat(eventMetadata.getProtocolVersion()).isEqualTo(clientProtocolVersion);
}
use of io.zeebe.protocol.impl.BrokerEventMetadata in project zeebe by zeebe-io.
the class AddTaskSubscriptionHandler method handle.
@Override
public void handle(final ActorControl actor, final int partitionId, final DirectBuffer buffer, final BrokerEventMetadata eventMetada) {
final TaskSubscriptionRequest request = new TaskSubscriptionRequest();
request.wrap(cloneBuffer(buffer));
final long requestId = eventMetada.getRequestId();
final int requestStreamId = eventMetada.getRequestStreamId();
final TaskSubscription taskSubscription = new TaskSubscription(partitionId, request.getLockTaskType(), request.getLockDuration(), request.getLockOwner(), requestStreamId);
taskSubscription.setCredits(request.getCredits());
final ActorFuture<Void> future = manager.addSubscription(taskSubscription);
actor.runOnCompletion(future, ((aVoid, throwable) -> {
if (throwable == null) {
final long subscriberKey = taskSubscription.getSubscriberKey();
request.setSubscriberKey(subscriberKey);
sendResponse(actor, requestStreamId, requestId, request);
} else {
sendErrorResponse(actor, requestStreamId, requestId, "Cannot add task subscription. %s", throwable.getMessage());
}
}));
}
use of io.zeebe.protocol.impl.BrokerEventMetadata in project zeebe by zeebe-io.
the class ClientApiMessageHandlerTest method shouldWriteCommandRequestEventType.
@Test
public void shouldWriteCommandRequestEventType() throws InterruptedException, ExecutionException {
// given
final int writtenLength = writeCommandRequestToBuffer(buffer, LOG_STREAM_PARTITION_ID, null, EventType.TASK_EVENT);
// when
final boolean isHandled = messageHandler.onRequest(serverOutput, DEFAULT_ADDRESS, buffer, 0, writtenLength, 123);
// then
assertThat(isHandled).isTrue();
final BufferedLogStreamReader logStreamReader = new BufferedLogStreamReader(logStream, true);
waitForAvailableEvent(logStreamReader);
final LoggedEvent loggedEvent = logStreamReader.next();
final BrokerEventMetadata eventMetadata = new BrokerEventMetadata();
loggedEvent.readMetadata(eventMetadata);
assertThat(eventMetadata.getEventType()).isEqualTo(EventType.TASK_EVENT);
}
Aggregations