public static String failureToString(final Throwable e) { if (isCancellation(e)) { if (isEarlyFinish(e)) { return ""; } else { return "cancelled because: " + toString(e.getCause()); } } else { return toString(e); } }
/** * Given a task this method will return a {@link ResultType} classification. * * @param task the task to classify * @return the result type classification for the task */ public static ResultType fromTask(final Task<?> task) { if (!task.isDone()) { return UNFINISHED; } else if (task.isFailed()) { if (Exceptions.isEarlyFinish(task.getError())) { return EARLY_FINISH; } return ERROR; } return SUCCESS; } }
protected void traceFailure(final Throwable reason) { if (Exceptions.isEarlyFinish(reason)) { _shallowTraceBuilder.setResultType(ResultType.EARLY_FINISH); } else { _shallowTraceBuilder.setResultType(ResultType.ERROR); _shallowTraceBuilder.setValue(Exceptions.failureToString(reason)); } }
assertTrue("Should be early finish", Exceptions.isEarlyFinish(par.getError())); assertEquals(1, successful.size()); assertEquals("done1", successful.get(0));
@Test public void testTimeoutTaskWithTimeout() throws InterruptedException { // This task will not complete on its own, which allows us to test the timeout final Task<String> task = new BaseTask<String>("task") { @Override protected Promise<? extends String> run(final Context context) throws Exception { return Promises.settable(); } }; final Task<String> timeoutTask = task.withTimeout(200, TimeUnit.MILLISECONDS); try { runAndWait("TestTasks.testTimeoutTaskWithTimeout", timeoutTask); fail("task should finish with Error"); } catch (Throwable t) { assertTrue(timeoutTask.getError() instanceof TimeoutException); } assertTrue(timeoutTask.isFailed()); assertTrue(task.await(5, TimeUnit.SECONDS)); // The original task should also be failed - this time with an early finish // exception. assertTrue(task.isFailed()); assertTrue(Exceptions.isEarlyFinish(task.getError())); }
if (task.isFailed() && !(Exceptions.isEarlyFinish(task.getError()))) { assertNotNull(trace.getValue()); } else {
public static String failureToString(final Throwable e) { if (isCancellation(e)) { if (isEarlyFinish(e)) { return ""; } else { return "cancelled because: " + toString(e.getCause()); } } else { return toString(e); } }
/** * Given a task this method will return a {@link ResultType} classification. * * @param task the task to classify * @return the result type classification for the task */ public static ResultType fromTask(final Task<?> task) { if (!task.isDone()) { return UNFINISHED; } else if (task.isFailed()) { if (Exceptions.isEarlyFinish(task.getError())) { return EARLY_FINISH; } return ERROR; } return SUCCESS; } }
protected void traceFailure(final Throwable reason) { if (Exceptions.isEarlyFinish(reason)) { _shallowTraceBuilder.setResultType(ResultType.EARLY_FINISH); } else { _shallowTraceBuilder.setResultType(ResultType.ERROR); _shallowTraceBuilder.setValue(Exceptions.failureToString(reason)); } }