@Test
    public void testRangeDistributionBitDecrease1() throws ParseException {
        int db = 16;
        BucketIdFactory idFactory = new BucketIdFactory();
        ProgressToken p = new ProgressToken();

        VisitorIterator iter = VisitorIterator.createFromDocumentSelection(
                "id.group != \"yahoo.com\"", idFactory, db, p);

        VisitorIterator.DistributionRangeBucketSource src
                = (VisitorIterator.DistributionRangeBucketSource)iter.getBucketSource();

        assertTrue(src.isLosslessResetPossible());

        // For this test, have 3 finished buckets, 6 pending and 1 active
        // This gives a sibling "distribution" of FF FP PP PP PA. When all
        // active buckets have been updated, 3 merges should be triggered
        for (int i = 0; i < 3; ++i) {
            iter.update(iter.getNext().getSuperbucket(), ProgressToken.FINISHED_BUCKET);
        }

        assertFalse(src.isLosslessResetPossible());

        VisitorIterator.BucketProgress[] bpp = new VisitorIterator.BucketProgress[6];
        for (int i = 0; i < 6; ++i) {
            bpp[i] = iter.getNext();
        }
        VisitorIterator.BucketProgress bpa = iter.getNext(); // Leave this hanging as active
        for (int i = 0; i < 6; ++i) {
            iter.update(bpp[i].getSuperbucket(), new BucketId());
        }

        assertEquals(p.getBucketCursor(), 10);

        iter.setDistributionBitCount(db - 1);
        assertEquals(iter.getDistributionBitCount(), db - 1);
        assertEquals(p.getDistributionBitCount(), db);
        assertEquals(iter.getBucketSource().getDistributionBitCount(), db - 1);
        // The iterator is waiting patiently for all active buckets to be updated,
        // at which point it will performed the merging and actually updating the
        // progress token's distribution bit count
        assertTrue(iter.getBucketSource().shouldYield());
        assertFalse(iter.hasNext());
        assertFalse(iter.isDone());
        assertEquals(p.getActiveBucketCount(), 1);
        iter.update(bpa.getSuperbucket(), new BucketId());

        assertEquals(p.getDistributionBitCount(), db - 1);
        assertEquals(p.getActiveBucketCount(), 0);
        assertEquals(p.getPendingBucketCount(), 4); // 3 merges, P PP PP PP -> P P P P

        assertEquals(p.getFinishedBucketCount(), 1);
        assertEquals(p.getBucketCursor(), 5);
    }
Test increasing the distribution bits for a full bucket space range
source with no finished, active or pending buckets
@throws ParseException upon docsel parse failure (shouldn't happen)
documentapi/src/test/java/com/yahoo/documentapi/VisitorIteratorTestCase.java