Search in sources :

Example 1 with BrokerEventMetadata

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;
}
Also used : BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata)

Example 2 with BrokerEventMetadata

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());
}
Also used : BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata)

Example 3 with BrokerEventMetadata

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);
}
Also used : BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata)

Example 4 with BrokerEventMetadata

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());
        }
    }));
}
Also used : TaskSubscriptionRequest(io.zeebe.broker.task.processor.TaskSubscriptionRequest) ActorControl(io.zeebe.util.sched.ActorControl) ActorFuture(io.zeebe.util.sched.future.ActorFuture) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) TaskSubscriptionManager(io.zeebe.broker.task.TaskSubscriptionManager) ServerOutput(io.zeebe.transport.ServerOutput) TaskSubscriptionRequest(io.zeebe.broker.task.processor.TaskSubscriptionRequest) BufferUtil.cloneBuffer(io.zeebe.util.buffer.BufferUtil.cloneBuffer) DirectBuffer(org.agrona.DirectBuffer) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription)

Example 5 with BrokerEventMetadata

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);
}
Also used : BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata)

Aggregations

BrokerEventMetadata (io.zeebe.protocol.impl.BrokerEventMetadata)7 ActorControl (io.zeebe.util.sched.ActorControl)3 DirectBuffer (org.agrona.DirectBuffer)3 CloseSubscriptionRequest (io.zeebe.broker.event.processor.CloseSubscriptionRequest)2 TopicSubscriptionService (io.zeebe.broker.event.processor.TopicSubscriptionService)2 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)2 ServerOutput (io.zeebe.transport.ServerOutput)2 BufferUtil.cloneBuffer (io.zeebe.util.buffer.BufferUtil.cloneBuffer)2 ActorFuture (io.zeebe.util.sched.future.ActorFuture)2 TaskSubscriptionManager (io.zeebe.broker.task.TaskSubscriptionManager)1 TaskSubscription (io.zeebe.broker.task.processor.TaskSubscription)1 TaskSubscriptionRequest (io.zeebe.broker.task.processor.TaskSubscriptionRequest)1 BufferingServerOutput (io.zeebe.broker.transport.clientapi.BufferingServerOutput)1 AbstractControlMessageHandler (io.zeebe.broker.transport.controlmessage.AbstractControlMessageHandler)1 UnpackedObject (io.zeebe.msgpack.UnpackedObject)1 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)1 ErrorResponseDecoder (io.zeebe.protocol.clientapi.ErrorResponseDecoder)1 Actor (io.zeebe.util.sched.Actor)1 ControlledActorSchedulerRule (io.zeebe.util.sched.testing.ControlledActorSchedulerRule)1 Consumer (java.util.function.Consumer)1