From d2507e6452274eaa0b270f9a6957ac3daa65884c Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Thu, 17 Apr 2014 17:18:27 +0200 Subject: [PATCH] +tck #29 null checks fixed - `null` from ABQueue#poll means "timeout" --- .../reactivestreams/tck/TestEnvironment.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java b/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java index 6a5e38b4..d6e8835f 100644 --- a/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java +++ b/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java @@ -493,10 +493,10 @@ public void assertUncompleted(String errorMsg) { env.flop(errorMsg); } - public void expectCompletion(long timeoutMillis, String errorMsg) throws InterruptedException { if (!isCompleted()) { T val = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS); + if (val == null) { env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis)); } else { @@ -528,12 +528,12 @@ public void complete() { public T next(long timeoutMillis, String errorMsg) throws InterruptedException { Optional value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS); - if (value.isEmpty()) { - env.flop("Expected element but got end-of-stream"); - } else if (value.get() == null) { + if (value == null) { env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis)); - } else { + } else if (value.isDefined()) { return value.get(); + } else { + env.flop("Expected element but got end-of-stream"); } return null; // keep compiler happy @@ -541,12 +541,12 @@ public T next(long timeoutMillis, String errorMsg) throws InterruptedException { public Optional nextOrEndOfStream(long timeoutMillis, String errorMsg) throws InterruptedException { Optional value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS); - if (value.isDefined()) { - return value; - } else { + + if (value == null) { env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis)); - return null; // keep compiler happy } + + return value; } public List nextN(int elements, long timeoutMillis, String errorMsg) throws InterruptedException { @@ -564,13 +564,11 @@ public List nextN(int elements, long timeoutMillis, String errorMsg) throws I public void expectCompletion(long timeoutMillis, String errorMsg) throws InterruptedException { Optional value = abq.poll(timeoutMillis, TimeUnit.MILLISECONDS); - if (value.isEmpty()) { - // ok - } else if (value.get() == null) { + if (value == null) { env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis)); - } else { + } else if (value.isDefined()) { env.flop("Expected end-of-stream but got " + value.get()); - } + } // else, ok } void expectNone(long withinMillis, String errorMsgPrefix) throws InterruptedException {