Javadoc
Test utility class for deterministically controlling the execution of cache refresh cycles. This
class is intended for use when the user wants to manage concurrent execution of two different
threads. As a sample use case, imagine we have a cached object with a scheduler that executes
the following runnable on a regular interval:
int thisVal = 0;
LoopController lp = LoopController.create();
Runnable running = new Runnable {
void run() {
lp.await();
thisVal += 1;
}
}
Without the LoopController inserted in the run statement, we would not be able to
deterministically guarantee how many cycles had completed. With the LoopController, we can now
advance it manually from our test code.
Example test code:
lp.start(); //this advances past the first barrier and freezes the runnable at the second
Assert.assertEquals(0, thisVal);
lp.advance(); //completes a cycle of the runnable and freezes at the second barrier again
Assert.assertEquals(1, thisVal);