@Override public void run() { startingGate.countDown(); try { future.checkedGet(); } catch (Exception e) { checkInterruptedException(e); // This only gets hit if the original call throws an exception and // the check call above passes. successLatch.countDown(); } } });
@GwtIncompatible // immediateCheckedFuture public void testMultipleImmediateCheckedFutures() throws Exception { CheckedFuture<String, MyException> future1 = immediateCheckedFuture(DATA1); CheckedFuture<String, MyException> future2 = immediateCheckedFuture(DATA2); // Verify that the proper objects are returned without waiting assertSame(DATA1, future1.get(0L, MILLISECONDS)); assertSame(DATA1, future1.checkedGet(0L, MILLISECONDS)); assertSame(DATA2, future2.get(0L, MILLISECONDS)); assertSame(DATA2, future2.checkedGet(0L, MILLISECONDS)); }
assertTrue(checked.isDone()); assertFalse(checked.isCancelled()); checked.get(); fail(); } catch (ExecutionException expected) { checked.get(5, SECONDS); fail(); } catch (ExecutionException expected) { checked.checkedGet(); fail(); } catch (TestException expected) { checked.checkedGet(5, SECONDS); fail(); } catch (TestException expected) {
public void testCheckedGetThrowsApplicationExceptionOnError() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, new Exception("Error"), latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { latch.countDown(); } }) .start(); try { future.checkedGet(); fail(); } catch (Exception e) { checkExecutionException(e); } assertTrue(future.isDone()); assertFalse(future.isCancelled()); } }
public void testCheckedGetThrowsApplicationExceptionOnInterruption() throws InterruptedException { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); final CountDownLatch startingGate = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(1); assertFalse(future.isDone()); assertFalse(future.isCancelled()); Thread getThread = new Thread( new Runnable() { @Override public void run() { startingGate.countDown(); try { future.checkedGet(); } catch (Exception e) { checkInterruptedException(e); // This only gets hit if the original call throws an exception and // the check call above passes. successLatch.countDown(); } } }); getThread.start(); assertTrue(startingGate.await(500, TimeUnit.MILLISECONDS)); getThread.interrupt(); assertTrue(successLatch.await(500, TimeUnit.MILLISECONDS)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
@Override public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) { try { return delegate.read(LogicalDatastoreType.OPERATIONAL, path).get().orNull(); } catch (InterruptedException | ExecutionException e) { LOG.error("Read of {} failed.", path,e); return null; } }
@Test(expected = SchemaSourceException.class) public void getNonExistingSchemaSource() throws Exception { Futures.failed(new Exception("halo")); Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn( Futures.failed( new SchemaSourceException("Source not provided"))); CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID); assertTrue(sourceFuture.isDone()); sourceFuture.checkedGet(); } }
@Override public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) { try { return delegate.read(LogicalDatastoreType.CONFIGURATION, path).get().orNull(); } catch (InterruptedException | ExecutionException e) { LOG.error("Read of {} failed.", path,e); return null; } }
/** * Tests that the {@link CheckedFuture#checkedGet()} method throws the correct type of * cancellation exception when it is cancelled. */ public void testCheckedGetThrowsApplicationExceptionOnCancellation() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { future.cancel(true); } }) .start(); try { future.checkedGet(); fail("RPC Should have been cancelled."); } catch (Exception e) { checkCancelledException(e); } assertTrue(future.isDone()); assertTrue(future.isCancelled()); }
@CanIgnoreReturnValue @Override public V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X { return delegate().checkedGet(timeout, unit); }
private static <T extends DataObject> T getDataObject(final ReadTransaction readOnlyTransaction, final InstanceIdentifier<T> identifier) { Optional<T> optionalData = null; try { optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get(); if (optionalData.isPresent()) { return optionalData.get(); } } catch (ExecutionException | InterruptedException e) { LOG.error("Read transaction for identifier {} failed.", identifier, e); } return null; }
@GwtIncompatible // immediateCheckedFuture public void testImmediateCheckedFuture() throws Exception { CheckedFuture<String, MyException> future = immediateCheckedFuture(DATA1); assertThat(future.toString()).endsWith("[status=SUCCESS, result=[" + DATA1 + "]]"); // Verify that the proper object is returned without waiting assertSame(DATA1, future.get(0L, MILLISECONDS)); assertSame(DATA1, future.checkedGet(0L, MILLISECONDS)); }
@CanIgnoreReturnValue @Override public V checkedGet() throws X { return delegate().checkedGet(); }
public static <T extends DataObject> Optional<T> syncReadOper(ReadTransaction rt, InstanceIdentifier<T> path) { Optional<T> opt; try { opt = rt.read(LogicalDatastoreType.OPERATIONAL, path).get(); } catch (InterruptedException | ExecutionException e) { LOG.error("unexcepte exception", e); opt = Optional.absent(); } return opt; }
checked.get(); fail(); } catch (InterruptedException expected) { checked.get(5, SECONDS); fail(); } catch (InterruptedException expected) { checked.checkedGet(); fail(); } catch (TestException expected) { checked.checkedGet(5, SECONDS); fail(); } catch (TestException expected) {
@CanIgnoreReturnValue @Override public V checkedGet() throws X { return delegate().checkedGet(); }
private static <T extends DataObject> T getDataObject(final ReadTransaction readOnlyTransaction, final InstanceIdentifier<T> identifier) { Optional<T> optionalData = null; try { optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get(); if (optionalData.isPresent()) { return optionalData.get(); } } catch (ExecutionException | InterruptedException e) { LOG.error("Read transaction for identifier {} failed.", identifier, e); } return null; }
@GwtIncompatible // immediateFailedCheckedFuture public void testImmediateFailedCheckedFuture() throws Exception { MyException exception = new MyException(); CheckedFuture<String, MyException> future = immediateFailedCheckedFuture(exception); assertThat(future.toString()).endsWith("[status=FAILURE, cause=[" + exception + "]]"); try { future.get(0L, MILLISECONDS); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } try { future.checkedGet(0L, MILLISECONDS); fail(); } catch (MyException expected) { assertSame(exception, expected); } }
@CanIgnoreReturnValue @Override public V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X { return delegate().checkedGet(timeout, unit); }
public static <T extends DataObject> T getDataObject(ReadTransaction readOnlyTransaction, InstanceIdentifier<T> identifier) { Optional<T> optionalData = null; try { optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get(); if (optionalData.isPresent()) { return optionalData.get(); } } catch (ExecutionException | InterruptedException e) { LOG.error("Read transaction for identifier {} failed.", identifier, e); } return null; }