@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(); } } });
@CanIgnoreReturnValue @Override public V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X { return delegate().checkedGet(timeout, unit); }
@CanIgnoreReturnValue @Override public V checkedGet() throws X { return delegate().checkedGet(); }
@CanIgnoreReturnValue @Override public V checkedGet() throws X { return delegate().checkedGet(); }
@CanIgnoreReturnValue @Override public V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X { return delegate().checkedGet(timeout, unit); }
@CanIgnoreReturnValue @Override public V checkedGet() throws X { return delegate().checkedGet(); }
@CanIgnoreReturnValue @Override public V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X { return delegate().checkedGet(timeout, unit); }
@GwtIncompatible // makeChecked public void testMakeChecked_propagatesFailedMappers() throws Exception { SettableFuture<String> future = SettableFuture.create(); CheckedFuture<String, TestException> checked = makeChecked( future, new Function<Exception, TestException>() { @Override public TestException apply(Exception from) { throw new NullPointerException(); } }); future.setException(new Exception("failed")); try { checked.checkedGet(); fail(); } catch (NullPointerException expected) { } try { checked.checkedGet(5, SECONDS); fail(); } catch (NullPointerException 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()); } }
@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)); }
/** * 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()); }
checked.checkedGet(); fail(); } catch (TestException expected) { checked.checkedGet(5, SECONDS); fail(); } catch (TestException expected) {
@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)); }
@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); } }
checked.checkedGet(); fail(); } catch (TestException expected) { checked.checkedGet(5, SECONDS); fail(); } catch (TestException expected) {
@GwtIncompatible // makeChecked public void testMakeChecked_mapsCancellation() throws Exception { SettableFuture<String> future = SettableFuture.create(); CheckedFuture<String, TestException> checked = makeChecked(future, mapper); assertTrue(future.cancel(true)); // argument is ignored try { checked.get(); fail(); } catch (CancellationException expected) { } try { checked.get(5, SECONDS); fail(); } catch (CancellationException expected) { } try { checked.checkedGet(); fail(); } catch (TestException expected) { assertThat(expected.getCause()).isInstanceOf(CancellationException.class); } try { checked.checkedGet(5, SECONDS); fail(); } catch (TestException expected) { assertThat(expected.getCause()).isInstanceOf(CancellationException.class); } }
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Exists: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); try { return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent()); } catch (ReadFailedException e) { return Futures.immediateFailedCheckedFuture(e); } } }
@Override public void run() { try { SourceState state = future.checkedGet(); plugin.initiateMetadataRefresh(); String result = state.getStatus() == SourceStatus.bad ? "started in bad state" : "started sucessfully"; logger.info("Plugin {} {} after {}ms. Current status: {}", plugin.getName(), result, plugin.getStartupTime(), state); } catch (Exception ex) { logger.error("Failure while starting plugin {} after {}ms.", plugin.getName(), plugin.getStartupTime(), ex); plugin.initiateFixFailedStartTask(); } }
@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(); } }
@Test public void getExistingYangTextSchemaSource() throws IOException, SchemaSourceException { String source = "Test"; YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource( ID, ByteSource.wrap(source.getBytes())); YangTextSchemaSourceSerializationProxy sourceProxy = new YangTextSchemaSourceSerializationProxy(schemaSource); Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)) .thenReturn(Futures.successful(sourceProxy)); YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet(); assertEquals(providedSource.getIdentifier(), ID); assertArrayEquals(providedSource.read(), schemaSource.read()); }