Search in sources :

Example 1 with Actor

use of io.zeebe.util.sched.Actor 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)

Aggregations

CloseSubscriptionRequest (io.zeebe.broker.event.processor.CloseSubscriptionRequest)1 TopicSubscriptionService (io.zeebe.broker.event.processor.TopicSubscriptionService)1 BufferingServerOutput (io.zeebe.broker.transport.clientapi.BufferingServerOutput)1 UnpackedObject (io.zeebe.msgpack.UnpackedObject)1 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)1 ErrorResponseDecoder (io.zeebe.protocol.clientapi.ErrorResponseDecoder)1 BrokerEventMetadata (io.zeebe.protocol.impl.BrokerEventMetadata)1 Actor (io.zeebe.util.sched.Actor)1 ActorControl (io.zeebe.util.sched.ActorControl)1 ControlledActorSchedulerRule (io.zeebe.util.sched.testing.ControlledActorSchedulerRule)1 Consumer (java.util.function.Consumer)1 DirectBuffer (org.agrona.DirectBuffer)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ArgumentMatchers.anyInt (org.mockito.ArgumentMatchers.anyInt)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1