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

        try
        {
            // Execute system under test.
            thread.start();
            archiver.archive( 1 );
            Thread.sleep( gracePeriod.toMillis() * 2 ); // Timing is affected by thread scheduling, etc. Waiting for _exactly_ 'grace period' often is not long enough for this test.
            archiver.archive( 2 );

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

            assertFalse( archiver.store.isEmpty() );
            assertEquals( 2, archiver.getBatches().size() );
            final List<Integer> firstBatch = archiver.getBatches().get(0).data;
            final List<Integer> secondBatch = archiver.getBatches().get(1).data;
            assertEquals( 1, firstBatch.size() );
            assertEquals( 1, (long) firstBatch.get( 0 ) );
            assertEquals( 1, secondBatch.size() );
            assertEquals( 2, (long) secondBatch.get( 0 ) );
        }
        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 different batches.
xmppserver/src/test/java/org/jivesoftware/openfire/archive/ArchiverTest.java