/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
/** * {@inheritDoc} */ @Override public Throwable getError() throws PromiseUnresolvedException { return _task.getError(); }
@Override protected void doRunExample(final Engine engine) throws Exception { final MockService<String> httpClient = getService(); final Task<Integer> fetchAndLength = fetch404Url(httpClient, "http://www.google.com") .map("length", x -> x.length()); engine.run(fetchAndLength); fetchAndLength.await(); System.out.println("Error while fetching url: " + fetchAndLength.getError()); ExampleUtil.printTracingResults(fetchAndLength); } }
public void testFlatMapFuncReturnNulll() { Task<String> task = getSuccessTask().flatMap(str -> null); runAndWaitException("AbstractTaskTest.testFlatMapFuncReturnNulll", task, RuntimeException.class); assertTrue(task.getError().getMessage().contains("returned null")); }
public void testWithSideEffectFuncReturnNulll() { Task<String> task = getSuccessTask().withSideEffect(str -> null); runAndWaitException("AbstractTaskTest.testWithSideEffectFuncReturnNulll", task, RuntimeException.class); assertTrue(task.getError().getMessage().contains("returned null")); }
public void testRecoverWithFuncReturnNulll() { Task<String> task = getFailureTask().recoverWith(e -> null); runAndWaitException("AbstractTaskTest.testRecoverWithFuncReturnNulll", task, RuntimeException.class); assertTrue(task.getError().getMessage().contains("returned null")); }
@Test public void testFailure() { Exception e = new Exception("ups!"); Task<Integer> task = Task.failure(e); try { runAndWait("TestTaskFactoryMethods.testFailure", task); fail("should have failed"); } catch (Exception ex) { assertEquals(task.getError(), e); } assertEquals(countTasks(task.getTrace()), 1); }
@Test public void testTransformFailureToSuccess() { Task<String> failure = getFailureTask(); Task<String> transformed = failure.transform(tryT -> Success.of(tryT.getError().toString() + "transformed")); runAndWait("AbstractTaskTest.testTransformFailureToSuccess", transformed); assertEquals(transformed.get(), failure.getError().toString() + "transformed"); }
@Test public void testToTryCancelled() throws InterruptedException { Task<String> cancelMain = delayedValue("value", 6000, TimeUnit.MILLISECONDS); Task<Try<String>> task = cancelMain.toTry(); run(task); assertTrue(cancelMain.cancel(new Exception("canceled"))); task.await(); assertTrue(task.isDone()); assertTrue(task.isFailed()); assertTrue(Exceptions.isCancellation(task.getError())); logTracingResults("AbstractTaskTest.testToTryCancelled", task); }
public void testCancelledRecover(int expectedNumberOfTasks) { Task<Integer> cancelled = getCancelledTask().map("strlen", String::length).recover(e -> -1); try { runAndWait("AbstractTaskTest.testCancelledRecover", cancelled); fail("should have failed"); } catch (Exception ex) { assertTrue(cancelled.isFailed()); assertTrue(Exceptions.isCancellation(cancelled.getError())); } assertEquals(countTasks(cancelled.getTrace()), expectedNumberOfTasks); }
private <T> void assertDone(final Task<T> task, final T expectedValue) { assertTrue(task.isDone()); assertFalse(task.isFailed()); assertEquals(expectedValue, task.get()); assertNull(task.getError()); assertTrue(task.getShallowTrace().getStartNanos() > 0); assertTrue(task.getShallowTrace().getStartNanos() <= task.getShallowTrace().getEndNanos()); }