Search in sources :

Example 6 with CheckedApiException

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

the class TopicBacklogReaderImplTest method computeMessageStats_failure.

@SuppressWarnings("incompatible")
@Test
public void computeMessageStats_failure() {
    when(mockClient.computeMessageStats(example(TopicPath.class), example(Partition.class), example(Offset.class), Offset.of(Integer.MAX_VALUE))).thenReturn(ApiFutures.immediateFailedFuture(new CheckedApiException(Code.UNAVAILABLE).underlying));
    ApiException e = assertThrows(ApiException.class, () -> reader.computeMessageStats(example(Offset.class)));
    assertEquals(Code.UNAVAILABLE, e.getStatusCode().getCode());
}
Also used : Partition(com.google.cloud.pubsublite.Partition) TopicPath(com.google.cloud.pubsublite.TopicPath) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) Offset(com.google.cloud.pubsublite.Offset) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Example 7 with CheckedApiException

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

the class SubscriptionPartitionProcessorImpl method handleMessages.

private void handleMessages(List<SequencedMessage> messages) {
    if (completionFuture.isDone()) {
        return;
    }
    Offset lastOffset = Offset.of(Iterables.getLast(messages).getCursor().getOffset());
    long byteSize = messages.stream().mapToLong(SequencedMessage::getSizeBytes).sum();
    if (tracker.tryClaim(OffsetByteProgress.of(lastOffset, byteSize))) {
        lastClaimedOffset = Optional.of(lastOffset);
        messages.forEach(message -> receiver.outputWithTimestamp(message, new Instant(Timestamps.toMillis(message.getPublishTime()))));
        try {
            subscriber.allowFlow(FlowControlRequest.newBuilder().setAllowedBytes(byteSize).setAllowedMessages(messages.size()).build());
        } catch (CheckedApiException e) {
            completionFuture.setException(e);
        }
    } else {
        completionFuture.set(null);
    }
}
Also used : Instant(org.joda.time.Instant) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) Offset(com.google.cloud.pubsublite.Offset)

Aggregations

CheckedApiException (com.google.cloud.pubsublite.internal.CheckedApiException)7 Test (org.junit.Test)6 ApiException (com.google.api.gax.rpc.ApiException)3 Offset (com.google.cloud.pubsublite.Offset)3 Message (com.google.cloud.pubsublite.Message)2 PipelineExecutionException (org.apache.beam.sdk.Pipeline.PipelineExecutionException)2 Instant (org.joda.time.Instant)2 SettableApiFuture (com.google.api.core.SettableApiFuture)1 Code (com.google.api.gax.rpc.StatusCode.Code)1 MessageMetadata (com.google.cloud.pubsublite.MessageMetadata)1 Partition (com.google.cloud.pubsublite.Partition)1 TopicPath (com.google.cloud.pubsublite.TopicPath)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