@Test
    public void session_abort_rejects_subsequent_inbound_messages() {
        MockComponents mc = createDefaultMock("");
        mc.visitorSession.start();
        mc.executor.expectAndProcessTasks(1);
        assertEquals(2, mc.sender.getMessageCount()); // 1 distribution bit => 2 buckets visited

        mc.visitorSession.abort();
        assertFalse(mc.controlHandler.isDone()); // Aborting does not close the session before work has completed
        mc.receiver.send(new RemoveDocumentMessage(new DocumentId("id:ns:testdoc::bar")));
        mc.executor.expectAndProcessTasks(1);

        assertEquals("RemoveDocumentReply(APP_FATAL_ERROR: Visitor has been shut down)\n",
                     mc.receiver.repliesToString());

        assertFalse(mc.controlHandler.isDone()); // Still not done; has pending CreateVisitor requests
        replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET); // Super bucket 1 of 2
        replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET); // Super bucket 2 of 2
        mc.executor.expectAndProcessTasks(2);
        mc.executor.expectNoTasks();
        assertTrue(mc.controlHandler.isDone()); // Now done

    }
To avoid race conditions during session closure we must ensure that no further
inbound message callbacks will be executed once a session has been aborted
(be it explicitly or implicitly via a fatal failure or timeout).
documentapi/src/test/java/com/yahoo/documentapi/messagebus/MessageBusVisitorSessionTestCase.java