@Test(timeout = 20000)
public void testCancelOutput() throws Exception, JVoiceXMLEvent {

    final SsmlDocument doc1 = new SsmlDocument();
    final Speak speak1 = doc1.getSpeak();
    speak1.setXmlLang(Locale.US);
    speak1.addText("Test 1.Barge-in on.");
    final SpeakableSsmlText ssml1 = new SpeakableSsmlText(doc1, true,
            BargeInType.SPEECH);
    output.queueSpeakable(ssml1, sessionId, documentServer);
    LOGGER.info(ssml1.getSpeakableText() + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
    final SsmlDocument doc2 = new SsmlDocument();
    final Speak speak2 = doc2.getSpeak();
    speak2.setXmlLang(Locale.US);
    speak2.addText("Test 2.Barge-in on.");
    final SpeakableSsmlText ssml2 = new SpeakableSsmlText(doc2, true,
            BargeInType.SPEECH);
    output.queueSpeakable(ssml2, sessionId, documentServer);
    LOGGER.info(ssml2.getSpeakableText() + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
    SpeakableSsmlText plainText = new SpeakableSsmlText(
            "Test 3. Barge-in off.You can not skip this audio", Locale.US);
    output.queueSpeakable(plainText, sessionId, documentServer);
    LOGGER.info(plainText + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
    plainText = new SpeakableSsmlText(
            "Test 4.Barge-in off.You can not skip this audio", Locale.US);
    output.queueSpeakable(plainText, sessionId, documentServer);
    LOGGER.info(plainText + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
    final SsmlDocument doc3 = new SsmlDocument();
    final Speak speak3 = doc3.getSpeak();
    speak3.setXmlLang(Locale.US);
    speak3.addText("Test 5.Barge-in on. ");
    final SpeakableSsmlText ssml3 = new SpeakableSsmlText(doc3, true,
            BargeInType.SPEECH);
    output.queueSpeakable(ssml3, sessionId, documentServer);
    LOGGER.info(ssml3.getSpeakableText() + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
    plainText = new SpeakableSsmlText(
            "Test 6.Barge-in off.You can not skip this audio", Locale.US);
    output.queueSpeakable(plainText, sessionId, documentServer);
    LOGGER.info(plainText + " offered to queue");
    synchronized (outputStartedLock) {
        while (!outputStarted) {
            outputStartedLock.wait();
        }
    }
    Thread.sleep(DELAY);
    output.cancelOutput(BargeInType.SPEECH);
    synchronized (outputEndedLock) {
        while (!outputEnded) {
            outputEndedLock.wait();
        }
    }
}