/** * Waits for the provided future to be complete, and returns true if it was successful, false otherwise. * * @param f The future to wait for. * @param <T> The Type of the future's result. * @return True if the provided CompletableFuture is complete and successful. */ public static <T> boolean await(CompletableFuture<T> f) { return await(f, Long.MAX_VALUE); }
@Override public CompletableFuture<ReadResult> read(String streamSegmentName, long offset, int maxLength, Duration timeout) { CompletableFuture<ReadResult> result = impl.read(streamSegmentName, offset, maxLength, timeout); Futures.await(result); return result; }
@Override public void close() { if (!this.closed.get()) { Futures.await(Services.stopAsync(this, this.executor)); log.info("{}: Closed.", this.traceObjectId); this.closed.set(true); } }
@Override public CompletableFuture<Long> sealStreamSegment(String streamSegmentName, Duration timeout) { CompletableFuture<Long> result = impl.sealStreamSegment(streamSegmentName, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<Void> append(String streamSegmentName, byte[] data, Collection<AttributeUpdate> attributeUpdates, Duration timeout) { CompletableFuture<Void> result = impl.append(streamSegmentName, data, attributeUpdates, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<Void> append(String streamSegmentName, long offset, byte[] data, Collection<AttributeUpdate> attributeUpdates, Duration timeout) { CompletableFuture<Void> result = impl.append(streamSegmentName, offset, data, attributeUpdates, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<Void> updateAttributes(String streamSegmentName, Collection<AttributeUpdate> attributeUpdates, Duration timeout) { CompletableFuture<Void> result = impl.updateAttributes(streamSegmentName, attributeUpdates, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<SegmentProperties> mergeStreamSegment(String targetStreamSegment, String sourceStreamSegment, Duration timeout) { CompletableFuture<SegmentProperties> result = impl.mergeStreamSegment(targetStreamSegment, sourceStreamSegment, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<Void> deleteStreamSegment(String streamSegmentName, Duration timeout) { CompletableFuture<Void> result = impl.deleteStreamSegment(streamSegmentName, timeout); Futures.await(result); return result; }
@Override public CompletableFuture<Void> truncateStreamSegment(String streamSegmentName, long offset, Duration timeout) { CompletableFuture<Void> result = impl.truncateStreamSegment(streamSegmentName, offset, timeout); Futures.await(result); return result; } }
@Override public CompletableFuture<Void> createStreamSegment(String streamSegmentName, Collection<AttributeUpdate> attributes, Duration timeout) { CompletableFuture<Void> result = impl.createStreamSegment(streamSegmentName, attributes, timeout); Futures.await(result); return result; }
@Override public void close() { if (this.closed.compareAndSet(false, true)) { Futures.await(Services.stopAsync(this, this.executor)); this.storage.close(); log.info("Closed."); } }
@Override public void close() { if (!this.closed.get()) { Futures.await(Services.stopAsync(this, this.executor)); this.operationProcessor.close(); this.durableDataLog.close(); // Call this again just in case we were not able to do it in doStop(). log.info("{}: Closed.", this.traceObjectId); this.closed.set(true); } }
private boolean append(String streamSegmentName, int number, StreamSegmentStore store) { return Futures.await(store.append(streamSegmentName, new byte[]{(byte) number}, null, PravegaRequestProcessor.TIMEOUT)); }
private void checkScaleStatus(CompletableFuture<Boolean> scaleStatus) { Futures.exceptionListener(scaleStatus, t -> log.error("Scale Operation completed with an error", t)); if (Futures.await(scaleStatus, SCALE_WAIT_SECONDS)) { log.info("Scale operation has completed: {}", scaleStatus.join()); if (!scaleStatus.join()) { log.error("Scale operation did not complete", scaleStatus.join()); Assert.fail("Scale operation did not complete successfully"); } } else { Assert.fail("Scale operation threw an exception"); } }
@Override public void close() { if (!this.closed.getAndSet(true)) { Futures.await(Services.stopAsync(this, executorService())); ReusableLatch signal = this.closeReleaseSignal; if (signal != null) { // Wait until we are told to complete. signal.awaitUninterruptibly(); } } }
private void runBackgroundStreamProcessing(String streamName, SerializedRequestHandler<TestEvent> requestHandler, AtomicBoolean stop) { CompletableFuture.runAsync(() -> { while (!stop.get()) { TestEvent event = new TestEvent("scope", streamName, 0); event.complete(); Futures.await(requestHandler.process(event)); } }); }
@Test public void testGetSegmentsBetween() throws ExecutionException, InterruptedException { List<Segment> list = new ArrayList<>(); when(this.mockControllerService.getSegmentsBetweenStreamCuts(any())).thenReturn( CompletableFuture.completedFuture(list)); Assert.assertTrue(Futures.await(this.testController.getSegments(new StreamCutImpl(new StreamImpl("scope", "stream"), Collections.emptyMap()), new StreamCutImpl(new StreamImpl("scope", "stream"), Collections.emptyMap())))); } }
@Test public void testTermination() { CancellableRequest<Boolean> request = new CancellableRequest<>(); request.start(() -> CompletableFuture.completedFuture(null), any -> true, executorService()); assertTrue(Futures.await(request.getFuture())); }
private static void updateConfigOfNonExistantStream(Controller controller) { assertFalse(Futures.await(controller.updateStream("scope", "streamName", StreamConfiguration.builder() .scalingPolicy(ScalingPolicy.byEventRate(200, 2, 3)) .build()))); }