private void closeClient() { try { mClient.close().get(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { LOG.debug("Failed to close raft client: {}", e.toString()); } catch (TimeoutException e) { LOG.debug("Failed to close raft client after 10 seconds"); } } }
protected void waitPostCommitDone(FutureTask<?> postCommitTask) throws XAException, IOException { try { postCommitTask.get(); } catch (InterruptedException e) { throw new InterruptedIOException(e.toString()); } catch (ExecutionException e) { Throwable t = e.getCause(); if (t instanceof XAException) { throw (XAException) t; } else if (t instanceof IOException) { throw (IOException) t; } else { throw new XAException(e.toString()); } } }
@Override public void close() { if (receiver != null) { try { receiver.close().whenComplete((voidargs, error) -> { try { if (error != null) { logger.error("Exception during receiver close phase" + error.toString()); } ehClient.closeSync(); } catch (Exception e) { logger.error("Exception during ehclient close phase" + e.toString()); } }).get(); } catch (InterruptedException e) { logger.error("Exception occured during close phase" + e.toString()); } catch (ExecutionException e) { logger.error("Exception occured during close phase" + e.toString()); } logger.info("closed eventhub receiver: partitionId=" + partitionId); receiver = null; ehClient = null; } }
@Override public void cleanup() { if (sender != null) { try { sender.close().whenComplete((voidargs, error) -> { try { if (error != null) { logger.error("Exception during sender cleanup phase" + error.toString()); } ehClient.closeSync(); } catch (Exception e) { logger.error("Exception during ehclient cleanup phase" + e.toString()); } }).get(); } catch (InterruptedException e) { logger.error("Exception occured during cleanup phase" + e.toString()); } catch (ExecutionException e) { logger.error("Exception occured during cleanup phase" + e.toString()); } logger.info("Eventhub Bolt cleaned up"); sender = null; ehClient = null; } }
public static void executeWithTimeOut(Queue<String> failures, Callable<Long> task) { ExecutorService es = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(true).build()); Future<Long> future = es.submit(task); try { long timeNS = future.get(TIMEOUT, TimeUnit.SECONDS); logger.debug("\nExecuted in " + TimeUnit.NANOSECONDS.toSeconds(timeNS) + " second(s)"); } catch (ExecutionException e) { fail("Exception during test: " + e.toString(), e); } catch (TimeoutException e) { handleTimout(failures, es, e); } catch (InterruptedException e) { fail("", e); } }
@Test(timeout = 5000) public void toFutureThrows() throws Exception { try { Single.error(new TestException()).toFuture().get(); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); } }
@Test public void onErrorOnComplete() throws Exception { fs.onError(new TestException("One")); fs.onComplete(); try { fs.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } }
@Test public void errorGetWithTimeout() throws Exception { Future<?> f = Single.error(new TestException()).toFuture(); try { f.get(5, TimeUnit.SECONDS); fail("Should have thrown"); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); } }
@Test public void onCompleteOnError() throws Exception { fs.onComplete(); fs.onError(new TestException("One")); try { assertNull(fs.get(5, TimeUnit.MILLISECONDS)); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof NoSuchElementException); } }
@Test public void onErrorOnComplete() throws Exception { List<Throwable> errors = TestHelper.trackPluginErrors(); try { fo.onError(new TestException("One")); fo.onComplete(); try { fo.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } TestHelper.assertUndeliverable(errors, 0, NoSuchElementException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void onError() throws Exception { List<Throwable> errors = TestHelper.trackPluginErrors(); try { fo.onError(new TestException("One")); fo.onError(new TestException("Two")); try { fo.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } TestHelper.assertUndeliverable(errors, 0, TestException.class, "Two"); } finally { RxJavaPlugins.reset(); } }
@Test public void onError() throws Exception { List<Throwable> errors = TestHelper.trackPluginErrors(); try { fs.onError(new TestException("One")); fs.onError(new TestException("Two")); try { fs.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } TestHelper.assertUndeliverable(errors, 0, TestException.class, "Two"); } finally { RxJavaPlugins.reset(); } }
@Test public void onCompleteOnError() throws Exception { List<Throwable> errors = TestHelper.trackPluginErrors(); try { fo.onComplete(); fo.onError(new TestException("One")); try { assertNull(fo.get(5, TimeUnit.MILLISECONDS)); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof NoSuchElementException); } TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { RxJavaPlugins.reset(); } }
LOGGER.error("exception during fetch: "+ee.toString()); } catch(TimeoutException te) {
throw new CloudRuntimeException(e); } catch (ExecutionException e) { s_logger.debug("create cache storage failed: " + e.toString()); throw new CloudRuntimeException(e); } finally {
throw (AssertionError) e.getCause(); fail(e.toString());
@Override public boolean deleteSnapshot(SnapshotInfo snapInfo) { snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested); AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>(); DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null, snapInfo, future); AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context); DataStore store = snapInfo.getDataStore(); store.getDriver().deleteAsync(store, snapInfo, caller); SnapshotResult result = null; try { result = future.get(); if (result.isFailed()) { throw new CloudRuntimeException(result.getResult()); } return true; } catch (InterruptedException e) { s_logger.debug("delete snapshot is failed: " + e.toString()); } catch (ExecutionException e) { s_logger.debug("delete snapshot is failed: " + e.toString()); } return false; }
@Override public boolean revertSnapshot(SnapshotInfo snapshot) { SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary); if (snapshotOnPrimaryStore == null) { throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools"); } PrimaryDataStore store = (PrimaryDataStore)snapshotOnPrimaryStore.getDataStore(); AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>(); RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future); AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context); ((PrimaryDataStoreDriver)store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller); SnapshotResult result = null; try { result = future.get(); if (result.isFailed()) { throw new CloudRuntimeException(result.getResult()); } return true; } catch (InterruptedException e) { s_logger.debug("revert snapshot is failed: " + e.toString()); } catch (ExecutionException e) { s_logger.debug("revert snapshot is failed: " + e.toString()); } return false; }
@Test public void onErrorOnComplete() throws Exception { fo.onError(new TestException("One")); fo.onComplete(); try { fo.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } }
@Test public void onErrorOnComplete() throws Exception { fs.onError(new TestException("One")); fs.onComplete(); try { fs.get(5, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { assertTrue(ex.toString(), ex.getCause() instanceof TestException); assertEquals("One", ex.getCause().getMessage()); } }