Skip to content
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

Return -1 as delay for removed elements in DeltaQueue #124

Merged
merged 3 commits into from Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,7 +42,7 @@ public long delay(T element) {
next = next.next;
}
if (next == null) {
throw new IllegalStateException("Element not found in the delay queue");
return -1;
}
return ret;
}
Expand Down
Expand Up @@ -146,10 +146,7 @@ public void testGetDelayOnPassedTasks() throws Exception {

scheduler.tick(2, TimeUnit.MILLISECONDS);

try {
assertEquals(0, task1.getDelay(TimeUnit.MILLISECONDS));
fail("should have thrown IllegalStateException");
} catch (IllegalStateException expected) {}
assertEquals(-1, task1.getDelay(TimeUnit.MILLISECONDS));
}

public class ExampleException extends Exception {}
Expand Down
Expand Up @@ -167,4 +167,11 @@ public void testReturnsFalseIfElementAlreadyRemoved() {

assertFalse(deltaQueue.remove(elementC));
}

public void testDelayIsMinusOneWhenElementIsAlreadyRemoved() {
deltaQueue.add(1L, elementA);
deltaQueue.remove(elementA);

assertEquals("delay", -1, deltaQueue.delay(elementA));
}
}