diff options
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java index 99111366b8e..195b07bd73f 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextManagerTest.java @@ -7,6 +7,8 @@ import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.util.Optional; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -146,46 +148,30 @@ public class NodeAgentContextManagerTest { } private static class AsyncExecutor<T> { - private final Object monitor = new Object(); - private final Thread thread; + private final CountDownLatch latch = new CountDownLatch(1); private volatile Optional<T> response = Optional.empty(); private volatile Optional<Exception> exception = Optional.empty(); - private boolean completed = false; - private AsyncExecutor(ThrowingSupplier<T> supplier) { - this.thread = new Thread(() -> { + private AsyncExecutor(Callable<T> supplier) { + new Thread(() -> { try { - response = Optional.of(supplier.get()); + response = Optional.of(supplier.call()); } catch (Exception e) { exception = Optional.of(e); } - synchronized (monitor) { - completed = true; - monitor.notifyAll(); - } - }); - this.thread.start(); + latch.countDown(); + }).start(); } private AsyncExecutor<T> awaitResult() { - synchronized (monitor) { - while (!completed) { - try { - monitor.wait(); - } catch (InterruptedException ignored) { } - } - } + try { + latch.await(); + } catch (InterruptedException ignored) { } return this; } private boolean isCompleted() { - synchronized (monitor) { - return completed; - } + return latch.getCount() == 0; } } - - private interface ThrowingSupplier<T> { - T get() throws Exception; - } }
\ No newline at end of file |