Skip to content

Commit

Permalink
Merge pull request #124 from adambalogh/master
Browse files Browse the repository at this point in the history
Return -1 as delay for removed elements in DeltaQueue
  • Loading branch information
olibye committed Apr 2, 2019
2 parents 1b3d8b9 + be91ddb commit a49f6a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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));
}
}

0 comments on commit a49f6a0

Please sign in to comment.