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());
}
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);
}
}
Aggregations