public NavigableSet<Position> getMessagesToReplayNow(int maxMessagesToRead) {
        return messagesToRedeliver.items(maxMessagesToRead, PositionFactory::create);
    }
@Test(dataProvider = "allowOutOfOrderDelivery", timeOut = 10000)
    public void testGetMessagesToReplayNow(boolean allowOutOfOrderDelivery) throws Exception {
        MessageRedeliveryController controller = new MessageRedeliveryController(allowOutOfOrderDelivery);
        controller.add(2, 2);
        controller.add(1, 3);
        controller.add(3, 1);
        controller.add(2, 1);
        controller.add(3, 2);
        controller.add(1, 2);
        controller.add(1, 1);

        if (allowOutOfOrderDelivery) {
            // The entries are sorted by ledger ID but not by entry ID
            Position[] actual1 = controller.getMessagesToReplayNow(3).toArray(new Position[3]);
            Position[] expected1 = { PositionFactory.create(1, 1), PositionFactory.create(1, 2), PositionFactory.create(1, 3) };
            assertEqualsNoOrder(actual1, expected1);
        } else {
            // The entries are completely sorted
            Set<Position> actual2 = controller.getMessagesToReplayNow(6);
            Set<Position> expected2 = new TreeSet<>();
            expected2.add(PositionFactory.create(1, 1));
            expected2.add(PositionFactory.create(1, 2));
            expected2.add(PositionFactory.create(1, 3));
            expected2.add(PositionFactory.create(2, 1));
            expected2.add(PositionFactory.create(2, 2));
            expected2.add(PositionFactory.create(3, 1));
            assertEquals(actual2, expected2);
        }
    }