Corrected some IO loop tests.
diff --git a/utils/nio/src/main/java/org/onlab/nio/SelectorLoop.java b/utils/nio/src/main/java/org/onlab/nio/SelectorLoop.java
index fc88e16..a74703a 100644
--- a/utils/nio/src/main/java/org/onlab/nio/SelectorLoop.java
+++ b/utils/nio/src/main/java/org/onlab/nio/SelectorLoop.java
@@ -7,6 +7,7 @@
import java.nio.channels.Selector;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.lang.System.currentTimeMillis;
/**
* Abstraction of an I/O processing loop based on an NIO selector.
@@ -118,4 +119,41 @@
notifyAll();
}
+ /**
+ * Waits for the loop execution to start.
+ *
+ * @param timeout number of milliseconds to wait
+ * @return true if loop started in time
+ */
+ public final synchronized boolean awaitStart(long timeout) {
+ long max = currentTimeMillis() + timeout;
+ while (state != State.STARTED && (currentTimeMillis() < max)) {
+ try {
+ wait(timeout);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted", e);
+ }
+ }
+ return state == State.STARTED;
+ }
+
+ /**
+ * Waits for the loop execution to stop.
+ *
+ * @param timeout number of milliseconds to wait
+ * @return true if loop finished in time
+ */
+ public final synchronized boolean awaitStop(long timeout) {
+ long max = currentTimeMillis() + timeout;
+ while (state != State.STOPPED && (currentTimeMillis() < max)) {
+ try {
+ wait(timeout);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted", e);
+ }
+ }
+ return state == State.STOPPED;
+ }
+
+
}