@Test// timeout=300000 public void testABunch() { assertEquals(0, indexOrderChecker.getMissedIndices()); indexOrderChecker.update(0); assertEquals(0, indexOrderChecker.getMissedIndices()); indexOrderChecker.update(1); assertEquals(0, indexOrderChecker.getMissedIndices()); indexOrderChecker.update(3); assertEquals(1, indexOrderChecker.getMissedIndices()); indexOrderChecker.update(8); assertEquals(5, indexOrderChecker.getMissedIndices()); } }
private void read(boolean block) { if (block) { synchronized (yoWhiteBoard) { while (!yoWhiteBoard.isNewDataAvailable()) { yoWhiteBoardReadControllerWaitingGlobalTimer.startMeasurement(); try { yoWhiteBoard.wait(); } catch (InterruptedException e) { } yoWhiteBoardReadControllerWaitingGlobalTimer.stopMeasurement(); } } } numberOfNewDataSinceLastRead.set(yoWhiteBoard.getNumberOfNewDataSinceLastRead()); yoWhiteBoard.readData(); indexOrderChecker.update(yoWhiteBoard.getReadIndex()); if (indexOrderChecker.getMissedIndices() - previousMissedIndices.getIntegerValue() > 0) System.out.println("YoWhiteBoardReadController: missed " + indexOrderChecker.getMissedIndices() + " YoWhiteBoard indices!"); previousMissedIndices.set(indexOrderChecker.getMissedIndices()); } }
@Test// timeout=300000 public void testNoOverflow() { int index = 0; indexOrderChecker.update(index); int increment = 5; index += increment; indexOrderChecker.update(index); assertEquals(increment - 1, indexOrderChecker.getMissedIndices()); }
@Test// timeout=300000 public void testOverflowOne() { int index = Integer.MAX_VALUE; indexOrderChecker.update(index); index++; indexOrderChecker.update(index); assertEquals(0, indexOrderChecker.getMissedIndices()); }
@Test// timeout=300000 public void testOverflowTwo() { int index = Integer.MAX_VALUE - 2; indexOrderChecker.update(index); int increment = 5; index += increment; indexOrderChecker.update(index); assertEquals(increment - 1, indexOrderChecker.getMissedIndices()); }