private PartETag awaitPendingPartUploadToComplete(CompletableFuture<PartETag> upload) throws IOException { final PartETag completedUploadEtag; try { completedUploadEtag = upload.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException("Interrupted while waiting for part uploads to complete"); } catch (ExecutionException e) { throw new IOException("Uploading parts failed", e.getCause()); } return completedUploadEtag; }
@PostConstruct void init() throws ExecutionException, InterruptedException { VertxOptions options = new VertxOptions() .setClusterManager(new HazelcastClusterManager(hazelcastInstance)); CompletableFuture<Vertx> future = new CompletableFuture<>(); Vertx.clusteredVertx(options, ar -> { if (ar.succeeded()) { future.complete(ar.result()); } else { future.completeExceptionally(ar.cause()); } }); vertx = future.get(); }
@Test public void publisherToCompletableFuture() throws Exception { Publisher<Integer> source = Flowable.fromArray(1, 2, 3); Object target = getAdapter(CompletableFuture.class).fromPublisher(source); assertTrue(target instanceof CompletableFuture); assertEquals(Integer.valueOf(1), ((CompletableFuture<Integer>) target).get()); }
@Test public void getEntityFromCompletable() throws Exception { ListenableFuture<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/{method}", String.class, "get"); ResponseEntity<String> entity = future.completable().get(); assertEquals("Invalid content", helloWorld, entity.getBody()); assertFalse("No headers", entity.getHeaders().isEmpty()); assertEquals("Invalid content-type", textContentType, entity.getHeaders().getContentType()); assertEquals("Invalid status code", HttpStatus.OK, entity.getStatusCode()); }
@Test public void listProcedure() throws Exception { String procList = admin.getProcedures().get(); assertTrue(procList.startsWith("[")); }
@Test public void testNoTable() throws InterruptedException { for (RegionLocateType locateType : RegionLocateType.values()) { try { getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
@Test public void testStopJobAfterSavepoint() throws Exception { setUpWithCheckpointInterval(10L); final String savepointLocation = cancelWithSavepoint(); final JobStatus jobStatus = clusterClient.getJobStatus(jobGraph.getJobID()).get(); assertThat(jobStatus, isOneOf(JobStatus.CANCELED, JobStatus.CANCELLING)); final List<Path> savepoints; try (Stream<Path> savepointFiles = Files.list(savepointDirectory)) { savepoints = savepointFiles.map(Path::getFileName).collect(Collectors.toList()); } assertThat(savepoints, hasItem(Paths.get(savepointLocation).getFileName())); }
/** * Tests disposal with a JAR file. */ @Test public void testDisposeWithJar() throws Exception { replaceStdOutAndStdErr(); final CompletableFuture<String> disposeSavepointFuture = new CompletableFuture<>(); final DisposeSavepointClusterClient clusterClient = new DisposeSavepointClusterClient( (String savepointPath) -> { disposeSavepointFuture.complete(savepointPath); return CompletableFuture.completedFuture(Acknowledge.get()); }, getConfiguration()); try { CliFrontend frontend = new MockedCliFrontend(clusterClient); // Fake JAR file File f = tmp.newFile(); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f)); out.close(); final String disposePath = "any-path"; String[] parameters = { "-d", disposePath, "-j", f.getAbsolutePath() }; frontend.savepoint(parameters); final String actualSavepointPath = disposeSavepointFuture.get(); assertEquals(disposePath, actualSavepointPath); } finally { clusterClient.shutdown(); restoreStdOutAndStdErr(); } }
@Override public void close() throws Exception { shutdownServer().get(); if (requestStats instanceof AtomicKvStateRequestStats) { AtomicKvStateRequestStats stats = (AtomicKvStateRequestStats) requestStats; Assert.assertEquals(0L, stats.getNumConnections()); } Assert.assertTrue(getQueryExecutor().isTerminated()); Assert.assertTrue(isEventGroupShutdown()); } }
@Test public void testRaceConditionWithWebsocketClientWorker() throws Exception { CompletableFuture<Context> fut = new CompletableFuture<>(); vertx.deployVerticle(new AbstractVerticle() { @Override public void start() throws Exception { fut.complete(context); } }, new DeploymentOptions().setWorker(true), ar -> { if (ar.failed()) { fut.completeExceptionally(ar.cause()); } }); testRaceConditionWithWebsocketClient(fut.get()); }
@Test public void testServerFailover() throws Exception { FakeDNSServer server = new FakeDNSServer().store(FakeDNSServer.A_store(Collections.singletonMap("vertx.io", "127.0.0.1"))).port(FakeDNSServer.PORT + 2); try { AddressResolverOptions options = new AddressResolverOptions(); options.setOptResourceEnabled(false); options.setMaxQueries(4); // 2 + 2 server.start(); InetSocketAddress dnsServerAddress = server.localAddress(); // First server is unreachable options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + (FakeDNSServer.PORT + 1)); // Second server is the failed over server options.addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()); AddressResolver resolver = new AddressResolver((VertxImpl) vertx, options); CompletableFuture<InetAddress> result = new CompletableFuture<>(); resolver.resolveHostname("vertx.io", ar -> { if (ar.succeeded()) { result.complete(ar.result()); } else { result.completeExceptionally(ar.cause()); } }); String resolved = result.get(10, TimeUnit.SECONDS).getHostAddress(); assertEquals("127.0.0.1", resolved); } finally { server.stop(); } } }
@Override public void close() throws Exception { // Free cluster resources clusterClient.cancel(jobId); // cancel() is non-blocking so do this to make sure the job finished CompletableFuture<JobStatus> jobStatusFuture = FutureUtils.retrySuccessfulWithDelay( () -> clusterClient.getJobStatus(jobId), Time.milliseconds(50), deadline, (jobStatus) -> jobStatus.equals(JobStatus.CANCELED), TestingUtils.defaultScheduledExecutor()); assertEquals( JobStatus.CANCELED, jobStatusFuture.get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS)); } }
private void initSplitMergeSwitch() throws Exception { if (!admin.isSplitEnabled().get()) { admin.splitSwitch(true).get(); } if (!admin.isMergeEnabled().get()) { admin.mergeSwitch(true).get(); } assertTrue(admin.isSplitEnabled().get()); assertTrue(admin.isMergeEnabled().get()); }
@Test(timeOut = 20000) public void createOptimisticBaseNotExist() throws Exception { CompletableFuture<Void> promise = new CompletableFuture<>(); MetaStoreImplZookeeper.asyncCreateFullPathOptimistic( zkc, "/foo", "bar/zar/gar", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, (rc, path, ctx, name) -> { if (rc != KeeperException.Code.OK.intValue()) { promise.completeExceptionally(KeeperException.create(rc)); } else { promise.complete(null); } }); try { promise.get(); fail("should have failed"); } catch (ExecutionException ee) { assertEquals(ee.getCause().getClass(), KeeperException.NoNodeException.class); } }
@Test public void testReceiveReply() throws Exception { CompletableFuture<Web3ClientVersion> reply = service.sendAsync( request, Web3ClientVersion.class); sendGethVersionReply(); assertTrue(reply.isDone()); assertEquals("geth-version", reply.get().getWeb3ClientVersion()); }
@Test public void futureTestBean() throws Exception { String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}"; ResolvableType type = forClassWithGenerics(CompletableFuture.class, TestBean.class); MethodParameter param = this.testMethod.arg(type); CompletableFuture<?> future = resolveValue(param, body); assertEquals(new TestBean("f1", "b1"), future.get()); }
@Test public void isProcedureFinished() throws Exception { boolean failed = false; try { admin.isProcedureFinished("fake-signature", "fake-instance", new HashMap<>()).get(); } catch (Exception e) { failed = true; } Assert.assertTrue(failed); }
@Test public void testDisabled() throws InterruptedException, ExecutionException { ASYNC_CONN.getAdmin().disableTable(TABLE_NAME).get(); try { getTable.get().get(new Get(row)).get(); fail("Should fail since table has been disabled"); } catch (ExecutionException e) { Throwable cause = e.getCause(); assertThat(cause, instanceOf(TableNotEnabledException.class)); assertThat(cause.getMessage(), containsString(TABLE_NAME.getNameAsString())); } } }