use of com.google.cloud.pubsublite.SequencedMessage in project java-pubsublite by googleapis.
the class BufferingPullSubscriberTest method pullEmptiesForNext.
@Test
public void pullEmptiesForNext() throws CheckedApiException {
SequencedMessage message1 = SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(10), 10);
SequencedMessage message2 = SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(11), 10);
messageConsumer.accept(ImmutableList.of(message1, message2));
assertThat(subscriber.pull()).containsExactly(message1, message2);
assertThat(subscriber.pull()).isEmpty();
}
use of com.google.cloud.pubsublite.SequencedMessage in project java-pubsublite by googleapis.
the class BufferingPullSubscriberTest method multipleBatchesAggregatedReturnsTokens.
@Test
public void multipleBatchesAggregatedReturnsTokens() throws CheckedApiException {
SequencedMessage message1 = SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(10), 10);
SequencedMessage message2 = SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(11), 20);
SequencedMessage message3 = SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(12), 30);
assertThat(subscriber.nextOffset()).isEmpty();
messageConsumer.accept(ImmutableList.of(message1, message2));
messageConsumer.accept(ImmutableList.of(message3));
assertThat(subscriber.pull()).containsExactly(message1, message2, message3);
assertThat(subscriber.nextOffset()).hasValue(Offset.of(13));
assertThat(subscriber.pull()).isEmpty();
FlowControlRequest flowControlRequest = FlowControlRequest.newBuilder().setAllowedMessages(3).setAllowedBytes(60).build();
verify(underlying).allowFlow(flowControlRequest);
}
use of com.google.cloud.pubsublite.SequencedMessage in project java-pubsublite by googleapis.
the class SubscriberImplTest method reinitialize_handlesSuccessfulReset.
@Test
public void reinitialize_handlesSuccessfulReset() 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);
doAnswer(args -> {
leakedResponseObserver = args.getArgument(1);
return mockConnectedSubscriber2;
}).when(mockSubscriberFactory).New(any(), any(), eq(initialRequest()));
// If the RESET signal is received and subscriber reset is handled, the subscriber should read
// from the committed cursor upon reconnect.
when(mockResetHandler.handleReset()).thenReturn(true);
subscriber.triggerReinitialize(TestResetSignal.newCheckedException());
verify(mockSubscriberFactory, times(2)).New(any(), any(), eq(initialRequest()));
verify(mockConnectedSubscriber2).allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(80).setAllowedMessages(98).build());
}
use of com.google.cloud.pubsublite.SequencedMessage in project java-pubsublite by googleapis.
the class SubscriberImplTest method messageResponseSubtracts.
@Test
public void messageResponseSubtracts() throws Exception {
Future<Void> failed = whenFailed(subscriber);
FlowControlRequest request = FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build();
subscriber.allowFlow(request);
verify(mockConnectedSubscriber1).allowFlow(request);
ImmutableList<SequencedMessage> messages1 = ImmutableList.of(SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(1), 98), SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(2), 1));
ImmutableList<SequencedMessage> messages2 = ImmutableList.of(SequencedMessage.of(Message.builder().build(), Timestamps.EPOCH, Offset.of(3), 2));
CountDownLatch messagesReceived = countdownMessageBatches(1);
leakedResponseObserver.onResponse(messages1);
assertThat(messagesReceived.await(10, SECONDS)).isTrue();
verify(mockMessageConsumer).accept(messages1);
assertThat(subscriber.isRunning()).isTrue();
leakedResponseObserver.onResponse(messages2);
failed.get();
assertThrowableMatches(subscriber.failureCause(), Code.FAILED_PRECONDITION);
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(initialRequest()));
}
use of com.google.cloud.pubsublite.SequencedMessage in project java-pubsublite by googleapis.
the class SubscriberImplTest method messagesOrdered_Ok.
@Test
public void messagesOrdered_Ok() throws Exception {
subscriber.allowFlow(bigFlowControlRequest());
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);
assertThat(subscriber.isRunning()).isTrue();
verify(mockSubscriberFactory, times(1)).New(any(), any(), eq(initialRequest()));
}
Aggregations