Search in sources :

Example 1 with Subscriber

use of com.google.cloud.pubsublite.internal.wire.Subscriber in project beam by apache.

the class SubscriptionPartitionProcessorImplTest method subscriberFailureFails.

@Test
public void subscriberFailureFails() throws Exception {
    when(tracker.currentRestriction()).thenReturn(initialRange());
    doAnswer((Answer<Void>) args -> {
        subscriber.fail(new CheckedApiException(Code.OUT_OF_RANGE));
        return null;
    }).when(subscriber).awaitRunning();
    ApiException e = assertThrows(// Longer wait is needed due to listener asynchrony, but should never wait this long.
    ApiException.class, () -> processor.runFor(Duration.standardMinutes(2)));
    assertEquals(Code.OUT_OF_RANGE, e.getStatusCode().getCode());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) FlowControlRequest(com.google.cloud.pubsublite.proto.FlowControlRequest) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) ProcessContinuation(org.apache.beam.sdk.transforms.DoFn.ProcessContinuation) Function(java.util.function.Function) Mockito.doThrow(org.mockito.Mockito.doThrow) Answer(org.mockito.stubbing.Answer) SequencedMessage(com.google.cloud.pubsublite.proto.SequencedMessage) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Spy(org.mockito.Spy) Timeout(org.junit.rules.Timeout) OutputReceiver(org.apache.beam.sdk.transforms.DoFn.OutputReceiver) RestrictionTracker(org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker) Before(org.junit.Before) InOrder(org.mockito.InOrder) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) UnitTestExamples.example(com.google.cloud.pubsublite.internal.testing.UnitTestExamples.example) Assert.assertNotNull(org.junit.Assert.assertNotNull) Offset(com.google.cloud.pubsublite.Offset) DEFAULT_FLOW_CONTROL(org.apache.beam.sdk.io.gcp.pubsublite.SubscriberOptions.DEFAULT_FLOW_CONTROL) Mockito.times(org.mockito.Mockito.times) Timestamps(com.google.protobuf.util.Timestamps) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Subscriber(com.google.cloud.pubsublite.internal.wire.Subscriber) ApiException(com.google.api.gax.rpc.ApiException) Mockito.verify(org.mockito.Mockito.verify) SettableApiFuture(com.google.api.core.SettableApiFuture) Consumer(java.util.function.Consumer) List(java.util.List) FakeApiService(com.google.cloud.pubsublite.internal.testing.FakeApiService) Rule(org.junit.Rule) Code(com.google.api.gax.rpc.StatusCode.Code) Assert.assertFalse(org.junit.Assert.assertFalse) Mockito.inOrder(org.mockito.Mockito.inOrder) Instant(org.joda.time.Instant) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Cursor(com.google.cloud.pubsublite.proto.Cursor) OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) SystemExecutors(com.google.cloud.pubsublite.internal.wire.SystemExecutors) Assert.assertEquals(org.junit.Assert.assertEquals) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Aggregations

SettableApiFuture (com.google.api.core.SettableApiFuture)1 ApiException (com.google.api.gax.rpc.ApiException)1 Code (com.google.api.gax.rpc.StatusCode.Code)1 Offset (com.google.cloud.pubsublite.Offset)1 CheckedApiException (com.google.cloud.pubsublite.internal.CheckedApiException)1 FakeApiService (com.google.cloud.pubsublite.internal.testing.FakeApiService)1 UnitTestExamples.example (com.google.cloud.pubsublite.internal.testing.UnitTestExamples.example)1 Subscriber (com.google.cloud.pubsublite.internal.wire.Subscriber)1 SystemExecutors (com.google.cloud.pubsublite.internal.wire.SystemExecutors)1 Cursor (com.google.cloud.pubsublite.proto.Cursor)1 FlowControlRequest (com.google.cloud.pubsublite.proto.FlowControlRequest)1 SequencedMessage (com.google.cloud.pubsublite.proto.SequencedMessage)1 Timestamps (com.google.protobuf.util.Timestamps)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 DEFAULT_FLOW_CONTROL (org.apache.beam.sdk.io.gcp.pubsublite.SubscriberOptions.DEFAULT_FLOW_CONTROL)1 OffsetRange (org.apache.beam.sdk.io.range.OffsetRange)1 OutputReceiver (org.apache.beam.sdk.transforms.DoFn.OutputReceiver)1 ProcessContinuation (org.apache.beam.sdk.transforms.DoFn.ProcessContinuation)1