Skip to content

Commit

Permalink
Merge pull request #30 from ktoso/wip-29-fix-nullchecks
Browse files Browse the repository at this point in the history
+tck #29 null checks fixed - `null` from ABQueue#poll means "timeout"
  • Loading branch information
rkuhn committed Apr 17, 2014
2 parents 86cfc18 + d2507e6 commit 566a700
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -528,25 +528,25 @@ public void complete() {
public T next(long timeoutMillis, String errorMsg) throws InterruptedException {
Optional<T> 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
}

public Optional<T> nextOrEndOfStream(long timeoutMillis, String errorMsg) throws InterruptedException {
Optional<T> 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<T> nextN(int elements, long timeoutMillis, String errorMsg) throws InterruptedException {
Expand All @@ -564,13 +564,11 @@ public List<T> nextN(int elements, long timeoutMillis, String errorMsg) throws I
public void expectCompletion(long timeoutMillis, String errorMsg) throws InterruptedException {
Optional<T> 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 {
Expand Down

0 comments on commit 566a700

Please sign in to comment.