long nextCheckTimeNs() {
        BrokerHeartbeatState broker = unfenced.first();
        if (broker == null) {
            return Long.MAX_VALUE;
        } else {
            return broker.lastContactNs + sessionTimeoutNs;
        }
    }
@Test
    public void testNextCheckTimeNs() {
        BrokerHeartbeatManager manager = newBrokerHeartbeatManager();
        MockTime time = (MockTime)  manager.time();
        assertEquals(Long.MAX_VALUE, manager.nextCheckTimeNs());
        for (int brokerId = 0; brokerId < 4; brokerId++) {
            manager.register(brokerId, true);
        }
        manager.touch(0, false, 0);
        time.sleep(2);
        manager.touch(1, false, 0);
        time.sleep(1);
        manager.touch(2, false, 0);
        time.sleep(1);
        manager.touch(3, false, 0);
        assertEquals(Optional.empty(), manager.findOneStaleBroker());
        assertEquals(10_000_000, manager.nextCheckTimeNs());
        time.sleep(7);
        assertEquals(10_000_000, manager.nextCheckTimeNs());
        assertEquals(Optional.of(0), manager.findOneStaleBroker());
        manager.fence(0);
        assertEquals(12_000_000, manager.nextCheckTimeNs());

        time.sleep(3);
        assertEquals(Optional.of(1), manager.findOneStaleBroker());
        manager.fence(1);
        assertEquals(Optional.of(2), manager.findOneStaleBroker());
        manager.fence(2);

        assertEquals(14_000_000, manager.nextCheckTimeNs());
    }