long timeToNextHeartbeat(long now) {
        update(now);
        return heartbeatTimer.remainingMs();
    }
@Test
    public void testTimeToNextHeartbeat() {
        heartbeat.sentHeartbeat(time.milliseconds());
        assertEquals(heartbeatIntervalMs, heartbeat.timeToNextHeartbeat(time.milliseconds()));

        time.sleep(heartbeatIntervalMs);
        assertEquals(0, heartbeat.timeToNextHeartbeat(time.milliseconds()));

        time.sleep(heartbeatIntervalMs);
        assertEquals(0, heartbeat.timeToNextHeartbeat(time.milliseconds()));
    }