use of io.pravega.client.stream.impl.StreamSegmentsWithPredecessors in project pravega by pravega.
the class ControllerImplTest method testDeadline.
@Test
public void testDeadline() {
@Cleanup final ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create((testSecure ? "tls://" : "tcp://") + "localhost:" + serverPort)).credentials(new DefaultCredentials("1111_aaaa", "admin")).trustStore(SecurityConfigDefaults.TLS_CA_CERT_PATH).build()).timeoutMillis(200).retryAttempts(1).build(), executor);
Predicate<Throwable> deadlinePredicate = e -> {
Throwable unwrapped = Exceptions.unwrap(e);
if (unwrapped instanceof RetriesExhaustedException) {
unwrapped = Exceptions.unwrap(unwrapped.getCause());
}
StatusRuntimeException exception = (StatusRuntimeException) unwrapped;
Status.Code code = exception.getStatus().getCode();
return code.equals(Status.Code.DEADLINE_EXCEEDED);
};
String deadline = "deadline";
// region scope
CompletableFuture<Boolean> scopeFuture = controller.createScope(deadline);
AssertExtensions.assertFutureThrows("", scopeFuture, deadlinePredicate);
CompletableFuture<Boolean> deleteScopeFuture = controller.deleteScope(deadline);
AssertExtensions.assertFutureThrows("", deleteScopeFuture, deadlinePredicate);
CompletableFuture<Void> listFuture = controller.listStreams(deadline).collectRemaining(x -> true);
AssertExtensions.assertFutureThrows("", listFuture, deadlinePredicate);
CompletableFuture<Void> listWithTagFuture = controller.listStreamsForTag(deadline, "tx").collectRemaining(x -> true);
AssertExtensions.assertFutureThrows("", listWithTagFuture, deadlinePredicate);
CompletableFuture<StreamConfiguration> getStreamCfgFuture = controller.getStreamConfiguration(deadline, deadline);
AssertExtensions.assertFutureThrows("", getStreamCfgFuture, deadlinePredicate);
// endregion
CompletableFuture<String> tokenFuture = controller.getOrRefreshDelegationTokenFor(deadline, deadline, AccessOperation.ANY);
AssertExtensions.assertFutureThrows("", tokenFuture, deadlinePredicate);
// region stream
CompletableFuture<Boolean> createStreamFuture = controller.createStream(deadline, deadline, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
AssertExtensions.assertFutureThrows("", createStreamFuture, deadlinePredicate);
Stream stream = Stream.of(deadline, deadline);
CompletableFuture<PravegaNodeUri> getEndpointFuture = controller.getEndpointForSegment(NameUtils.getQualifiedStreamSegmentName(deadline, deadline, 0L));
AssertExtensions.assertFutureThrows("", getEndpointFuture, deadlinePredicate);
CompletableFuture<StreamSegments> getSegmentFuture = controller.getCurrentSegments(deadline, deadline);
AssertExtensions.assertFutureThrows("", getSegmentFuture, deadlinePredicate);
CompletableFuture<Map<Segment, Long>> getSegmentsAtTimeFuture = controller.getSegmentsAtTime(stream, 0L);
AssertExtensions.assertFutureThrows("", getSegmentsAtTimeFuture, deadlinePredicate);
CompletableFuture<StreamSegments> currentSegmentsFuture = controller.getCurrentSegments(deadline, deadline);
AssertExtensions.assertFutureThrows("", currentSegmentsFuture, deadlinePredicate);
Segment segment = new Segment(deadline, deadline, 0L);
CompletableFuture<Boolean> isSegmentOpenFuture = controller.isSegmentOpen(segment);
AssertExtensions.assertFutureThrows("", isSegmentOpenFuture, deadlinePredicate);
CompletableFuture<StreamSegmentsWithPredecessors> successorFuture = controller.getSuccessors(segment);
AssertExtensions.assertFutureThrows("", successorFuture, deadlinePredicate);
StreamCut streamCut = new StreamCutImpl(stream, Collections.emptyMap());
CompletableFuture<StreamSegmentSuccessors> streamCutFuture = controller.getSegments(streamCut, streamCut);
AssertExtensions.assertFutureThrows("", streamCutFuture, deadlinePredicate);
CompletableFuture<StreamSegmentSuccessors> streamcutSuccessorsFuture = controller.getSuccessors(streamCut);
AssertExtensions.assertFutureThrows("", streamcutSuccessorsFuture, deadlinePredicate);
CompletableFuture<Boolean> updateFuture = controller.updateStream(deadline, deadline, StreamConfiguration.builder().build());
AssertExtensions.assertFutureThrows("", updateFuture, deadlinePredicate);
CompletableFuture<Boolean> scaleFuture = controller.scaleStream(stream, Collections.emptyList(), Collections.emptyMap(), executor).getFuture();
AssertExtensions.assertFutureThrows("", scaleFuture, deadlinePredicate);
CompletableFuture<Boolean> scaleStatusFuture = controller.checkScaleStatus(stream, 0);
AssertExtensions.assertFutureThrows("", scaleStatusFuture, deadlinePredicate);
CompletableFuture<Boolean> truncateFuture = controller.truncateStream(deadline, deadline, new StreamCutImpl(Stream.of(deadline, deadline), Collections.emptyMap()));
AssertExtensions.assertFutureThrows("", truncateFuture, deadlinePredicate);
CompletableFuture<Boolean> sealFuture = controller.sealStream(deadline, deadline);
AssertExtensions.assertFutureThrows("", sealFuture, deadlinePredicate);
CompletableFuture<Boolean> deleteFuture = controller.deleteStream(deadline, deadline);
AssertExtensions.assertFutureThrows("", deleteFuture, deadlinePredicate);
// endregion
// region transaction
CompletableFuture<TxnSegments> createtxnFuture = controller.createTransaction(stream, 100L);
AssertExtensions.assertFutureThrows("", createtxnFuture, deadlinePredicate);
CompletableFuture<Transaction.PingStatus> pingTxnFuture = controller.pingTransaction(stream, UUID.randomUUID(), 100L);
AssertExtensions.assertFutureThrows("", pingTxnFuture, deadlinePredicate);
CompletableFuture<Void> abortFuture = controller.abortTransaction(stream, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", abortFuture, deadlinePredicate);
CompletableFuture<Void> commitFuture = controller.commitTransaction(stream, "", 0L, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", commitFuture, deadlinePredicate);
CompletableFuture<Transaction.Status> txnStatusFuture = controller.checkTransactionStatus(stream, UUID.randomUUID());
AssertExtensions.assertFutureThrows("", txnStatusFuture, deadlinePredicate);
// endregion
// region writer mark
CompletableFuture<Void> writerPosFuture = controller.noteTimestampFromWriter("deadline", stream, 0L, mock(WriterPosition.class));
AssertExtensions.assertFutureThrows("", writerPosFuture, deadlinePredicate);
CompletableFuture<Void> removeWriterFuture = controller.removeWriter("deadline", stream);
AssertExtensions.assertFutureThrows("", removeWriterFuture, deadlinePredicate);
// endregion
// verify that a stub level deadline is not set and that the stub can still make successful calls for which we
// have mocked successful responses.
controller.createScope("scope1").join();
}
use of io.pravega.client.stream.impl.StreamSegmentsWithPredecessors in project pravega by pravega.
the class MockController method getSuccessors.
@Override
public CompletableFuture<StreamSegmentsWithPredecessors> getSuccessors(Segment segment) {
final Stream segmentStream = Stream.of(segment.getScopedStreamName());
final CompletableFuture<StreamSegmentsWithPredecessors> result = new CompletableFuture<>();
if (getStreamConfig(segmentStream) == null) {
result.completeExceptionally(new RuntimeException("Stream is deleted"));
} else {
result.complete(new StreamSegmentsWithPredecessors(Collections.emptyMap(), ""));
}
return result;
}
use of io.pravega.client.stream.impl.StreamSegmentsWithPredecessors in project pravega by pravega.
the class ControllerImpl method getSuccessors.
@Override
public CompletableFuture<StreamSegmentsWithPredecessors> getSuccessors(Segment segment) {
Exceptions.checkNotClosed(closed.get(), this);
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "getSuccessors", segment, requestId);
final CompletableFuture<SuccessorResponse> resultFuture = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<SuccessorResponse> callback = new RPCAsyncCallback<>(requestId, "getSuccessors", segment);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_SEGMENTS_IMMEDIATELY_FOLLOWING, segment.getScopedName()).getSegmentsImmediatelyFollowing(ModelHelper.decode(segment), callback);
return callback.getFuture();
}, this.executor);
return resultFuture.thenApplyAsync(successors -> {
log.debug(requestId, "Received the following data from the controller {}", successors.getSegmentsList());
Map<SegmentWithRange, List<Long>> result = new HashMap<>();
for (SuccessorResponse.SegmentEntry entry : successors.getSegmentsList()) {
result.put(encode(entry.getSegment()), entry.getValueList());
}
return new StreamSegmentsWithPredecessors(result, successors.getDelegationToken());
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getSuccessors of segment {} failed: ", segment.getSegmentId(), e);
}
LoggerHelpers.traceLeave(log, "getSuccessors", traceId, requestId);
});
}
Aggregations