Skip to content

+tck #29 null checks fixed - null from ABQueue#poll means "timeout" #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could return value at the end sich we return null if it is null. (i.e. you don't need to keep the compiler happy)

  if (value == null) {
      env.flop(String.format("%s within %d ms", errorMsg, timeoutMillis));
   }

   return value;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, less noise +1


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