.getXMLParser()
.parseAnalysisEngineDescription(
new XMLInputSource(
JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateWithSegmenterForErrorTest.xml")));
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(aggSegDesc);
CAS cas = ae.newCAS();
for (int i = 0; i < 2; i++) // verify we can do this more than once
{
FlowControllerForErrorTest.reset();
cas.setDocumentText("Line one\nLine two\nERROR");
CasIterator iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
CAS outCas = iter.next();
assertEquals("Line one", outCas.getDocumentText());
outCas.release();
assertTrue(iter.hasNext());
outCas = iter.next();
assertEquals("Line two", outCas.getDocumentText());
outCas.release();
try {
UIMAFramework.getLogger().setLevel(Level.OFF); // Suppress logging of expected exception
assertTrue(iter.hasNext());
outCas = iter.next();
fail(); // the above should throw an exception
} catch (AnalysisEngineProcessException e) {
UIMAFramework.getLogger().setLevel(Level.INFO); // Restore to apparent default of INFO
}
//check that FlowController was notified twice, once for the
//segment's flow and once for the complete document's flow
assertEquals(2, FlowControllerForErrorTest.abortedDocuments.size());
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("ERROR"));
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("Line one\nLine two\nERROR"));
cas.reset();
}
// nested aggregate
AnalysisEngineDescription nestedAggSegDesc = UIMAFramework
.getXMLParser()
.parseAnalysisEngineDescription(
new XMLInputSource(
JUnitExtension
.getFile("TextAnalysisEngineImplTest/NestedAggregateSegmenterForErrorTest.xml")));
ae = UIMAFramework.produceAnalysisEngine(nestedAggSegDesc);
cas = ae.newCAS();
for (int i = 0; i < 2; i++) // verify we can do this more than once
{
FlowControllerForErrorTest.reset();
cas.setDocumentText("Line one\nLine two\nERROR");
CasIterator iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
CAS outCas = iter.next();
assertEquals("Line one", outCas.getDocumentText());
outCas.release();
assertTrue(iter.hasNext());
outCas = iter.next();
assertEquals("Line two", outCas.getDocumentText());
outCas.release();
try {
UIMAFramework.getLogger().setLevel(Level.OFF); // Suppress logging of expected exception
assertTrue(iter.hasNext());
outCas = iter.next();
fail(); // the above should throw an exception
} catch (AnalysisEngineProcessException e) {
UIMAFramework.getLogger().setLevel(Level.INFO); // Restore to apparent default of INFO
}
//check that FlowController was notified three times, once for the
//segment's flow and twice for the complete document's flow (once
//in each aggregate)
assertEquals(3, FlowControllerForErrorTest.abortedDocuments.size());
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("ERROR"));
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("Line one\nLine two\nERROR"));
FlowControllerForErrorTest.abortedDocuments.remove("Line one\nLine two\nERROR");
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("Line one\nLine two\nERROR"));
cas.reset();
}
// 2 segmenters
AnalysisEngineDescription twoSegDesc = UIMAFramework
.getXMLParser()
.parseAnalysisEngineDescription(
new XMLInputSource(
JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateWith2SegmentersForErrorTest.xml")));
ae = UIMAFramework.produceAnalysisEngine(twoSegDesc);
cas = ae.newCAS();
for (int i = 0; i < 2; i++) // verify we can do this more than once
{
FlowControllerForErrorTest.abortedDocuments.clear();
cas.setDocumentText("One\tTwo\nThree\tERROR");
CasIterator iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
CAS outCas = iter.next();
assertEquals("One", outCas.getDocumentText());
outCas.release();
assertTrue(iter.hasNext());
outCas = iter.next();
assertEquals("Two", outCas.getDocumentText());
outCas.release();
assertTrue(iter.hasNext());
outCas = iter.next();
assertEquals("Three", outCas.getDocumentText());
outCas.release();
try {
UIMAFramework.getLogger().setLevel(Level.OFF); // Suppress logging of expected exception
assertTrue(iter.hasNext());
outCas = iter.next();
fail(); // the above should throw an exception
} catch (AnalysisEngineProcessException e) {
UIMAFramework.getLogger().setLevel(Level.INFO); // Restore to apparent default of INFO
}
//check that FlowController was notified three times, once for each level of granularity
assertEquals(3, FlowControllerForErrorTest.abortedDocuments.size());
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("ERROR"));
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("Three\tERROR"));
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("One\tTwo\nThree\tERROR"));
cas.reset();
}
// segmenter that requests too many CASes
AnalysisEngineDescription segmenterDesc = UIMAFramework.getXMLParser()
.parseAnalysisEngineDescription(
new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/BadSegmenter.xml")));
ae = UIMAFramework.produceAnalysisEngine(segmenterDesc);
cas = ae.newCAS();
cas.setDocumentText("Line one\nLine two\nLine three");
CasIterator iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
CAS outCas = iter.next(); // first call OK
outCas.release();
assertTrue(iter.hasNext());
// next call should fail with AnalysisEngineProcessException
try {
UIMAFramework.getLogger().setLevel(Level.OFF); // Suppress logging of expected exception
iter.next();
fail(); // should not get here
} catch (AnalysisEngineProcessException e) {
UIMAFramework.getLogger().setLevel(Level.INFO); // Restore to apparent default of INFO
}
// bad segmenter in an aggregate
AnalysisEngineDescription aggWithBadSegmenterDesc = UIMAFramework.getXMLParser()
.parseAnalysisEngineDescription(
new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateWithBadSegmenterForErrorTest.xml")));
ae = UIMAFramework.produceAnalysisEngine(aggWithBadSegmenterDesc);
FlowControllerForErrorTest.reset();
cas = ae.newCAS();
cas.setDocumentText("Line one\nLine two\nLine three");
iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
outCas = iter.next(); // first call OK
outCas.release();
assertTrue(FlowControllerForErrorTest.abortedDocuments.isEmpty());
assertTrue(FlowControllerForErrorTest.failedAEs.isEmpty());
// next call should fail with AnalysisEngineProcessException
try {
UIMAFramework.getLogger().setLevel(Level.OFF); // Suppress logging of expected exception
if (iter.hasNext()) {
iter.next();
}
fail(); // should not get here
} catch (AnalysisEngineProcessException e) {
UIMAFramework.getLogger().setLevel(Level.INFO); // Restore to apparent default of INFO
}
assertEquals(1, FlowControllerForErrorTest.abortedDocuments.size());
assertTrue(FlowControllerForErrorTest.abortedDocuments.contains("Line one\nLine two\nLine three"));
assertEquals(1,FlowControllerForErrorTest.failedAEs.size());
assertTrue(FlowControllerForErrorTest.failedAEs.contains("Segmenter"));
//configure AE to continue after error
ae = UIMAFramework.produceAnalysisEngine(aggWithBadSegmenterDesc);
ae.setConfigParameterValue("ContinueOnFailure", Boolean.TRUE);
ae.reconfigure();
FlowControllerForErrorTest.reset();
cas.reset();
cas.setDocumentText("Line one\nLine two\nLine three");
iter = ae.processAndOutputNewCASes(cas);
assertTrue(iter.hasNext());
outCas = iter.next(); // first call OK
outCas.release();
assertTrue(FlowControllerForErrorTest.abortedDocuments.isEmpty());
assertTrue(FlowControllerForErrorTest.failedAEs.isEmpty());