Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/org/zeromq/timer/ZTicket.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ public long timeout()
sortIfNeeded();
// Tickets are sorted, so check first ticket
Ticket first = tickets.get(0);
return first.start - now() + first.delay;
long time = first.start - now() + first.delay;

if (time > 0) {
return time;
}
else {
return 0;
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/zeromq/timer/ZTickerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.Test;
import org.zeromq.timer.ZTicket.Ticket;
import org.zeromq.timer.ZTimer.Timer;
import zmq.ZMQ;

public class ZTickerTest
{
Expand Down Expand Up @@ -68,6 +69,16 @@ public void testTicketInsertion()
assertThat(ticker.timeout(), is(1L));
}

@Test
public void testTicketTimeout()
{
ZTicker ticker = new ZTicker();
Ticket ticket = ticker.addTicket(1, NOOP);
ZMQ.sleep(1);
assertThat(ticket, is(notNullValue()));
assertThat(ticker.timeout(), is(0L));
}

@Test
public void testTimerInsertion()
{
Expand Down