public void waitForInternalState(TaskImpl task, TaskStateInternal finalState) throws Exception { int timeoutSecs = 0; TaskReport report = task.getReport(); TaskStateInternal iState = task.getInternalState(); while (!finalState.equals(iState) && timeoutSecs++ < 20) { System.out.println("Task Internal State is : " + iState + " Waiting for Internal state : " + finalState + " progress : " + report.getProgress()); Thread.sleep(500); report = task.getReport(); iState = task.getInternalState(); } System.out.println("Task Internal State is : " + iState); Assert.assertEquals("Task Internal state is not correct (timedout)", finalState, iState); }