@Test public void verifyPollingTaskExecutionExceptionIsNotSwallowed() throws Exception { TaskExecutionException ex = TaskExecutionException.ofNextPolling(INTERVAL, ConfigElement.empty()); BaseOperator op = new BaseOperator(newContext(temporaryFolder.getRoot().toPath(), request)) { @Override public TaskResult runTask() { throw ex; } }; try { op.run(); fail(); } catch (TaskExecutionException e) { assertThat(e, is(ex)); assertThat(e.isError(), is(false)); assertThat(e.getRetryInterval().get(), is(INTERVAL)); } }
@Override public TaskResult run() { RetryControl retry = RetryControl.prepare(request.getConfig(), request.getLastStateParams(), false); try { try { return runTask(); } finally { workspace.close(); } } catch (RuntimeException ex) { if (ex instanceof TaskExecutionException) { TaskExecutionException tex = (TaskExecutionException) ex; boolean isPolling = !tex.isError(); if (isPolling) { throw tex; } } boolean doRetry = retry.evaluate(); if (doRetry) { throw TaskExecutionException.ofNextPollingWithCause(ex, retry.getNextRetryInterval(), ConfigElement.copyOf(retry.getNextRetryStateParams())); } else { throw ex; } } }
BaseOperator implements Operator { @Override public TaskResult run() { RetryControl retry = RetryControl.prepare(request.getConfig(), request.getLastStateParams(), false); try { try { return runTask(); } finally { workspace.close(); } } catch (RuntimeException ex) { if (ex instanceof TaskExecutionException) { TaskExecutionException tex = (TaskExecutionException) ex; boolean isPolling = !tex.isError(); if (isPolling) { throw tex; } } boolean doRetry = retry.evaluate(); if (doRetry) { throw TaskExecutionException.ofNextPollingWithCause(ex, retry.getNextRetryInterval(), ConfigElement.copyOf(retry.getNextRetryStateParams())); } else { throw ex; } } } }
BaseOperator implements Operator { @Override public TaskResult run() { RetryControl retry = RetryControl.prepare(request.getConfig(), request.getLastStateParams(), false); try { try { return runTask(); } finally { workspace.close(); } } catch (RuntimeException ex) { if (ex instanceof TaskExecutionException) { TaskExecutionException tex = (TaskExecutionException) ex; boolean isPolling = !tex.isError(); if (isPolling) { throw tex; } } boolean doRetry = retry.evaluate(); if (doRetry) { throw TaskExecutionException.ofNextPollingWithCause(ex, retry.getNextRetryInterval(), ConfigElement.copyOf(retry.getNextRetryStateParams())); } else { throw ex; } } } BaseOperator(OperatorContext context); }
BaseOperator implements Operator { @Override public TaskResult run() { RetryControl retry = RetryControl.prepare(request.getConfig(), request.getLastStateParams(), false); try { try { return runTask(); } finally { workspace.close(); } } catch (RuntimeException ex) { if (ex instanceof TaskExecutionException) { TaskExecutionException tex = (TaskExecutionException) ex; boolean isPolling = !tex.isError(); if (isPolling) { throw tex; } } boolean doRetry = retry.evaluate(); if (doRetry) { throw TaskExecutionException.ofNextPollingWithCause(ex, retry.getNextRetryInterval(), ConfigElement.copyOf(retry.getNextRetryStateParams())); } else { throw ex; } } } BaseOperator(OperatorContext context); @Override TaskResult run(); abstract TaskResult runTask(); }
BaseOperator implements Operator { @Override public TaskResult run() { RetryControl retry = RetryControl.prepare(request.getConfig(), request.getLastStateParams(), false); try { try { return runTask(); } finally { workspace.close(); } } catch (RuntimeException ex) { if (ex instanceof TaskExecutionException) { TaskExecutionException tex = (TaskExecutionException) ex; boolean isPolling = !tex.isError(); if (isPolling) { throw tex; } } boolean doRetry = retry.evaluate(); if (doRetry) { throw TaskExecutionException.ofNextPollingWithCause(ex, retry.getNextRetryInterval(), ConfigElement.copyOf(retry.getNextRetryStateParams())); } else { throw ex; } } } BaseOperator(OperatorContext context); @Override TaskResult run(); abstract TaskResult runTask();  }