Search in sources :

Example 1 with CloseSubscriptionRequest

use of io.zeebe.broker.event.processor.CloseSubscriptionRequest 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 2 with CloseSubscriptionRequest

use of io.zeebe.broker.event.processor.CloseSubscriptionRequest in project zeebe by zeebe-io.

the class RemoveTopicSubscriptionHandler method handle.

@Override
public void handle(final ActorControl actor, final int partitionId, final DirectBuffer buffer, final BrokerEventMetadata metadata) {
    final int requestStreamId = metadata.getRequestStreamId();
    final long requestId = metadata.getRequestId();
    final CloseSubscriptionRequest request = new CloseSubscriptionRequest();
    request.wrap(cloneBuffer(buffer));
    final ActorFuture<Void> future = subscriptionService.closeSubscriptionAsync(partitionId, request.getSubscriberKey());
    actor.runOnCompletion(future, ((aVoid, throwable) -> {
        if (throwable == null) {
            sendResponse(actor, requestStreamId, requestId, request);
        } else {
            sendErrorResponse(actor, requestStreamId, requestId, "Cannot close topic subscription. %s", throwable.getMessage());
        }
    }));
}
Also used : AbstractControlMessageHandler(io.zeebe.broker.transport.controlmessage.AbstractControlMessageHandler) ActorControl(io.zeebe.util.sched.ActorControl) ActorFuture(io.zeebe.util.sched.future.ActorFuture) BrokerEventMetadata(io.zeebe.protocol.impl.BrokerEventMetadata) TopicSubscriptionService(io.zeebe.broker.event.processor.TopicSubscriptionService) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) ServerOutput(io.zeebe.transport.ServerOutput) BufferUtil.cloneBuffer(io.zeebe.util.buffer.BufferUtil.cloneBuffer) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest) DirectBuffer(org.agrona.DirectBuffer) CloseSubscriptionRequest(io.zeebe.broker.event.processor.CloseSubscriptionRequest)

Aggregations

CloseSubscriptionRequest (io.zeebe.broker.event.processor.CloseSubscriptionRequest)2 TopicSubscriptionService (io.zeebe.broker.event.processor.TopicSubscriptionService)2 BrokerEventMetadata (io.zeebe.protocol.impl.BrokerEventMetadata)2 ActorControl (io.zeebe.util.sched.ActorControl)2 DirectBuffer (org.agrona.DirectBuffer)2 BufferingServerOutput (io.zeebe.broker.transport.clientapi.BufferingServerOutput)1 AbstractControlMessageHandler (io.zeebe.broker.transport.controlmessage.AbstractControlMessageHandler)1 UnpackedObject (io.zeebe.msgpack.UnpackedObject)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)1 ErrorResponseDecoder (io.zeebe.protocol.clientapi.ErrorResponseDecoder)1 ServerOutput (io.zeebe.transport.ServerOutput)1 BufferUtil.cloneBuffer (io.zeebe.util.buffer.BufferUtil.cloneBuffer)1 Actor (io.zeebe.util.sched.Actor)1 ActorFuture (io.zeebe.util.sched.future.ActorFuture)1 ControlledActorSchedulerRule (io.zeebe.util.sched.testing.ControlledActorSchedulerRule)1 Consumer (java.util.function.Consumer)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1