public void flush(Consumer<List<FilteredMessage>> flusher) {
        final List<FilteredMessage> flushBatch;
        synchronized (this) {
            flushBatch = buffer;
            buffer = new ArrayList<>(bufferLength);
            bufferLength = 0;
            bufferSizeBytes = 0L;
        }
        if (flushBatch != null) {
            lastFlushTime.set(System.nanoTime());
            flusher.accept(flushBatch);
        }
    }
@Test
    void flush() {
        createNMessages(2).forEach(message -> buffer.appendAndFlush(message, flusher));
        buffer.flush(flusher);

        verify(flusher, times(1)).accept(argThat(argument -> {
            assertThat(argument).hasSize(2);
            return true;
        }));

        buffer.flush(flusher);
        buffer.flush(flusher);

        verify(flusher, times(2)).accept(List.of());
    }