Repository: incubator-reef Updated Branches: refs/heads/master 7b99be950 -> 85c01c6ce
[REEF-367]: Allow clean multiple calls to Wake Clock close This adds a condition to check if the clock is already closed and a test that invokes close calls from multiple threads. JIRA: [REEF-367] https://issues.apache.org/jira/browse/REEF-367 Pull Request: This closes #215 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/85c01c6c Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/85c01c6c Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/85c01c6c Branch: refs/heads/master Commit: 85c01c6ceed49b2bc97a6031cc32bf9f16e427ec Parents: 7b99be9 Author: Byung-Gon Chun <[email protected]> Authored: Fri Jun 12 16:02:49 2015 +0900 Committer: Brian Cho <[email protected]> Committed: Fri Jun 12 17:54:16 2015 +0900 ---------------------------------------------------------------------- .../reef/wake/time/runtime/RuntimeClock.java | 4 ++++ .../apache/reef/wake/test/time/ClockTest.java | 24 ++++++++++++++++++++ 2 files changed, 28 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/85c01c6c/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/time/runtime/RuntimeClock.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/time/runtime/RuntimeClock.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/time/runtime/RuntimeClock.java index d67bec2..d8f27da 100644 --- a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/time/runtime/RuntimeClock.java +++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/time/runtime/RuntimeClock.java @@ -112,6 +112,10 @@ public final class RuntimeClock implements Clock { public final void close() { LOG.entering(RuntimeClock.class.getCanonicalName(), "close"); synchronized (this.schedule) { + if (this.closed) { + LOG.log(Level.INFO, "Clock is already closed"); + return; + } this.schedule.clear(); this.schedule.add(new StopTime(findAcceptableStopTime())); this.schedule.notifyAll(); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/85c01c6c/lang/java/reef-wake/wake/src/test/java/org/apache/reef/wake/test/time/ClockTest.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-wake/wake/src/test/java/org/apache/reef/wake/test/time/ClockTest.java b/lang/java/reef-wake/wake/src/test/java/org/apache/reef/wake/test/time/ClockTest.java index 6a1c8b2..2cdab5b 100644 --- a/lang/java/reef-wake/wake/src/test/java/org/apache/reef/wake/test/time/ClockTest.java +++ b/lang/java/reef-wake/wake/src/test/java/org/apache/reef/wake/test/time/ClockTest.java @@ -114,6 +114,30 @@ public class ClockTest { } @Test + public void testMultipleCloseCalls() throws Exception { + LoggingUtils.setLoggingLevel(Level.FINE); + + final int numThreads = 3; + final RuntimeClock clock = buildClock(); + new Thread(clock).start(); + final ThreadPoolStage<Alarm> stage = new ThreadPoolStage<>(new EventHandler<Alarm>() { + @Override + public void onNext(final Alarm value) { + clock.close(); + } + }, numThreads); + + try { + for (int i = 0; i < numThreads; ++i) + stage.onNext(null); + Thread.sleep(1000); + } finally { + stage.close(); + clock.close(); + } + } + + @Test public void testSimultaneousAlarms() throws Exception { LoggingUtils.setLoggingLevel(Level.FINE);
