public void add(long offset, DeferredEvent event) {
        if (!pending.isEmpty()) {
            long lastKey = pending.lastKey();
            if (offset < lastKey) {
                throw new IllegalArgumentException("There is already a deferred event with " +
                    "offset " + lastKey + ". We should not add one with an offset of " +
                    offset + " which is lower than that.");
            }
        }
        List<DeferredEvent> events = pending.computeIfAbsent(offset, k -> new ArrayList<>());
        events.add(event);
        if (log.isTraceEnabled()) {
            log.trace("Adding deferred event {} at offset {}", event, offset);
        }
    }
@Test
    public void testFailOnIncorrectOrdering() {
        DeferredEventQueue deferredEventQueue = new DeferredEventQueue(new LogContext());
        SampleDeferredEvent event1 = new SampleDeferredEvent();
        SampleDeferredEvent event2 = new SampleDeferredEvent();
        deferredEventQueue.add(2, event1);
        assertThrows(RuntimeException.class, () -> deferredEventQueue.add(1, event2));
    }