You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2006/11/22 17:44:00 UTC
svn commit: r478226 [30/32] - in /incubator/uima/uimaj/trunk/uimaj-cpe/src:
main/java/org/apache/uima/cas_data/impl/vinci/
main/java/org/apache/uima/collection/impl/
main/java/org/apache/uima/collection/impl/base_cpm/container/
main/java/org/apache/uim...
Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmCollectionReader_ErrorTests.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmCollectionReader_ErrorTests.java?view=diff&rev=478226&r1=478225&r2=478226
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmCollectionReader_ErrorTests.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmCollectionReader_ErrorTests.java Wed Nov 22 08:43:54 2006
@@ -43,23 +43,19 @@
*
* <p>
* The TestCase aims to test the important methods normally used within the CollectionReader
- * (initialize, getNext, hasNext and getProgress). In each function different Exceptions are thrown to test
- * the behaviour of the system in such a situation.
+ * (initialize, getNext, hasNext and getProgress). In each function different Exceptions are thrown
+ * to test the behaviour of the system in such a situation.
* </p>
* <p>
- * To offer a short introduction into the generell mode of operation have a look at the following list:
+ * To offer a short introduction into the generell mode of operation have a look at the following
+ * list:
* </p>
* <ul>
- * <li>
- * generate the descriptors, with fit to the testcase. For instance a
- * CollectionReader which throws a (runtime) exception every 5th document.
- * </li>
- * <li>
- * [optional] add some mechanism to handle errors in the tests (timeouts or try-catch blocks)
- * </li>
- * <li>
- * run the test and check for the results
- * </li>
+ * <li> generate the descriptors, with fit to the testcase. For instance a CollectionReader which
+ * throws a (runtime) exception every 5th document. </li>
+ * <li> [optional] add some mechanism to handle errors in the tests (timeouts or try-catch blocks)
+ * </li>
+ * <li> run the test and check for the results </li>
* </ul>
*
* Also have a look at <br>
@@ -69,718 +65,692 @@
*/
public class CpmCollectionReader_ErrorTests extends TestCase {
- private static final String FS =
- System.getProperties().getProperty("file.separator");
+ private static final String FS = System.getProperties().getProperty("file.separator");
- private String junitTestBasePath;
+ private String junitTestBasePath;
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- //get test base path setting
- junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
- }
-
- /**
- * <b>testcase:</b> the getNext method throws an OutOfMemoryError.<br>
- * <b>expected behaviour:</b><br>
- * The cpm notify the entityProcessComplete methode of the listener and
- * propagate the error in the EntityProcessStatus. After that, the cpm is
- * shut down and the abort methode is called.
- *
- * @throws Exception
- */
- public void testGetNextWithOutOfMemoryError() throws Exception {
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 5; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "OutOfMemoryError",
- exceptionSequence,
- "getNext");
-
- //Create and register a Status Callback Listener
- CollectionReaderStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
- ManageOutputDevice.setAllSystemOutputToDefault();
- assertEquals("Abort was not called as expected.", true, listener.isAborted());
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- checkForOutOfMemoryError(listener);
- }
-
- /**
- * <b>testcase:</b> the getNext method throws multiple CollectionExceptions.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
- * of the listener was called
- *
- * @throws Exception
- */
- public void testGetNextWithCollectionException() throws Exception {
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 2; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "CollectionException",
- exceptionSequence,
- "getNext");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm is still working or the collectionProcessComplete-method of the listener was not called.", true, listener.isFinished());
- assertEquals("The cpm propably didn't finish correctly! The aborted method of the listener was called.", false, listener.isAborted());
- assertEquals("There are not as much exceptions as expected! ", documentCount / exceptionSequence, FunctionErrorStore.getCount());
- }
-
- /**
- * <b>testcase:</b> the getNext method throws multiple IOExceptions.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
- * of the listener was called
- *
- * @throws Exception
- */
- public void testGetNextWithIOException() throws Exception{
- int TIMEOUT = 10; // seconds, till the test is aborted
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 3; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "IOException",
- exceptionSequence,
- "getNext");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- Date d = new Date();
- long time = d.getTime() + 1000 * TIMEOUT;
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- d = new Date();
- // timeout mechanism
- if (time < d.getTime()) {
- System.out.println("CPM manually aborted!");
- cpe.stop();
- //wait until CPM has aborted
- while (!listener.isAborted())
- {
- Thread.sleep(5);
- }
- }
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm is still working or the collectionProcessComplete-method of the listener was not called.", true, listener.isFinished());
- assertEquals("The cpm propably didn't finish correctly! The aborted method of the listener was called.", false, listener.isAborted());
- assertEquals("There are not as much exceptions as expected! ", documentCount / exceptionSequence, FunctionErrorStore.getCount());
- }
-
- /**
- * <b>testcase:</b> the getNext method throws multiple NullPointerExceptions.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
- * of the listener was called
- *
- * @throws Exception
- */
- public void testGetNextWithNullPointerException() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 2; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "NullPointerException",
- exceptionSequence,
- "getNext");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm is still working or the collectionProcessComplete-method of the listener was not called.", true, listener.isFinished());
- assertEquals("The cpm propably didn't finish correctly! The aborted method of the listener was called.", false, listener.isAborted());
- assertEquals("There are not as much exceptions as expected! ", documentCount / exceptionSequence, FunctionErrorStore.getCount());
- }
-
- /**
- * <b>testcase:</b> the hasNext method throws a OutOfMemoryError.<br>
- * <b>expected behaviour:</b><br>
- * The cpm notifies the entityProcessComplete methode of the listener and
- * propagate the error in the EntityProcessStatus. After that, the cpm is
- * shut down and the abort methode is called.
- *
- * @throws Exception
- */
- public void testHasNextWithOutOfMemoryError() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 4; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "OutOfMemoryError",
- exceptionSequence,
- "hasNext");
-
- //Create and register a Status Callback Listener
- CollectionReaderStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
- assertEquals("Abort was not called.", true, listener.isAborted());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- checkForOutOfMemoryError(listener);
- }
- /**
- * <b>testcase:</b> the hasNext method throws a NullPointerException.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should automatically finish. No error should be reported and the
- * finished methode
- *
- * @throws Exception
- */
- public void testHasNextWithNullPointerException() throws Exception{
- int TIMEOUT = 20; // seconds, till the test is aborted
- int documentCount = 30; // number of documents processed
- int exceptionSequence = 4; // the sequence in which errors are produced
- boolean manuallyAborted = false; // flag, if we shut down the cpm by hand.
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "NullPointerException",
- exceptionSequence,
- "hasNext");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- Date d = new Date();
- long time = d.getTime() + 1000 * TIMEOUT;
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- d = new Date();
- // timeout mechanism
- if (time < d.getTime()) {
- manuallyAborted = true;
- cpe.stop();
- //wait until CPM has aborted
- while (!listener.isAborted())
- {
- Thread.sleep(5);
- }
- }
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm didn't finish correctly! Abort was called.", false, listener.isAborted());
- assertEquals("The cpm didn't finish correctly! Finish was not called.", true, listener.isFinished());
- assertEquals("The cpm was manually aborted.", false, manuallyAborted);
- }
-
- /**
- * <b>testcase:</b> the hasNext method throws a ResourceInitializationException.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should not finish. An exception is thrown to the callerclass.
- *
- * @throws Exception
- */
- public void testInitializeWithResourceInitializationException() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 1; // the sequence in which errors are produced
- TestStatusCallbackListener listener = null; // listener with which the statusinformation are made avaiable
- boolean exceptionThrown = false; // flag, if the expected exception was thrown
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- try {
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "ResourceInitializationException",
- exceptionSequence,
- "initialize");
-
- //Create and register a Status Callback Listener
- listener = new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
-
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
- } catch (ResourceInitializationException e) {
- exceptionThrown = true;
- } finally{
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The cpm didn't finish correctly! Abort was called.", false, listener.isAborted());
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- assertEquals("The expected ResourceInitializationException was not fiven back to the programm. ", true, exceptionThrown);
- // that's it.
- }
- }
-
- /**
- * <b>testcase:</b> the initialize method throws a NullPointerException.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should not finish. An exception is thrown to the callerclass.
- *
- * @throws Exception
- */
- public void testInitializeWithNullPointerException() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 1; // the sequence in which errors are produced
- boolean exceptionThrown = false; // flag, if the expected exception was thrown
- ManageOutputDevice.setAllSystemOutputToNirvana();
- TestStatusCallbackListener listener = null;
-
- try {
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "NullPointerException",
- exceptionSequence,
- "initialize");
-
- //Create and register a Status Callback Listener
- listener = new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
- } catch (ResourceInitializationException e) {
- //e.printStackTrace();
- exceptionThrown = true;
- } finally {
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("Abort was called.", false, listener.isAborted());
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- assertEquals("The expected ResourceInitializationException was not fiven back to the programm. ", true, exceptionThrown);
- }
- }
-
- /**
- * <b>testcase:</b> the initialize method throws a OutOfMemoryError.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should not finish correctly. An exception is thrown to the callerclass.
- *
- * @throws Exception
- */
- public void testInitializeWithOutOfMemoryError() throws Exception{
- boolean outOfMemoryError = false;
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 1; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
- CollectionReaderStatusCallbackListener listener = null; // listener with which the statusinformation are made avaiable
-
- try{
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "OutOfMemoryError",
- exceptionSequence,
- "initialize");
-
- //Create and register a Status Callback Listener
- listener = new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
- }catch(OutOfMemoryError e){
- outOfMemoryError = true;
- }finally{
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("The OutOfMemoryError is not given back to the caller.", true, outOfMemoryError);
- assertEquals("Abort was called.", false, listener.isAborted());
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- }
-
- }
-
- /**
- * <b>testcase:</b> the getProgress method throws multiple IOExceptions.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
- * of the listener was called
- *
- * @throws Exception
- */
- public void testGetProgressWithIOException() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 3; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "IOException",
- exceptionSequence,
- "getProgress");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("Abort was called.", false, listener.isAborted());
- assertEquals("The cpm is still working or the collectionProcessComplete-method of the listener was not called.", true, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", (documentCount/exceptionSequence), FunctionErrorStore.getCount());
- // that's it.
- }
-
- /**
- * <b>testcase:</b> the getProgress method throws one OutOfMemoryError.<br>
- * <b>expected behaviour:</b><br>
- * The cpm notifies the entityProcessComplete methode of the listener and
- * propagate the error in the EntityProcessStatus. After that, the cpm is
- * shut down and the abort methode is called.
- *
- * @throws Exception
- */
- public void testGetProcessWithOutOfMemoryError() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 3; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "OutOfMemoryError",
- exceptionSequence,
- "getProgress");
-
- //Create and register a Status Callback Listener
- CollectionReaderStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("Abort was not called.", true, listener.isAborted());
- assertEquals("The collectionProcessComplete-method of the listener was called. - Unexpected!", false, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- checkForOutOfMemoryError(listener);
- }
-
- /**
- * <b>testcase:</b> the getProgress method throws multiple NullPointerExceptions.<br>
- * <b>expected behaviour:</b><br>
- * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
- * of the listener was called
- *
- * @throws Exception
- */
- public void testGetProgressWithNullPointerException() throws Exception{
- int documentCount = 20; // number of documents processed
- int exceptionSequence = 3; // the sequence in which errors are produced
- ManageOutputDevice.setAllSystemOutputToNirvana();
-
- //setup CPM
- CollectionProcessingEngine cpe =
- setupCpm(
- documentCount,
- "NullPointerException",
- exceptionSequence,
- "getProgress");
-
- //Create and register a Status Callback Listener
- TestStatusCallbackListener listener =
- new CollectionReaderStatusCallbackListener(cpe);
- cpe.addStatusCallbackListener(listener);
-
- cpe.process();
-
- //wait until cpm has finished
- while (!listener.isFinished() && !listener.isAborted()) {
- Thread.sleep(5);
- }
-
- ManageOutputDevice.setAllSystemOutputToDefault();
- // check the results, if everything worked as expected
- assertEquals("Abort was called.", false, listener.isAborted());
- assertEquals("The cpm is still working or the collectionProcessComplete-method of the listener was not called.", true, listener.isFinished());
- assertEquals("There are not as much exceptions as expected! ", (documentCount/exceptionSequence), FunctionErrorStore.getCount());
-
- }
-
-// INFO: the close -methode could not be invoked by an external action
-// public void testCloseWithNullPointerException() throws Exception{
-// int TIMEOUT = 15; // seconds, till the test is aborted
-// int documentCount = 20; // number of documents processed
-// int exceptionSequence = 1; // the sequence in which errors are produced
-//
-// //setup CPM
-// CollectionProcessingEngine cpe =
-// setupCpm(
-// documentCount,
-// "NullPointerException",
-// exceptionSequence,
-// "close");
-//
-// //Create and register a Status Callback Listener
-// TestStatusCallbackListener listener =
-// new CollectionReaderStatusCallbackListener(cpe);
-// cpe.addStatusCallbackListener(listener);
-//
-// cpe.process();
-//
-// //wait until cpm has finished
-// while (!listener.isFinished() && !listener.isAborted()) {
-// Thread.sleep(5);
-//
-// }
-// // check the results, if everything worked as expected
-// assertEquals("The cpm didn't finish correctly! Abort was called.", false, listener.isAborted());
-// assertEquals("The cpm didn't should down correctly", true, listener.isFinished());
-// assertEquals("The cpm crashed.", false, manuallyAborted);
-// assertEquals("No Exception should be thrown!", 0, FunctionErrorStore.getCount());
-// // that's it.
-// }
-
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- FunctionErrorStore.resetCount();
- System.gc();
- System.gc();
- }
-
- private void checkForOutOfMemoryError(CollectionReaderStatusCallbackListener listener){
- assertEquals("The indication failed, that an error was thrown.", true, listener.isAborted());
- assertEquals("No Error was thrown (and no Exception) - expected was an OutOfMemoryError.", true, listener.hasError());
- assertEquals("The expected null for the failed cas is missing.", true, (listener.getLastCas() == null));
- assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
- assertEquals("The cpm called the listener, that the cpm has finished - which normally could not be.", false, listener.isFinished());
-
- }
-
- /**
- * setup the CPM with base functionality.
- *
- * @param documentCount how many documents should be processed
- * @param exceptionName the exception to be thrown
- * @param exceptionSequence the iteration rate of the exceptions
- * @param functionName the name of the function/method that throws the exception
- *
- * @return CollectionProcessingEngine - initialized cpe
- */
- private CollectionProcessingEngine setupCpm(
- int documentCount,
- String exceptionName,
- int exceptionSequence,
- String functionName) {
- CpeDescription cpeDesc = null;
- CollectionProcessingEngine cpe = null;
-
- try {
- String colReaderBase =
- junitTestBasePath
- + "CpmTests"
- + FS
- + "ErrorTestCollectionReader.xml";
- String taeBase =
- junitTestBasePath + "CpmTests" + FS + "ErrorTestAnnotator.xml";
- String casConsumerBase =
- junitTestBasePath + "CpmTests" + FS + "ErrorTestCasConsumer.xml";
-
- // first, prepare all descriptors as needed
- String colReaderDesc =
- DescriptorMakeUtil.makeCollectionReader(
- colReaderBase,
- true,
- functionName,
- exceptionSequence,
- exceptionName,
- documentCount);
- String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
- String casConsumerDesc =
- DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
-
- // secondly, create the cpm based on the descriptors
- cpeDesc = CpeDescriptorFactory.produceDescriptor();
-
- // managing the default behaviour of this client
- CpeIntegratedCasProcessor integratedProcessor =
- CpeDescriptorFactory.produceCasProcessor("ErrorTestAnnotator");
- integratedProcessor.setDescriptor(taeDesc);
-
- CpeIntegratedCasProcessor casConsumer =
- CpeDescriptorFactory.produceCasProcessor("ErrorTest CasConsumer");
- casConsumer.setDescriptor(casConsumerDesc);
-
- // - add all descriptors
- cpeDesc.addCollectionReader(colReaderDesc);
- cpeDesc.addCasProcessor(integratedProcessor);
- cpeDesc.addCasProcessor(casConsumer);
- cpeDesc.setInputQueueSize(2);
- cpeDesc.setOutputQueueSize(2);
- cpeDesc.setProcessingUnitThreadCount(1);
- // - Create a new CPE
- cpe =
- UIMAFramework.produceCollectionProcessingEngine(
- cpeDesc,
- null,
- null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return cpe;
- }
-
- class CollectionReaderStatusCallbackListener
- extends TestStatusCallbackListener {
- protected CollectionProcessingEngine cpe = null;
- private boolean errorThrown = false; // indicates, if the OutOfMemoryError is thrown
-
- public CollectionReaderStatusCallbackListener(CollectionProcessingEngine cpe) {
- this.cpe = cpe;
- }
-
- /**
- * @see org.apache.uima.collection.base_cpm.BaseStatusCallbackListener#aborted()
- */
- public void aborted() {
- super.aborted();
- //System.out.println("abort was called.");
- cpe.stop();
- }
-
- /**
- * This methode is modified, to react on OutOfMemoryErrors in the correct way.
- *
- * @see org.apache.uima.collection.StatusCallbackListener#entityProcessComplete(org.apache.uima.cas.CAS, org.apache.uima.collection.EntityProcessStatus)
- */
- public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
- super.entityProcessComplete(aCas, aStatus);
- // check for a failure in processing...
- if(aStatus.getStatusMessage().equals("failed")){
- Iterator iter = aStatus.getExceptions().iterator();
- while(iter.hasNext()){
- // if there is an error ... call the cpm to kill and check for a null CAS
- if(iter.next() instanceof java.lang.Error){
- cpe.kill();
- errorThrown = true;
- assertEquals("The cas is not null, as expected.", null, aCas);
- }
- }
- }
- }
-
- public boolean hasError(){
- return errorThrown;
- }
- }
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ // get test base path setting
+ junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
+ }
+
+ /**
+ * <b>testcase:</b> the getNext method throws an OutOfMemoryError.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm notify the entityProcessComplete methode of the listener and propagate the error in the
+ * EntityProcessStatus. After that, the cpm is shut down and the abort methode is called.
+ *
+ * @throws Exception
+ */
+ public void testGetNextWithOutOfMemoryError() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 5; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "OutOfMemoryError", exceptionSequence,
+ "getNext");
+
+ // Create and register a Status Callback Listener
+ CollectionReaderStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(
+ cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ assertEquals("Abort was not called as expected.", true, listener.isAborted());
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
+ checkForOutOfMemoryError(listener);
+ }
+
+ /**
+ * <b>testcase:</b> the getNext method throws multiple CollectionExceptions.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
+ * of the listener was called
+ *
+ * @throws Exception
+ */
+ public void testGetNextWithCollectionException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 2; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "CollectionException",
+ exceptionSequence, "getNext");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals(
+ "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
+ true, listener.isFinished());
+ assertEquals(
+ "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
+ false, listener.isAborted());
+ assertEquals("There are not as much exceptions as expected! ", documentCount
+ / exceptionSequence, FunctionErrorStore.getCount());
+ }
+
+ /**
+ * <b>testcase:</b> the getNext method throws multiple IOExceptions.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
+ * of the listener was called
+ *
+ * @throws Exception
+ */
+ public void testGetNextWithIOException() throws Exception {
+ int TIMEOUT = 10; // seconds, till the test is aborted
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 3; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "IOException", exceptionSequence,
+ "getNext");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ Date d = new Date();
+ long time = d.getTime() + 1000 * TIMEOUT;
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ d = new Date();
+ // timeout mechanism
+ if (time < d.getTime()) {
+ System.out.println("CPM manually aborted!");
+ cpe.stop();
+ // wait until CPM has aborted
+ while (!listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ }
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals(
+ "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
+ true, listener.isFinished());
+ assertEquals(
+ "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
+ false, listener.isAborted());
+ assertEquals("There are not as much exceptions as expected! ", documentCount
+ / exceptionSequence, FunctionErrorStore.getCount());
+ }
+
+ /**
+ * <b>testcase:</b> the getNext method throws multiple NullPointerExceptions.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
+ * of the listener was called
+ *
+ * @throws Exception
+ */
+ public void testGetNextWithNullPointerException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 2; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
+ exceptionSequence, "getNext");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals(
+ "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
+ true, listener.isFinished());
+ assertEquals(
+ "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
+ false, listener.isAborted());
+ assertEquals("There are not as much exceptions as expected! ", documentCount
+ / exceptionSequence, FunctionErrorStore.getCount());
+ }
+
+ /**
+ * <b>testcase:</b> the hasNext method throws a OutOfMemoryError.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm notifies the entityProcessComplete methode of the listener and propagate the error in
+ * the EntityProcessStatus. After that, the cpm is shut down and the abort methode is called.
+ *
+ * @throws Exception
+ */
+ public void testHasNextWithOutOfMemoryError() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 4; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "OutOfMemoryError", exceptionSequence,
+ "hasNext");
+
+ // Create and register a Status Callback Listener
+ CollectionReaderStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(
+ cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+ assertEquals("Abort was not called.", true, listener.isAborted());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
+ checkForOutOfMemoryError(listener);
+ }
+
+ /**
+ * <b>testcase:</b> the hasNext method throws a NullPointerException.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should automatically finish. No error should be reported and the finished methode
+ *
+ * @throws Exception
+ */
+ public void testHasNextWithNullPointerException() throws Exception {
+ int TIMEOUT = 20; // seconds, till the test is aborted
+ int documentCount = 30; // number of documents processed
+ int exceptionSequence = 4; // the sequence in which errors are produced
+ boolean manuallyAborted = false; // flag, if we shut down the cpm by hand.
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
+ exceptionSequence, "hasNext");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ Date d = new Date();
+ long time = d.getTime() + 1000 * TIMEOUT;
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ d = new Date();
+ // timeout mechanism
+ if (time < d.getTime()) {
+ manuallyAborted = true;
+ cpe.stop();
+ // wait until CPM has aborted
+ while (!listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ }
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("The cpm didn't finish correctly! Abort was called.", false, listener.isAborted());
+ assertEquals("The cpm didn't finish correctly! Finish was not called.", true, listener
+ .isFinished());
+ assertEquals("The cpm was manually aborted.", false, manuallyAborted);
+ }
+
+ /**
+ * <b>testcase:</b> the hasNext method throws a ResourceInitializationException.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should not finish. An exception is thrown to the callerclass.
+ *
+ * @throws Exception
+ */
+ public void testInitializeWithResourceInitializationException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 1; // the sequence in which errors are produced
+ TestStatusCallbackListener listener = null; // listener with which the statusinformation are
+ // made avaiable
+ boolean exceptionThrown = false; // flag, if the expected exception was thrown
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ try {
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "ResourceInitializationException",
+ exceptionSequence, "initialize");
+
+ // Create and register a Status Callback Listener
+ listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ } catch (ResourceInitializationException e) {
+ exceptionThrown = true;
+ } finally {
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("The cpm didn't finish correctly! Abort was called.", false, listener
+ .isAborted());
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
+ .getCount());
+ assertEquals(
+ "The expected ResourceInitializationException was not fiven back to the programm. ",
+ true, exceptionThrown);
+ // that's it.
+ }
+ }
+
+ /**
+ * <b>testcase:</b> the initialize method throws a NullPointerException.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should not finish. An exception is thrown to the callerclass.
+ *
+ * @throws Exception
+ */
+ public void testInitializeWithNullPointerException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 1; // the sequence in which errors are produced
+ boolean exceptionThrown = false; // flag, if the expected exception was thrown
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+ TestStatusCallbackListener listener = null;
+
+ try {
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
+ exceptionSequence, "initialize");
+
+ // Create and register a Status Callback Listener
+ listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ } catch (ResourceInitializationException e) {
+ // e.printStackTrace();
+ exceptionThrown = true;
+ } finally {
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("Abort was called.", false, listener.isAborted());
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
+ .getCount());
+ assertEquals(
+ "The expected ResourceInitializationException was not fiven back to the programm. ",
+ true, exceptionThrown);
+ }
+ }
+
+ /**
+ * <b>testcase:</b> the initialize method throws a OutOfMemoryError.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should not finish correctly. An exception is thrown to the callerclass.
+ *
+ * @throws Exception
+ */
+ public void testInitializeWithOutOfMemoryError() throws Exception {
+ boolean outOfMemoryError = false;
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 1; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+ CollectionReaderStatusCallbackListener listener = null; // listener with which the
+ // statusinformation are made avaiable
+
+ try {
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "OutOfMemoryError",
+ exceptionSequence, "initialize");
+
+ // Create and register a Status Callback Listener
+ listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ } catch (OutOfMemoryError e) {
+ outOfMemoryError = true;
+ } finally {
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("The OutOfMemoryError is not given back to the caller.", true, outOfMemoryError);
+ assertEquals("Abort was called.", false, listener.isAborted());
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
+ .getCount());
+ }
+
+ }
+
+ /**
+ * <b>testcase:</b> the getProgress method throws multiple IOExceptions.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
+ * of the listener was called
+ *
+ * @throws Exception
+ */
+ public void testGetProgressWithIOException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 3; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "IOException", exceptionSequence,
+ "getProgress");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("Abort was called.", false, listener.isAborted());
+ assertEquals(
+ "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
+ true, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ",
+ (documentCount / exceptionSequence), FunctionErrorStore.getCount());
+ // that's it.
+ }
+
+ /**
+ * <b>testcase:</b> the getProgress method throws one OutOfMemoryError.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm notifies the entityProcessComplete methode of the listener and propagate the error in
+ * the EntityProcessStatus. After that, the cpm is shut down and the abort methode is called.
+ *
+ * @throws Exception
+ */
+ public void testGetProcessWithOutOfMemoryError() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 3; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "OutOfMemoryError", exceptionSequence,
+ "getProgress");
+
+ // Create and register a Status Callback Listener
+ CollectionReaderStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(
+ cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("Abort was not called.", true, listener.isAborted());
+ assertEquals("The collectionProcessComplete-method of the listener was called. - Unexpected!",
+ false, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
+ checkForOutOfMemoryError(listener);
+ }
+
+ /**
+ * <b>testcase:</b> the getProgress method throws multiple NullPointerExceptions.<br>
+ * <b>expected behaviour:</b><br>
+ * The cpm should finish. The cpm by itself is shut down, and the collectionProcessComplete-method
+ * of the listener was called
+ *
+ * @throws Exception
+ */
+ public void testGetProgressWithNullPointerException() throws Exception {
+ int documentCount = 20; // number of documents processed
+ int exceptionSequence = 3; // the sequence in which errors are produced
+ ManageOutputDevice.setAllSystemOutputToNirvana();
+
+ // setup CPM
+ CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
+ exceptionSequence, "getProgress");
+
+ // Create and register a Status Callback Listener
+ TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
+ cpe.addStatusCallbackListener(listener);
+
+ cpe.process();
+
+ // wait until cpm has finished
+ while (!listener.isFinished() && !listener.isAborted()) {
+ Thread.sleep(5);
+ }
+
+ ManageOutputDevice.setAllSystemOutputToDefault();
+ // check the results, if everything worked as expected
+ assertEquals("Abort was called.", false, listener.isAborted());
+ assertEquals(
+ "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
+ true, listener.isFinished());
+ assertEquals("There are not as much exceptions as expected! ",
+ (documentCount / exceptionSequence), FunctionErrorStore.getCount());
+
+ }
+
+ // INFO: the close -methode could not be invoked by an external action
+ // public void testCloseWithNullPointerException() throws Exception{
+ // int TIMEOUT = 15; // seconds, till the test is aborted
+ // int documentCount = 20; // number of documents processed
+ // int exceptionSequence = 1; // the sequence in which errors are produced
+ //
+ // //setup CPM
+ // CollectionProcessingEngine cpe =
+ // setupCpm(
+ // documentCount,
+ // "NullPointerException",
+ // exceptionSequence,
+ // "close");
+ //
+ // //Create and register a Status Callback Listener
+ // TestStatusCallbackListener listener =
+ // new CollectionReaderStatusCallbackListener(cpe);
+ // cpe.addStatusCallbackListener(listener);
+ //
+ // cpe.process();
+ //
+ // //wait until cpm has finished
+ // while (!listener.isFinished() && !listener.isAborted()) {
+ // Thread.sleep(5);
+ //
+ // }
+ // // check the results, if everything worked as expected
+ // assertEquals("The cpm didn't finish correctly! Abort was called.", false,
+ // listener.isAborted());
+ // assertEquals("The cpm didn't should down correctly", true, listener.isFinished());
+ // assertEquals("The cpm crashed.", false, manuallyAborted);
+ // assertEquals("No Exception should be thrown!", 0, FunctionErrorStore.getCount());
+ // // that's it.
+ // }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FunctionErrorStore.resetCount();
+ System.gc();
+ System.gc();
+ }
+
+ private void checkForOutOfMemoryError(CollectionReaderStatusCallbackListener listener) {
+ assertEquals("The indication failed, that an error was thrown.", true, listener.isAborted());
+ assertEquals("No Error was thrown (and no Exception) - expected was an OutOfMemoryError.",
+ true, listener.hasError());
+ assertEquals("The expected null for the failed cas is missing.", true,
+ (listener.getLastCas() == null));
+ assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore.getCount());
+ assertEquals(
+ "The cpm called the listener, that the cpm has finished - which normally could not be.",
+ false, listener.isFinished());
+
+ }
+
+ /**
+ * setup the CPM with base functionality.
+ *
+ * @param documentCount
+ * how many documents should be processed
+ * @param exceptionName
+ * the exception to be thrown
+ * @param exceptionSequence
+ * the iteration rate of the exceptions
+ * @param functionName
+ * the name of the function/method that throws the exception
+ *
+ * @return CollectionProcessingEngine - initialized cpe
+ */
+ private CollectionProcessingEngine setupCpm(int documentCount, String exceptionName,
+ int exceptionSequence, String functionName) {
+ CpeDescription cpeDesc = null;
+ CollectionProcessingEngine cpe = null;
+
+ try {
+ String colReaderBase = junitTestBasePath + "CpmTests" + FS + "ErrorTestCollectionReader.xml";
+ String taeBase = junitTestBasePath + "CpmTests" + FS + "ErrorTestAnnotator.xml";
+ String casConsumerBase = junitTestBasePath + "CpmTests" + FS + "ErrorTestCasConsumer.xml";
+
+ // first, prepare all descriptors as needed
+ String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, true,
+ functionName, exceptionSequence, exceptionName, documentCount);
+ String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
+ String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
+
+ // secondly, create the cpm based on the descriptors
+ cpeDesc = CpeDescriptorFactory.produceDescriptor();
+
+ // managing the default behaviour of this client
+ CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTestAnnotator");
+ integratedProcessor.setDescriptor(taeDesc);
+
+ CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTest CasConsumer");
+ casConsumer.setDescriptor(casConsumerDesc);
+
+ // - add all descriptors
+ cpeDesc.addCollectionReader(colReaderDesc);
+ cpeDesc.addCasProcessor(integratedProcessor);
+ cpeDesc.addCasProcessor(casConsumer);
+ cpeDesc.setInputQueueSize(2);
+ cpeDesc.setOutputQueueSize(2);
+ cpeDesc.setProcessingUnitThreadCount(1);
+ // - Create a new CPE
+ cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return cpe;
+ }
+
+ class CollectionReaderStatusCallbackListener extends TestStatusCallbackListener {
+ protected CollectionProcessingEngine cpe = null;
+
+ private boolean errorThrown = false; // indicates, if the OutOfMemoryError is thrown
+
+ public CollectionReaderStatusCallbackListener(CollectionProcessingEngine cpe) {
+ this.cpe = cpe;
+ }
+
+ /**
+ * @see org.apache.uima.collection.base_cpm.BaseStatusCallbackListener#aborted()
+ */
+ public void aborted() {
+ super.aborted();
+ // System.out.println("abort was called.");
+ cpe.stop();
+ }
+
+ /**
+ * This methode is modified, to react on OutOfMemoryErrors in the correct way.
+ *
+ * @see org.apache.uima.collection.StatusCallbackListener#entityProcessComplete(org.apache.uima.cas.CAS,
+ * org.apache.uima.collection.EntityProcessStatus)
+ */
+ public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
+ super.entityProcessComplete(aCas, aStatus);
+ // check for a failure in processing...
+ if (aStatus.getStatusMessage().equals("failed")) {
+ Iterator iter = aStatus.getExceptions().iterator();
+ while (iter.hasNext()) {
+ // if there is an error ... call the cpm to kill and check for a null CAS
+ if (iter.next() instanceof java.lang.Error) {
+ cpe.kill();
+ errorThrown = true;
+ assertEquals("The cas is not null, as expected.", null, aCas);
+ }
+ }
+ }
+ }
+
+ public boolean hasError() {
+ return errorThrown;
+ }
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmInitTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmInitTest.java?view=diff&rev=478226&r1=478225&r2=478226
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmInitTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmInitTest.java Wed Nov 22 08:43:54 2006
@@ -31,194 +31,188 @@
import org.apache.uima.collection.metadata.CpeIntegratedCasProcessor;
import org.apache.uima.test.junit_extension.TestPropertyReader;
-public class CpmInitTest extends TestCase
-{
- private static final String separator = System.getProperties().getProperty("file.separator");
-
- private static String junitTestBasePath;
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception
- {
- //get test base path setting
- junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
- }
-
- /**
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception
- {
- super.tearDown();
- FunctionErrorStore.resetCount();
- }
-
- public void testInitSingleThreadCPMMode() throws Exception
- {
- int documentCount = 10000;
- int threadCount = 1;
-
- //setup CPM to process 1 documents
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, true);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- // wait for initialized call from the CPM
- while(!listener.isInitialized()) {
- Thread.sleep(10);
- }
- System.out.println("Initialize was called: " + listener.isInitialized());
-
- // Let the CPM process some docs, before calling stop
- Thread.sleep(500);
-
- //stop CPM
- cpe.stop();
-
- //wait until CPM has aborted
- while (!listener.isAborted())
- {
- Thread.sleep(5);
- }
- }
+public class CpmInitTest extends TestCase {
+ private static final String separator = System.getProperties().getProperty("file.separator");
- public void testInitMultiThreadCPMMode() throws Exception
- {
- int documentCount = 10000; //hopefully enough that we won't finish before we abort
- int threadCount = 1;
-
- //setup CPM to process 1 documents
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, false);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- while(!listener.isInitialized()) {
- Thread.sleep(10);
- }
- System.out.println("Initialize was called: " + listener.isInitialized());
-
- // Let the CPM process some docs, before calling stop
- Thread.sleep(500);
-
- //stop CPM
- cpe.stop();
-
- //wait until CPM has aborted
- while (!listener.isAborted())
- {
- Thread.sleep(5);
- }
- }
-
- public void testInitMultiThreadCPM() throws Exception
- {
- int documentCount = 10000;
- int threadCount = 3;
-
- //setup CPM to process documents
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, false);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
-
- while(!listener.isInitialized()) {
- Thread.sleep(10);
- }
- System.out.println("testInitMultiThreadCPM()-Initialize was called: " + listener.isInitialized());
- // Let the CPM process some docs, before calling stop
- Thread.sleep(500);
-
- //stop CPM
- cpe.stop();
-
- //wait until CPM has aborted
- while (!listener.isAborted())
- {
- Thread.sleep(5);
- }
- }
-
-
- /**
- * setup the CPM with base functionality.
- *
- * @param documentCount how many documents should be processed
- * @param threadCount how many threads are used by the cpm
- *
- * @return CollectionProcessingEngine - initialized cpe
- */
- private CollectionProcessingEngine setupCpm(int documentCount, int threadCount, boolean useSlowAnnotator, boolean singleThreaded) throws Exception
- {
- CpeDescription cpeDesc = null;
- CollectionProcessingEngine cpe = null;
-
- try
- {
- String colReaderBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestCollectionReader.xml";
- String taeBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestAnnotator.xml";
- String casConsumerBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestCasConsumer.xml";
-
- // created needed descriptors
- String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
- String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
- String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
-
- // create cpm descriptor
- cpeDesc = CpeDescriptorFactory.produceDescriptor();
- cpeDesc.setInputQueueSize(2);
- cpeDesc.setOutputQueueSize(2);
- cpeDesc.setProcessingUnitThreadCount(threadCount);
-
- if(singleThreaded) {
- cpeDesc.setDeployment("single-threaded");
- }
-
- // add tae
- CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory.produceCasProcessor("ErrorTestAnnotator");
- integratedProcessor.setDescriptor(taeDesc);
- cpeDesc.addCasProcessor(integratedProcessor);
-
- //add slow annotator if requested
- if (useSlowAnnotator)
- {
- CpeIntegratedCasProcessor slowProcessor = CpeDescriptorFactory.produceCasProcessor("SlowAnnotator");
- slowProcessor.setDescriptor(junitTestBasePath + "CpmTests" + separator + "SlowAnnotator.xml");
- cpeDesc.addCasProcessor(slowProcessor);
- }
-
- // add casConsumer
- CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory.produceCasProcessor("ErrorTest CasConsumer");
- casConsumer.setDescriptor(casConsumerDesc);
- cpeDesc.addCasProcessor(casConsumer);
+ private static String junitTestBasePath;
- // add collectionReader
- cpeDesc.addCollectionReader(colReaderDesc);
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ // get test base path setting
+ junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FunctionErrorStore.resetCount();
+ }
+
+ public void testInitSingleThreadCPMMode() throws Exception {
+ int documentCount = 10000;
+ int threadCount = 1;
+
+ // setup CPM to process 1 documents
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, true);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ // wait for initialized call from the CPM
+ while (!listener.isInitialized()) {
+ Thread.sleep(10);
+ }
+ System.out.println("Initialize was called: " + listener.isInitialized());
+
+ // Let the CPM process some docs, before calling stop
+ Thread.sleep(500);
+
+ // stop CPM
+ cpe.stop();
+
+ // wait until CPM has aborted
+ while (!listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ }
+
+ public void testInitMultiThreadCPMMode() throws Exception {
+ int documentCount = 10000; // hopefully enough that we won't finish before we abort
+ int threadCount = 1;
+
+ // setup CPM to process 1 documents
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, false);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ while (!listener.isInitialized()) {
+ Thread.sleep(10);
+ }
+ System.out.println("Initialize was called: " + listener.isInitialized());
+
+ // Let the CPM process some docs, before calling stop
+ Thread.sleep(500);
+
+ // stop CPM
+ cpe.stop();
+
+ // wait until CPM has aborted
+ while (!listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ }
+
+ public void testInitMultiThreadCPM() throws Exception {
+ int documentCount = 10000;
+ int threadCount = 3;
+
+ // setup CPM to process documents
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount, false, false);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ while (!listener.isInitialized()) {
+ Thread.sleep(10);
+ }
+ System.out.println("testInitMultiThreadCPM()-Initialize was called: "
+ + listener.isInitialized());
+ // Let the CPM process some docs, before calling stop
+ Thread.sleep(500);
+
+ // stop CPM
+ cpe.stop();
+
+ // wait until CPM has aborted
+ while (!listener.isAborted()) {
+ Thread.sleep(5);
+ }
+ }
+
+ /**
+ * setup the CPM with base functionality.
+ *
+ * @param documentCount
+ * how many documents should be processed
+ * @param threadCount
+ * how many threads are used by the cpm
+ *
+ * @return CollectionProcessingEngine - initialized cpe
+ */
+ private CollectionProcessingEngine setupCpm(int documentCount, int threadCount,
+ boolean useSlowAnnotator, boolean singleThreaded) throws Exception {
+ CpeDescription cpeDesc = null;
+ CollectionProcessingEngine cpe = null;
+
+ try {
+ String colReaderBase = junitTestBasePath + "CpmTests" + separator
+ + "ErrorTestCollectionReader.xml";
+ String taeBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestAnnotator.xml";
+ String casConsumerBase = junitTestBasePath + "CpmTests" + separator
+ + "ErrorTestCasConsumer.xml";
+
+ // created needed descriptors
+ String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
+ String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
+ String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
+
+ // create cpm descriptor
+ cpeDesc = CpeDescriptorFactory.produceDescriptor();
+ cpeDesc.setInputQueueSize(2);
+ cpeDesc.setOutputQueueSize(2);
+ cpeDesc.setProcessingUnitThreadCount(threadCount);
- //produce cpe
- cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
+ if (singleThreaded) {
+ cpeDesc.setDeployment("single-threaded");
}
- catch (Exception e)
- {
- e.printStackTrace();
+
+ // add tae
+ CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTestAnnotator");
+ integratedProcessor.setDescriptor(taeDesc);
+ cpeDesc.addCasProcessor(integratedProcessor);
+
+ // add slow annotator if requested
+ if (useSlowAnnotator) {
+ CpeIntegratedCasProcessor slowProcessor = CpeDescriptorFactory
+ .produceCasProcessor("SlowAnnotator");
+ slowProcessor.setDescriptor(junitTestBasePath + "CpmTests" + separator
+ + "SlowAnnotator.xml");
+ cpeDesc.addCasProcessor(slowProcessor);
}
- return cpe;
- }
+ // add casConsumer
+ CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTest CasConsumer");
+ casConsumer.setDescriptor(casConsumerDesc);
+ cpeDesc.addCasProcessor(casConsumer);
+
+ // add collectionReader
+ cpeDesc.addCollectionReader(colReaderDesc);
+
+ // produce cpe
+ cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return cpe;
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmProcessingTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmProcessingTest.java?view=diff&rev=478226&r1=478225&r2=478226
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmProcessingTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-cpe/src/test/java/org/apache/uima/collection/impl/cpm/CpmProcessingTest.java Wed Nov 22 08:43:54 2006
@@ -33,226 +33,237 @@
import org.apache.uima.test.junit_extension.TestPropertyReader;
/**
- * This test aimes to check if the cpm implements the ProcessingUnitThreadCount in
- * the correct manner. That means that no matter which configuration and document number
- * is chosen, every document should be processed exactly one time.
- *
+ * This test aimes to check if the cpm implements the ProcessingUnitThreadCount in the correct
+ * manner. That means that no matter which configuration and document number is chosen, every
+ * document should be processed exactly one time.
+ *
*/
-public class CpmProcessingTest extends TestCase
-{
- private static final String separator = System.getProperties().getProperty("file.separator");
-
- private static String junitTestBasePath;
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception
- {
- //get test base path setting
- junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
- //disable schema validation -- this test uses descriptors
- //that don't validate, for some reason
- UIMAFramework.getXMLParser().enableSchemaValidation(false);
- }
-
- /**
- * @throws Exception
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception
- {
- super.tearDown();
- FunctionErrorStore.resetCount();
- }
-
- /**
- * Create a single processor which have to work on only on document
- *
- * @throws Exception
- */
- public void testCasConsumerProcessingSingleThreadSingleDocument() throws Exception
- {
- //process only a single document and a single thread
- int documentCount = 1;
- int threadCount = 1;
-
- //setup CPM to process one document
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- //wait until CPM has finished
- while (!listener.isFinished())
- {
- Thread.sleep(5);
- }
-
- //check if CasConsumer was called
- Assert.assertEquals("StatusCallbackListener", documentCount, listener.getEntityProcessCompleteCount());
- Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore.getCasConsumerProcessCount());
- Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore.getAnnotatorProcessCount());
- Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore.getCollectionReaderGetNextCount());
- Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount()); }
-
- /**
- * Create a single processor which have to process multiple documents
- *
- * @throws Exception
- */
- public void testCasConsumerProcessingSingleThreadMultipleDocuments() throws Exception
- {
- //process 100 documents and a single thread
- int documentCount = 100;
- int threadCount = 1;
-
- //setup CPM to process 100 documents
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- //wait until CPM has finished
- while (!listener.isFinished())
- {
- Thread.sleep(5);
- }
-
- //check if CasConsumer was called
- Assert.assertEquals("StatusCallbackListener", documentCount, listener.getEntityProcessCompleteCount());
- Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore.getCasConsumerProcessCount());
- Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore.getAnnotatorProcessCount());
- Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore.getCollectionReaderGetNextCount());
- Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount()); }
-
- /**
- * Create multiple processors which have to process only one single document!
- *
- * @throws Exception
- */
- public void testCasConsumerProcessingMultipleThreadsSingleDocument() throws Exception
- {
- //process only a single document and multiple threads
- int documentCount = 1;
- int threadCount = 5;
-
- //setup CPM to process one document
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- //wait until CPM has finished
- while (!listener.isFinished())
- {
- Thread.sleep(5);
- }
-
- //check if CasConsumer was called
- Assert.assertEquals("StatusCallbackListener", documentCount, listener.getEntityProcessCompleteCount());
- Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore.getCasConsumerProcessCount());
- Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore.getAnnotatorProcessCount());
- Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore.getCollectionReaderGetNextCount());
- Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount()); }
-
- /**
- * Create multiple processors which have to process multiple documents
- *
- * @throws Exception
- */
- public void testCasConsumerProcessingMultipleThreadsMultipleDocuments() throws Exception
- {
- //process 100 documents and multiple threads
- int documentCount = 100;
- int threadCount = 5;
-
- //setup CPM to process 100 documents
- CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
-
- //create and register a status callback listener
- TestStatusCallbackListener listener = new TestStatusCallbackListener();
- cpe.addStatusCallbackListener(listener);
-
- //run CPM
- cpe.process();
-
- //wait until CPM has finished
- while (!listener.isFinished())
- {
- Thread.sleep(5);
- }
-
- //check if CasConsumer was called
- Assert.assertEquals("StatusCallbackListener", documentCount, listener.getEntityProcessCompleteCount());
- Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore.getCasConsumerProcessCount());
- Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore.getAnnotatorProcessCount());
- Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore.getCollectionReaderGetNextCount());
- Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount()); }
-
- /**
- * setup the CPM with base functionality.
- *
- * @param documentCount how many documents should be processed
- * @param threadCount how many threads are used by the cpm
- *
- * @return CollectionProcessingEngine - initialized cpe
- */
- private CollectionProcessingEngine setupCpm(int documentCount, int threadCount) throws Exception
- {
- CpeDescription cpeDesc = null;
- CollectionProcessingEngine cpe = null;
-
- try
- {
- String colReaderBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestCollectionReader.xml";
- String taeBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestAnnotator.xml";
- String casConsumerBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestCasConsumer.xml";
-
- // created needed descriptors
- String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
- String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
- String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
-
- // create cpm descriptor
- cpeDesc = CpeDescriptorFactory.produceDescriptor();
- cpeDesc.setInputQueueSize(2);
- cpeDesc.setOutputQueueSize(2);
- cpeDesc.setProcessingUnitThreadCount(threadCount);
-
- // add tae
- CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory.produceCasProcessor("ErrorTestAnnotator");
- integratedProcessor.setDescriptor(taeDesc);
- cpeDesc.addCasProcessor(integratedProcessor);
-
- // add casConsumer
- CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory.produceCasProcessor("ErrorTest CasConsumer");
- casConsumer.setDescriptor(casConsumerDesc);
- cpeDesc.addCasProcessor(casConsumer);
-
- // add collectionReader
- cpeDesc.addCollectionReader(colReaderDesc);
-
- //produce cpe
- cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+public class CpmProcessingTest extends TestCase {
+ private static final String separator = System.getProperties().getProperty("file.separator");
- return cpe;
- }
+ private static String junitTestBasePath;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ // get test base path setting
+ junitTestBasePath = TestPropertyReader.getJUnitTestBasePath();
+ // disable schema validation -- this test uses descriptors
+ // that don't validate, for some reason
+ UIMAFramework.getXMLParser().enableSchemaValidation(false);
+ }
+
+ /**
+ * @throws Exception
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FunctionErrorStore.resetCount();
+ }
+
+ /**
+ * Create a single processor which have to work on only on document
+ *
+ * @throws Exception
+ */
+ public void testCasConsumerProcessingSingleThreadSingleDocument() throws Exception {
+ // process only a single document and a single thread
+ int documentCount = 1;
+ int threadCount = 1;
+
+ // setup CPM to process one document
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ // wait until CPM has finished
+ while (!listener.isFinished()) {
+ Thread.sleep(5);
+ }
+
+ // check if CasConsumer was called
+ Assert.assertEquals("StatusCallbackListener", documentCount, listener
+ .getEntityProcessCompleteCount());
+ Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
+ .getCasConsumerProcessCount());
+ Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
+ .getAnnotatorProcessCount());
+ Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
+ .getCollectionReaderGetNextCount());
+ Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount());
+ }
+
+ /**
+ * Create a single processor which have to process multiple documents
+ *
+ * @throws Exception
+ */
+ public void testCasConsumerProcessingSingleThreadMultipleDocuments() throws Exception {
+ // process 100 documents and a single thread
+ int documentCount = 100;
+ int threadCount = 1;
+
+ // setup CPM to process 100 documents
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ // wait until CPM has finished
+ while (!listener.isFinished()) {
+ Thread.sleep(5);
+ }
+
+ // check if CasConsumer was called
+ Assert.assertEquals("StatusCallbackListener", documentCount, listener
+ .getEntityProcessCompleteCount());
+ Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
+ .getCasConsumerProcessCount());
+ Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
+ .getAnnotatorProcessCount());
+ Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
+ .getCollectionReaderGetNextCount());
+ Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount());
+ }
+
+ /**
+ * Create multiple processors which have to process only one single document!
+ *
+ * @throws Exception
+ */
+ public void testCasConsumerProcessingMultipleThreadsSingleDocument() throws Exception {
+ // process only a single document and multiple threads
+ int documentCount = 1;
+ int threadCount = 5;
+
+ // setup CPM to process one document
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ // wait until CPM has finished
+ while (!listener.isFinished()) {
+ Thread.sleep(5);
+ }
+
+ // check if CasConsumer was called
+ Assert.assertEquals("StatusCallbackListener", documentCount, listener
+ .getEntityProcessCompleteCount());
+ Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
+ .getCasConsumerProcessCount());
+ Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
+ .getAnnotatorProcessCount());
+ Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
+ .getCollectionReaderGetNextCount());
+ Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount());
+ }
+
+ /**
+ * Create multiple processors which have to process multiple documents
+ *
+ * @throws Exception
+ */
+ public void testCasConsumerProcessingMultipleThreadsMultipleDocuments() throws Exception {
+ // process 100 documents and multiple threads
+ int documentCount = 100;
+ int threadCount = 5;
+
+ // setup CPM to process 100 documents
+ CollectionProcessingEngine cpe = setupCpm(documentCount, threadCount);
+
+ // create and register a status callback listener
+ TestStatusCallbackListener listener = new TestStatusCallbackListener();
+ cpe.addStatusCallbackListener(listener);
+
+ // run CPM
+ cpe.process();
+
+ // wait until CPM has finished
+ while (!listener.isFinished()) {
+ Thread.sleep(5);
+ }
+
+ // check if CasConsumer was called
+ Assert.assertEquals("StatusCallbackListener", documentCount, listener
+ .getEntityProcessCompleteCount());
+ Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
+ .getCasConsumerProcessCount());
+ Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
+ .getAnnotatorProcessCount());
+ Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
+ .getCollectionReaderGetNextCount());
+ Assert.assertEquals("number of annoators", threadCount, FunctionErrorStore.getAnnotatorCount());
+ }
+
+ /**
+ * setup the CPM with base functionality.
+ *
+ * @param documentCount
+ * how many documents should be processed
+ * @param threadCount
+ * how many threads are used by the cpm
+ *
+ * @return CollectionProcessingEngine - initialized cpe
+ */
+ private CollectionProcessingEngine setupCpm(int documentCount, int threadCount) throws Exception {
+ CpeDescription cpeDesc = null;
+ CollectionProcessingEngine cpe = null;
+
+ try {
+ String colReaderBase = junitTestBasePath + "CpmTests" + separator
+ + "ErrorTestCollectionReader.xml";
+ String taeBase = junitTestBasePath + "CpmTests" + separator + "ErrorTestAnnotator.xml";
+ String casConsumerBase = junitTestBasePath + "CpmTests" + separator
+ + "ErrorTestCasConsumer.xml";
+
+ // created needed descriptors
+ String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
+ String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
+ String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);
+
+ // create cpm descriptor
+ cpeDesc = CpeDescriptorFactory.produceDescriptor();
+ cpeDesc.setInputQueueSize(2);
+ cpeDesc.setOutputQueueSize(2);
+ cpeDesc.setProcessingUnitThreadCount(threadCount);
+
+ // add tae
+ CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTestAnnotator");
+ integratedProcessor.setDescriptor(taeDesc);
+ cpeDesc.addCasProcessor(integratedProcessor);
+
+ // add casConsumer
+ CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
+ .produceCasProcessor("ErrorTest CasConsumer");
+ casConsumer.setDescriptor(casConsumerDesc);
+ cpeDesc.addCasProcessor(casConsumer);
+
+ // add collectionReader
+ cpeDesc.addCollectionReader(colReaderDesc);
+
+ // produce cpe
+ cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return cpe;
+ }
}