use of com.google.cloud.pubsublite.proto.SubscribeRequest in project java-pubsublite by googleapis.
the class SubscriberImplTest method reinitialize_handlesIgnoredReset.
@Test
public void reinitialize_handlesIgnoredReset() throws Exception {
subscriber.allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build());
ImmutableList<SequencedMessage> messages = ImmutableList.of(SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(0), 10), SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(1), 10));
CountDownLatch messagesReceived = countdownMessageBatches(1);
leakedResponseObserver.onResponse(messages);
assertThat(messagesReceived.await(10, SECONDS)).isTrue();
verify(mockMessageConsumer).accept(messages);
final SubscribeRequest nextOffsetRequest = SubscribeRequest.newBuilder().setInitial(BASE_INITIAL_SUBSCRIBE_REQUEST.toBuilder().setInitialLocation(SeekRequest.newBuilder().setCursor(Cursor.newBuilder().setOffset(2)))).build();
doAnswer(args -> {
leakedResponseObserver = args.getArgument(1);
return mockConnectedSubscriber2;
}).when(mockSubscriberFactory).New(any(), any(), eq(nextOffsetRequest));
// If the RESET signal is received and subscriber reset is ignored, the subscriber should read
// from the next offset upon reconnect.
when(mockResetHandler.handleReset()).thenReturn(false);
subscriber.triggerReinitialize(TestResetSignal.newCheckedException());
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(initialRequest()));
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(nextOffsetRequest));
verify(mockConnectedSubscriber2).allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(80).setAllowedMessages(98).build());
}
use of com.google.cloud.pubsublite.proto.SubscribeRequest in project java-pubsublite by googleapis.
the class SubscriberImplTest method reinitialize_reconnectsToNextOffset.
@Test
public void reinitialize_reconnectsToNextOffset() throws Exception {
subscriber.allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build());
ImmutableList<SequencedMessage> messages = ImmutableList.of(SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(0), 10), SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(1), 10));
CountDownLatch messagesReceived = countdownMessageBatches(1);
leakedResponseObserver.onResponse(messages);
assertThat(messagesReceived.await(10, SECONDS)).isTrue();
verify(mockMessageConsumer).accept(messages);
final SubscribeRequest nextOffsetRequest = SubscribeRequest.newBuilder().setInitial(BASE_INITIAL_SUBSCRIBE_REQUEST.toBuilder().setInitialLocation(SeekRequest.newBuilder().setCursor(Cursor.newBuilder().setOffset(2)))).build();
doAnswer(args -> {
leakedResponseObserver = args.getArgument(1);
return mockConnectedSubscriber2;
}).when(mockSubscriberFactory).New(any(), any(), eq(nextOffsetRequest));
subscriber.triggerReinitialize(new CheckedApiException(Code.ABORTED));
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(initialRequest()));
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(nextOffsetRequest));
verify(mockConnectedSubscriber2).allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(80).setAllowedMessages(98).build());
}
use of com.google.cloud.pubsublite.proto.SubscribeRequest in project java-pubsublite by googleapis.
the class SubscriberServiceClientTest method subscribeTest.
@Test
public void subscribeTest() throws Exception {
SubscribeResponse expectedResponse = SubscribeResponse.newBuilder().build();
mockSubscriberService.addResponse(expectedResponse);
SubscribeRequest request = SubscribeRequest.newBuilder().build();
MockStreamObserver<SubscribeResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<SubscribeRequest, SubscribeResponse> callable = client.subscribeCallable();
ApiStreamObserver<SubscribeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<SubscribeResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
use of com.google.cloud.pubsublite.proto.SubscribeRequest in project java-pubsublite by googleapis.
the class SubscriberServiceClientTest method subscribeExceptionTest.
@Test
public void subscribeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSubscriberService.addException(exception);
SubscribeRequest request = SubscribeRequest.newBuilder().build();
MockStreamObserver<SubscribeResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<SubscribeRequest, SubscribeResponse> callable = client.subscribeCallable();
ApiStreamObserver<SubscribeRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
try {
List<SubscribeResponse> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
Aggregations