use of io.zeebe.protocol.impl.BrokerEventMetadata 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");
}
use of io.zeebe.protocol.impl.BrokerEventMetadata 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());
}
}));
}
Aggregations