@Test
    public void testArchiverInSameBatchWhenWithinGrace() throws Exception
    {
        // Setup fixture.
        final int maxWorkQueueSize = 100;
        final Duration maxPurgeInterval = Duration.ofMillis( 5000 );
        final Duration gracePeriod = Duration.ofMillis( 250 );
        final DummyArchiver archiver = new DummyArchiver( "test", maxWorkQueueSize, maxPurgeInterval, gracePeriod );
        final Thread thread = new Thread( archiver );

        try
        {
            // Execute system under test.
            thread.start();
            final Instant start = Instant.now();
            archiver.archive( 1 );
            archiver.archive( 2 );
            if ( Duration.between( start, Instant.now() ).compareTo( gracePeriod ) >= 0 )
            {
                // This is very unlikely (maybe caused by a stop-the-world garbage collection), but would render the test result useless. Better to check for it explicitly.
                throw new IllegalStateException( "The test data could not be written fast enough for the test to be meaningful." );
            }

            // Verify result.
            waitUntilArchivingIsDone( archiver, 2 );

            assertFalse( archiver.store.isEmpty() );
            assertEquals( 1, archiver.getBatches().size() );
            final List<Integer> firstBatch = archiver.getBatches().get(0).data;
            assertEquals( 2, firstBatch.size() );
            assertEquals( 1, (long) firstBatch.get( 0 ) );
            assertEquals( 2, (long) firstBatch.get( 1 ) );
        }
        finally
        {
            // Teardown fixture.
            archiver.stop();
        }
    }
The archiver is expected to wait for a certain amount of time, before
writing data to the store (this is intended to allow the archiver to batch
work). This test verifies that two sets of data that are written to the
archiver within the 'grace period' are written in the same batch.
xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java