@Test public void testRun() { task = new SimpleTask("Test Task", c -> { taskStateWhenRunWasCalled = task.getState(); taskIsRun = true; }); task.run(); assertThat(taskStateWhenRunWasCalled, is(TaskState.RUNNING)); assertThat(task.getState(), is(TaskState.FINISHED)); assertThat(taskIsRun, is(true)); }
@Override public void run() { if (state != TaskState.SCHEDULED && state != TaskState.INITIALIZING) { throw new IllegalStateException("Can only run in SCHEDULED or INITIALIZING state, but is " + state); } state = TaskState.RUNNING; LOGGER.info("Task started: " + title); try { runTask(context); state = TaskState.FINISHED; LOGGER.info("Task finished: " + title); } catch (Throwable e) { exception = e; state = TaskState.FAILED; LOGGER.warn("Task failed: " + title, exception); } }
Task implements Runnable { @Override public void run() { if (state != TaskState.SCHEDULED && state != TaskState.INITIALIZING) { throw new IllegalStateException("Can only run in SCHEDULED or INITIALIZING state, but is " + state); } state = TaskState.RUNNING; LOGGER.info("Task started: " + title); try { runTask(context); state = TaskState.FINISHED; LOGGER.info("Task finished: " + title); } catch (Throwable e) { exception = e; state = TaskState.FAILED; LOGGER.warn("Task failed: " + title, exception); } } }
Task implements Runnable { @Override public void run() { if (state != TaskState.SCHEDULED && state != TaskState.INITIALIZING) { throw new IllegalStateException("Can only run in SCHEDULED or INITIALIZING state, but is " + state); } state = TaskState.RUNNING; LOGGER.info("Task started: " + title); try { runTask(context); state = TaskState.FINISHED; LOGGER.info("Task finished: " + title); } catch (Throwable e) { exception = e; state = TaskState.FAILED; LOGGER.warn("Task failed: " + title, exception); } } Task(String title); }
Task implements Runnable { @Override public void run() { if (state != TaskState.SCHEDULED && state != TaskState.INITIALIZING) { throw new IllegalStateException("Can only run in SCHEDULED or INITIALIZING state, but is " + state); } state = TaskState.RUNNING; LOGGER.info("Task started: " + title); try { runTask(context); state = TaskState.FINISHED; LOGGER.info("Task finished: " + title); } catch (Throwable e) { exception = e; state = TaskState.FAILED; LOGGER.warn("Task failed: " + title, exception); } } Task(String title); void markAsScheduled(); @Override void run(); String getTitle(); double getProgress(); String getCurrentStatus(); TaskState getState(); Throwable getException(); @Override String toString(); }
Task implements Runnable { @Override public void run() { if (state != TaskState.SCHEDULED && state != TaskState.INITIALIZING) { throw new IllegalStateException("Can only run in SCHEDULED or INITIALIZING state, but is " + state); } state = TaskState.RUNNING; LOGGER.info("Task started: " + title); try { runTask(context); state = TaskState.FINISHED; LOGGER.info("Task finished: " + title); } catch (Throwable e) { exception = e; state = TaskState.FAILED; LOGGER.warn("Task failed: " + title, exception); } } Task(String title); void markAsScheduled(); @Override void run(); String getTitle(); double getProgress(); String getCurrentStatus(); TaskState getState(); Throwable getException(); @Override String toString();  }