Search in sources :

Example 6 with SequencedMessage

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();
}
Also used : SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) Test(org.junit.Test)

Example 7 with SequencedMessage

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);
}
Also used : FlowControlRequest(com.google.cloud.pubsublite.proto.FlowControlRequest) SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) Test(org.junit.Test)

Example 8 with SequencedMessage

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());
}
Also used : SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 9 with SequencedMessage

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()));
}
Also used : FlowControlRequest(com.google.cloud.pubsublite.proto.FlowControlRequest) SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with SequencedMessage

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()));
}
Also used : SequencedMessage(com.google.cloud.pubsublite.SequencedMessage) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

SequencedMessage (com.google.cloud.pubsublite.SequencedMessage)24 Test (org.junit.Test)20 Partition (com.google.cloud.pubsublite.Partition)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Offset (com.google.cloud.pubsublite.Offset)4 PubsubMessage (com.google.pubsub.v1.PubsubMessage)4 TopicPath (com.google.cloud.pubsublite.TopicPath)3 FlowControlRequest (com.google.cloud.pubsublite.proto.FlowControlRequest)3 ArrayList (java.util.ArrayList)3 ApiFuture (com.google.api.core.ApiFuture)2 ApiFutureCallback (com.google.api.core.ApiFutureCallback)2 ApiFutures (com.google.api.core.ApiFutures)2 SettableApiFuture (com.google.api.core.SettableApiFuture)2 CheckedApiException (com.google.cloud.pubsublite.internal.CheckedApiException)2 CloseableMonitor (com.google.cloud.pubsublite.internal.CloseableMonitor)2 ExtractStatus (com.google.cloud.pubsublite.internal.ExtractStatus)2 ApiServiceUtils.blockingShutdown (com.google.cloud.pubsublite.internal.wire.ApiServiceUtils.blockingShutdown)2 KafkaExceptionUtils.toKafka (com.google.cloud.pubsublite.kafka.KafkaExceptionUtils.toKafka)2 InitialSubscribeRequest (com.google.cloud.pubsublite.proto.InitialSubscribeRequest)2 SeekRequest (com.google.cloud.pubsublite.proto.SeekRequest)2