Source:
public void testMetrics() throws Exception { List<BufferOrEvent> output = new ArrayList<>(); ValidatingCheckpointHandler handler = new ValidatingCheckpointHandler(); int numberOfChannels = 3; inputGate = createCheckpointedInputGate(numberOfChannels, handler); int[] sequenceNumbers = new int[numberOfChannels]; int bufferSize = 100; long checkpointId = 1; long sleepTime = 10; long checkpointBarrierCreation = System.currentTimeMillis(); long alignmentStartNanos = System.nanoTime(); Thread.sleep(sleepTime); addSequence( inputGate, output, sequenceNumbers, createBuffer(0, bufferSize), createBuffer(1, bufferSize), createBuffer(2, bufferSize), createBarrier(checkpointId, 1, checkpointBarrierCreation), createBuffer(0, bufferSize), createBuffer(2, bufferSize), createBarrier(checkpointId, 0), createBuffer(2, bufferSize)); Thread.sleep(sleepTime); addSequence(inputGate, output, sequenceNumbers, createBarrier(checkpointId, 2), createBuffer(0, bufferSize), createBuffer(1, bufferSize), createBuffer(2, bufferSize), createEndOfPartition(0), createEndOfPartition(1), createEndOfPartition(2)); long startDelay = System.currentTimeMillis() - checkpointBarrierCreation; long alignmentDuration = System.nanoTime() - alignmentStartNanos; assertThat(inputGate.getCheckpointStartDelayNanos() / 1_000_000, Matchers.greaterThanOrEqualTo(sleepTime)); assertThat(inputGate.getCheckpointStartDelayNanos() / 1_000_000, Matchers.lessThanOrEqualTo(startDelay)); assertTrue(handler.getLastAlignmentDurationNanos().isDone()); assertThat(handler.getLastAlignmentDurationNanos().get() / 1_000_000, Matchers.greaterThanOrEqualTo(sleepTime)); assertThat(handler.getLastAlignmentDurationNanos().get(), Matchers.lessThanOrEqualTo(alignmentDuration)); assertTrue(handler.lastBytesProcessedDuringAlignment.isDone()); assertThat(handler.lastBytesProcessedDuringAlignment.get(), Matchers.equalTo(3L * bufferSize)); }

Target:
public void testMetrics() throws Exception { List<BufferOrEvent> output = new ArrayList<>(); ValidatingCheckpointHandler handler = new ValidatingCheckpointHandler(); int numberOfChannels = 3; inputGate = createCheckpointedInputGate(numberOfChannels, handler); int[] sequenceNumbers = new int[numberOfChannels]; int bufferSize = 100; long checkpointId = 1; long sleepTime = 10; long checkpointBarrierCreation = System.currentTimeMillis(); long alignmentStartNanos = System.nanoTime(); Thread.sleep(sleepTime); addSequence( inputGate, output, sequenceNumbers, createBuffer(0, bufferSize), createBuffer(1, bufferSize), createBuffer(2, bufferSize), createBarrier(checkpointId, 1, checkpointBarrierCreation), createBuffer(0, bufferSize), createBuffer(2, bufferSize), createBarrier(checkpointId, 0), createBuffer(2, bufferSize)); Thread.sleep(sleepTime); addSequence(inputGate, output, sequenceNumbers, createBarrier(checkpointId, 2), createBuffer(0, bufferSize), createBuffer(1, bufferSize), createBuffer(2, bufferSize), createEndOfPartition(0), createEndOfPartition(1), createEndOfPartition(2)); long startDelay = System.currentTimeMillis() - checkpointBarrierCreation; long alignmentDuration = System.nanoTime() - alignmentStartNanos; assertThat(inputGate.getCheckpointStartDelayNanos() / 1_000_000, is(both(greaterThanOrEqualTo(sleepTime)).and(lessThanOrEqualTo(startDelay)))); assertTrue(handler.getLastAlignmentDurationNanos().isDone()); assertThat(handler.getLastAlignmentDurationNanos().get() / 1_000_000, is(both(greaterThanOrEqualTo(sleepTime)).and(lessThanOrEqualTo(alignmentDuration)))); assertTrue(handler.getLastBytesProcessedDuringAlignment().isDone()); assertThat(handler.getLastBytesProcessedDuringAlignment().get(), equalTo(3L * bufferSize)); }