private void doTestEarlyCompletion(VisitorParameters visitorParameters,
                                       ReplyModifier replyModifier1,
                                       ReplyModifier replyModifier2)
    {
        MockComponents mc = createDefaultMock(visitorParameters);
        mc.controlHandler.resetMock();

        mc.visitorSession.start();
        mc.executor.expectAndProcessTasks(1);
        // First reply gives only 9 hits, so must send another visitor
        assertEquals("CreateVisitorMessage(buckets=[\n" +
                "BucketId(0x80000000000004d2)\n" +
                "BucketId(0x0000000000000000)\n" +
                "]\n" +
                "selection='id.user==1234'\n)",
                replyToCreateVisitor(mc.sender, replyModifier1));
        mc.executor.expectAndProcessTasks(1); // reply
        mc.executor.expectAndProcessTasks(1); // new visitor
        mc.controlHandler.resetMock();
        assertEquals(1, mc.sender.getMessageCount());
        assertEquals("CreateVisitorMessage(buckets=[\n" +
                "BucketId(0x80000000000004d2)\n" +
                "BucketId(0x84000001000004d2)\n" +
                "]\n" +
                "selection='id.user==1234'\n)",
                replyToCreateVisitor(mc.sender, replyModifier2));
        // we've now got enough total hits; session should be marked as
        // completed and no further visitors should be sent.
        mc.executor.expectAndProcessTasks(1); // reply
        mc.executor.expectNoTasks();
        assertEquals(0, mc.sender.getMessageCount());

        assertEquals("onProgress : 0 active, 1 pending, 0 finished, 1 total\n" +
                "onVisitorStatistics : 2 buckets visited, 10 docs returned\n" +
                "onDone : SUCCESS - ''\n", mc.controlHandler.toString());
        assertEquals("OK: ", mc.controlHandler.getResult().toString());
    }
Do not complete visiting upon fatal error until all replies have
been received.
documentapi/src/test/java/com/yahoo/documentapi/messagebus/MessageBusVisitorSessionTestCase.java