/** * @param buf Byte buffer to unmarshal. * @return Unmarshalled object. * @throws IgniteCheckedException Thrown if any exception occurs while unmarshalling. */ @SuppressWarnings({"RedundantTypeArguments"}) protected static <T> T unmarshal(final byte[] buf) throws IgniteCheckedException { RunnableFuture<T> f = new FutureTask<>(new Callable<T>() { @Override public T call() throws IgniteCheckedException { return marsh.<T>unmarshal(buf, Thread.currentThread().getContextClassLoader()); } }); // Any deserialization has to be executed under a thread, that contains the Ignite instance name. new IgniteThread(igniteInstanceName, "unmarshal-thread", f).start(); try { return f.get(); } catch (Exception e) { if (e.getCause() instanceof IgniteCheckedException) throw (IgniteCheckedException)e.getCause(); fail(e.getCause().getMessage()); } return null; }
value = future.get(); gotValue = true;
when(failingFuture.get()).thenThrow(new ExecutionException(new Exception("Test exception")));
snapshotResult = snapshot.get();
((RunnableFuture) in).get(); } catch (final Exception e) {
@Test public void testCompleteAndThenCancel() throws Exception { RunnableFuture<Integer> interruptible = new InterruptibleFuture<Integer>() { @Override public Integer call() throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } return 1; } }; executor.execute(interruptible); assertThat(interruptible.get(), is(1)); interruptible.cancel(true); assertThat(interruptible.get(), is(1)); }
@Test public void testSimple() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); executor.execute(interruptible); assertThat(interruptible.get(), is(1)); }
@Test public void testCancelButRunToCompletion() throws Exception { final CountDownLatch started = new CountDownLatch(1); final CountDownLatch hang = new CountDownLatch(1); RunnableFuture<Integer> interruptible = new InterruptibleFuture<Integer>() { @Override public Integer call() { try { started.countDown(); hang.await(); return 0; } catch (InterruptedException e) { return 1; } } }; executor.execute(interruptible); started.await(); interruptible.cancel(true); assertThat(interruptible.get(), is(1)); }
@Test public void testNoStart() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); expectedException.expect(TimeoutException.class); interruptible.get(10, TimeUnit.MILLISECONDS); }
@Test public void testCancelTrueBeforeStart() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); interruptible.cancel(true); executor.execute(interruptible); expectedException.expect(CancellationException.class); interruptible.get(); }
@Test public void testCancelFalseBeforeStart() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); interruptible.cancel(false); executor.execute(interruptible); expectedException.expect(CancellationException.class); interruptible.get(); }
@Test public void testCancelAfterRunning() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); interruptible.run(); interruptible.cancel(true); assertThat(interruptible.get(), is(1)); }
@Test public void testCancelFalseNoStart() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); interruptible.cancel(false); expectedException.expect(CancellationException.class); interruptible.get(); }
@Test public void testCancelTrueNoStart() throws Exception { RunnableFuture<Integer> interruptible = getInterruptible(); interruptible.cancel(true); expectedException.expect(CancellationException.class); interruptible.get(); }
public Long getPluginPid() { try { return pluginPidJob.get(); } catch ( Exception e ) { return null; } }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return result.get(timeout, unit); } }
public Long getPluginPid() { try { return pluginPidJob.get(); } catch ( Exception e ) { return null; } }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { return task.get(timeout, unit); } catch (ExecutionException ex) { throw rewrapExecutionException(ex); } }
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException { if (null == future) { return null; } if (!future.isDone()) { future.run(); } return future.get(); }
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException { if (null == future) { return null; } if (!future.isDone()) { future.run(); } return future.get(); }