private CompletableFuture<?> abortInternal() { CompletableFuture<List<Void>> futures = allAsList(connectorIdToMetadata.values().stream() .map(connection -> runAsync(() -> safeAbort(connection), finishingExecutor)) .collect(toList())); return unmodifiableFuture(futures); }
@Override public CompletableFuture<Collection<Slice>> finish() { List<CompletableFuture<? extends List<Slice>>> futureSlices = pageWriter.getPageBuffers().stream().map(pageBuffer -> { pageBuffer.flush(); CompletableFuture<List<ShardInfo>> futureShards = pageBuffer.getStoragePageSink().commit(); return futureShards.thenApply(shards -> shards.stream() .map(shard -> Slices.wrappedBuffer(SHARD_INFO_CODEC.toJsonBytes(shard))) .collect(toList())); }).collect(toList()); return allAsList(futureSlices).thenApply(lists -> lists.stream() .flatMap(Collection::stream) .collect(toList())); }
@Override public CompletableFuture<Collection<Slice>> finish() { List<CompletableFuture<? extends List<Slice>>> futureSlices = pageWriter.getPageBuffers().stream().map(pageBuffer -> { pageBuffer.flush(); CompletableFuture<List<ShardInfo>> futureShards = pageBuffer.getStoragePageSink().commit(); return futureShards.thenApply(shards -> shards.stream() .map(shard -> Slices.wrappedBuffer(SHARD_INFO_CODEC.toJsonBytes(shard))) .collect(toList())); }).collect(toList()); return allAsList(futureSlices).thenApply(lists -> lists.stream() .flatMap(Collection::stream) .collect(toList())); }
@Override public CompletableFuture<List<ShardInfo>> commit() { checkState(!committed, "already committed"); committed = true; flush(); return allAsList(futures).thenApplyAsync(ignored -> { for (ShardInfo shard : shards) { writeShard(shard.getShardUuid()); } return ImmutableList.copyOf(shards); }, commitExecutor); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testUnmodifiableAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(new CompletableFuture<String>())); future.complete(null); }
@Override public CompletableFuture<List<ShardInfo>> commit() { checkState(!committed, "already committed"); committed = true; flush(); return allAsList(futures).thenApplyAsync(ignored -> { for (ShardInfo shard : shards) { writeShard(shard.getShardUuid()); } return ImmutableList.copyOf(shards); }, commitExecutor); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testUnmodifiableAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(new CompletableFuture<String>())); future.complete(null); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testUnmodifiableAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(new CompletableFuture<String>())); future.complete(null); }
@Test public void testEmptyAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of()); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of()); }
@Test public void testEmptyAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of()); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of()); }
@Test public void testEmptyAllAsList() throws Exception { CompletableFuture<List<Object>> future = allAsList(ImmutableList.of()); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of()); }
@Test public void testSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.complete("a"); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of("a")); }
@Test public void testExceptionalSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }
@Test public void testExceptionalSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }
@Test public void testExceptionalSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }
@Test public void testSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.complete("a"); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of("a")); }
@Test public void testExceptionalMultipleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<String> element2 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1, element2)); assertFalse(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }
@Test public void testSingleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); element1.complete("a"); assertTrue(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); assertEquals(future.join(), ImmutableList.of("a")); }
@Test public void testExceptionalMultipleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<String> element2 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1, element2)); assertFalse(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }
@Test public void testExceptionalMultipleElementAllAsList() throws Exception { CompletableFuture<String> element1 = new CompletableFuture<>(); CompletableFuture<String> element2 = new CompletableFuture<>(); CompletableFuture<List<Object>> future = allAsList(ImmutableList.of(element1, element2)); assertFalse(future.isDone()); assertFalse(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); element1.completeExceptionally(new RuntimeException()); assertTrue(future.isDone()); assertTrue(future.isCompletedExceptionally()); assertFalse(future.isCancelled()); }