Search in sources :

Example 61 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class RemoveTopicSubscriptionHandlerTest method shouldWriteErrorOnFailure.

@Test
public void shouldWriteErrorOnFailure() {
    // given
    final RemoveTopicSubscriptionHandler handler = new RemoveTopicSubscriptionHandler(output, subscriptionService);
    final BrokerEventMetadata metadata = new BrokerEventMetadata();
    metadata.requestStreamId(14);
    final DirectBuffer request = encode(new CloseSubscriptionRequest().setSubscriberKey(5L));
    actorSchedulerRule.submitActor(new Handler((actor) -> handler.handle(actor, 0, request, metadata)));
    actorSchedulerRule.workUntilDone();
    // when
    futurePool.at(0).completeExceptionally(new RuntimeException("foo"));
    actorSchedulerRule.workUntilDone();
    // then
    assertThat(output.getSentResponses()).hasSize(1);
    final ErrorResponseDecoder errorDecoder = output.getAsErrorResponse(0);
    assertThat(errorDecoder.errorCode()).isEqualTo(ErrorCode.REQUEST_PROCESSING_FAILURE);
    assertThat(errorDecoder.errorData()).isEqualTo("Cannot close topic subscription. foo");
}
Also used : DirectBuffer(org.agrona.DirectBuffer) TopicSubscriptionService(io.zeebe.broker.event.processor.TopicSubscriptionService) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) UnpackedObject(io.zeebe.msgpack.UnpackedObject) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest) ActorControl(io.zeebe.util.sched.ActorControl) Consumer(java.util.function.Consumer) MockitoAnnotations(org.mockito.MockitoAnnotations) BufferingServerOutput(io.zeebe.broker.transport.clientapi.BufferingServerOutput) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) Actor(io.zeebe.util.sched.Actor) Rule(org.junit.Rule) Ignore(org.junit.Ignore) ControlledActorSchedulerRule(io.zeebe.util.sched.testing.ControlledActorSchedulerRule) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) ErrorResponseDecoder(io.zeebe.protocol.clientapi.ErrorResponseDecoder) DirectBuffer(org.agrona.DirectBuffer) Before(org.junit.Before) ErrorResponseDecoder(io.zeebe.protocol.clientapi.ErrorResponseDecoder) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) Test(org.junit.Test)

Example 62 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class BufferingServerOutput method getAs.

protected <T extends MessageDecoderFlyweight> T getAs(int index, T decoder) {
    final DirectBuffer sentResponse = sentResponses.get(index);
    final int offset = TransportHeaderDescriptor.HEADER_LENGTH + RequestResponseHeaderDescriptor.HEADER_LENGTH;
    headerDecoder.wrap(sentResponse, offset);
    decoder.wrap(sentResponse, offset + headerDecoder.encodedLength(), headerDecoder.blockLength(), headerDecoder.version());
    return decoder;
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Example 63 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class POJODeserializationBenchmark method deserialize.

@Benchmark
@Threads(1)
public void deserialize(POJODeserializationContext ctx) throws Exception {
    final MsgPackSerializer serializer = ctx.getSerializer();
    final DirectBuffer encodedMsgPack = ctx.getMsgpackBuffer();
    serializer.deserialize(ctx.getTargetClass(), encodedMsgPack, 0, encodedMsgPack.capacity());
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Threads(org.openjdk.jmh.annotations.Threads) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 64 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class PayloadCache method lookupPayload.

private DirectBuffer lookupPayload(long position) {
    DirectBuffer payload = null;
    final boolean found = logStreamReader.seek(position);
    if (found && logStreamReader.hasNext()) {
        final LoggedEvent event = logStreamReader.next();
        workflowInstanceEvent.reset();
        event.readValue(workflowInstanceEvent);
        payload = workflowInstanceEvent.getPayload();
    }
    return payload;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent)

Example 65 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class WorkflowCreateProcessor method processEvent.

@Override
public void processEvent(TypedEvent<WorkflowEvent> event) {
    partitionIds.clear();
    final WorkflowEvent workflowEvent = event.getValue();
    final PendingDeployment pendingDeployment = pendingDeployments.get(workflowEvent.getDeploymentKey());
    ensureNotNull("pending deployment", pendingDeployment);
    final DirectBuffer topicName = pendingDeployment.getTopicName();
    final TopicPartitionIterator iterator = topicPartitions.iterator();
    while (iterator.hasNext()) {
        final TopicPartition topicPartition = iterator.next();
        if (BufferUtil.equals(topicName, topicPartition.getTopicName())) {
            partitionIds.add(topicPartition.getPartitionId());
        }
    }
    ensureGreaterThan("partition ids", partitionIds.size(), 0);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) PendingDeployment(io.zeebe.broker.system.deployment.data.PendingDeployments.PendingDeployment) TopicPartitionIterator(io.zeebe.broker.system.deployment.data.TopicPartitions.TopicPartitionIterator) TopicPartition(io.zeebe.broker.system.deployment.data.TopicPartitions.TopicPartition) WorkflowEvent(io.zeebe.broker.workflow.data.WorkflowEvent)

Aggregations

DirectBuffer (org.agrona.DirectBuffer)116 Header (io.aeron.logbuffer.Header)21 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)21 MutableDirectBuffer (org.agrona.MutableDirectBuffer)20 File (java.io.File)19 MediaDriver (io.aeron.driver.MediaDriver)18 CountersReader (org.agrona.concurrent.status.CountersReader)15 ThreadingMode (io.aeron.driver.ThreadingMode)12 FragmentHandler (io.aeron.logbuffer.FragmentHandler)12 MappedByteBuffer (java.nio.MappedByteBuffer)12 ClusteredService (io.aeron.cluster.service.ClusteredService)10 InterruptAfter (io.aeron.test.InterruptAfter)10 Test (org.junit.jupiter.api.Test)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Publication (io.aeron.Publication)9 ClientSession (io.aeron.cluster.service.ClientSession)9 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)8 Assertions (org.junit.jupiter.api.Assertions)8 Mockito.mock (org.mockito.Mockito.mock)8