NodeAgentContextManager implements NodeAgentContextSupplier, NodeAgentScheduler { @Override public boolean setFrozen(boolean frozen, Duration timeout) { synchronized (monitor) { if (wantFrozen != frozen) { wantFrozen = frozen; monitor.notifyAll(); } boolean successful; long remainder; long end = clock.instant().plus(timeout).toEpochMilli(); while (!(successful = isFrozen == frozen) && (remainder = end - clock.millis()) > 0) { try { monitor.wait(remainder); } catch (InterruptedException ignored) { } } return successful; } } NodeAgentContextManager(Clock clock, NodeAgentContext context); @Override void scheduleTickWith(NodeAgentContext context, Instant at); @Override boolean setFrozen(boolean frozen, Duration timeout); @Override NodeAgentContext nextContext(); @Override NodeAgentContext currentContext(); @Override void interrupt();  }
@Test(timeout = TIMEOUT) public void setFrozen_blocks_at_least_for_duration_of_timeout() { long wantedDurationMillis = 100; long start = clock.millis(); assertFalse(manager.setFrozen(false, Duration.ofMillis(wantedDurationMillis))); long actualDurationMillis = clock.millis() - start; assertTrue(actualDurationMillis >= wantedDurationMillis); }