@Test
    public void testIterationSingleBucketUpdate() throws ParseException {
        BucketIdFactory idFactory = new BucketIdFactory();
        ProgressToken progress = new ProgressToken();

        VisitorIterator iter = VisitorIterator.createFromDocumentSelection(
                "id.user = 1234", idFactory, 1, progress);

        assertFalse(progress.hasActive());
        assertEquals(progress.getPendingBucketCount(), 1);
        assertEquals(progress.getFinishedBucketCount(), 0);
        assertEquals(progress.getTotalBucketCount(), 1);
        assertFalse(iter.isDone());
        assertTrue(iter.hasNext());
        assertEquals(iter.getRemainingBucketCount(), 1);
        VisitorIterator.BucketProgress b1 = iter.getNext();
        // Upon first getNext of a superbucket, progress == 0
        assertEquals(b1.getSuperbucket(), new BucketId(32, 1234));
        assertEquals(b1.getProgress(), new BucketId());
        assertFalse(iter.hasNext());
        assertFalse(iter.isDone());
        assertEquals(iter.getRemainingBucketCount(), 1);
        // Should only be one active bucket; the one we just got
        assertEquals(progress.getActiveBucketCount(), 1);
        // No pending yet
        assertFalse(progress.hasPending());
        // Update the bucket with a sub-bucket, moving it from active to pending
        BucketId sub = new BucketId(b1.getSuperbucket().getUsedBits() + 1, b1.getSuperbucket().getId());
        iter.update(b1.getSuperbucket(), sub);
        assertFalse(progress.hasActive());
        assertEquals(progress.getPendingBucketCount(), 1);
        assertTrue(iter.hasNext());
        assertFalse(iter.isDone());
        assertEquals(iter.getRemainingBucketCount(), 1);
        // Get the pending bucket
        VisitorIterator.BucketProgress b2 = iter.getNext();
        assertEquals(b2.getSuperbucket(), new BucketId(32, 1234));
        assertEquals(b2.getProgress(), new BucketId(33, 1234));
        assertFalse(iter.hasNext());
        assertEquals(progress.getActiveBucketCount(), 1);
        assertFalse(progress.hasPending());
        // Now update with progress==super, signalling that the bucket is done
        iter.update(b1.getSuperbucket(), ProgressToken.FINISHED_BUCKET);
        assertFalse(progress.hasActive());
        assertFalse(progress.hasPending());
        assertFalse(iter.hasNext());
        assertTrue(iter.isDone());
        assertTrue(progress.isFinished());
        assertEquals(progress.getFinishedBucketCount(), 1);
        assertEquals(iter.getRemainingBucketCount(), 0);
    }
Tests for VisitorIterator and ProgressToken (kept in one test case because their
interactions are so tightly coupled)

@author vekterli
documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java