@Test public void testCheckpointCallsInOrder() { try { Task task = createTask(); task.startTaskThread(); awaitLatch.await(); for (int i = 1; i <= NUM_CALLS; i++) { task.triggerCheckpointBarrier(i, 156865867234L); } triggerLatch.await(); assertFalse(task.isCanceledOrFailed()); ExecutionState currentState = task.getExecutionState(); if (currentState != ExecutionState.RUNNING && currentState != ExecutionState.FINISHED) { fail("Task should be RUNNING or FINISHED, but is " + currentState); } task.cancelExecution(); task.getExecutingThread().join(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override public void invoke() throws Exception { awaitLatch.trigger(); // wait forever (until canceled) synchronized (this) { while (error == null && lastCheckpointId < NUM_CALLS) { wait(); } } triggerLatch.trigger(); if (error != null) { throw error; } }
@Override public void triggerCheckpoint(long checkpointId, long timestamp) { lastCheckpointId++; if (checkpointId == lastCheckpointId) { if (lastCheckpointId == NUM_CALLS) { triggerLatch.trigger(); } } else if (this.error == null) { this.error = new Exception("calls out of order"); synchronized (this) { notifyAll(); } } }