Package org.apache.uima.collection.impl.cpm.utils

Examples of org.apache.uima.collection.impl.cpm.utils.TestStatusCallbackListener


    // 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);
    }
  }
View Full Code Here


    // 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);
    }
  }
View Full Code Here

    // 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);
    }
  }
View Full Code Here

   */
  public void testInitializeWithResourceInitializationException() throws Exception {
    int documentCount = 20; // number of documents processed
    int exceptionSequence = 1; // the sequence in which errors are produced
    boolean exceptionThrown = false;
    TestStatusCallbackListener listener = null;
    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);
      cpeProcessNoMsg(cpe, listener);
    } catch (NullPointerException e) {
      exceptionThrown = true;
    } finally {
      // check the results, if everything worked as expected
      ManageOutputDevice.setAllSystemOutputToDefault();
      assertEquals("The expected NullPointerException wasn't thrown!", true, exceptionThrown);
      assertEquals(
              "The cpm called the listener, that the cpm has finished - which normally could not be.",
              false, listener.isFinished());
      assertEquals("The aborted-method of the listener was called. (new behaviour?)", false,
              listener.isAborted());
      assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
              .getCount());
    }
  }
View Full Code Here

  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;
    // setup CPM
    TestStatusCallbackListener listener = null;
    ManageOutputDevice.setAllSystemOutputToNirvana();
    try {
      CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
              exceptionSequence, "initialize");

      // Create and register a Status Callback Listener
      listener = new CollectionReaderStatusCallbackListener(cpe);
      cpe.addStatusCallbackListener(listener);
      cpeProcessNoMsg(cpe, listener);
    } catch (NullPointerException e) {
      // e.printStackTrace();
      exceptionThrown = true;
    } finally {
      // check the results, if everything worked as expected
      ManageOutputDevice.setAllSystemOutputToDefault();
      assertEquals("The expected NullPointerException wasn't thrown!", true, exceptionThrown);
      assertEquals(
              "The cpm called the listener, that the cpm has finished - which normally could not be.",
              false, listener.isFinished());
      assertEquals("The aborted-method of the listener was called. (new behaviour?)", false,
              listener.isAborted());
      assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
              .getCount());
    }
  }
View Full Code Here

  public void testInitializeWithOutOfMemoryError() throws Exception {
    int documentCount = 20; // number of documents processed
    int exceptionSequence = 1; // the sequence in which errors are produced
    boolean errorThrown = false;
    // setup CPM
    TestStatusCallbackListener listener = new TestStatusCallbackListener();
    ManageOutputDevice.setAllSystemOutputToNirvana();
    try {
      CollectionProcessingEngine cpe = setupCpm(documentCount, "OutOfMemoryError",
              exceptionSequence, "initialize");

      // Create and register a Status Callback Listener
      listener = new CollectionReaderStatusCallbackListener(cpe);
      cpe.addStatusCallbackListener(listener);
      cpeProcessNoMsg(cpe, listener);
    } catch (OutOfMemoryError er) {
      errorThrown = true;
    } finally {
      // check the results, if everything worked as expected
      ManageOutputDevice.setAllSystemOutputToDefault();
      assertEquals(
              "The cpm called the listener, that the cpm has finished - which normally could not be.",
              false, listener.isFinished());
      assertEquals("The aborted-method of the listener was called. (new behaviour?)", false,
              listener.isAborted());
      assertEquals("There are not as much exceptions as expected! ", 1, FunctionErrorStore
              .getCount());
      assertEquals("The expected Error wasn't thrown! ", true, errorThrown);
    }
  }
View Full Code Here

    // setup CPM
    CollectionProcessingEngine cpe = setupCpm(documentCount, "IOException", exceptionSequence,
            "processCas");

    // Create and register a Status Callback Listener
    TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
    cpe.addStatusCallbackListener(listener);
    cpeProcessNoMsg(cpe, listener);
    // check the results, if everything worked as expected
    ManageOutputDevice.setAllSystemOutputToDefault();
    assertEquals(
            "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
            true, listener.isFinished());
    assertEquals("The aborted-method of the listener was called. (new behaviour?)", false, listener
            .isAborted());
    assertEquals("There are not as much exceptions  thrown as expected! ",
            ((documentCount) / exceptionSequence), FunctionErrorStore.getCount());
    assertEquals(
            "The CAS which causes the error wasn't given to the process methode. Null was returned.",
            false, null == listener.getLastCas());
  }
View Full Code Here

    // setup CPM
    CollectionProcessingEngine cpe = setupCpm(documentCount, "ResourceProcessException",
            exceptionSequence, "processCas");

    // Create and register a Status Callback Listener
    TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
    cpe.addStatusCallbackListener(listener);
    cpeProcessNoMsg(cpe, listener);
    // check the results, if everything worked as expected
    ManageOutputDevice.setAllSystemOutputToDefault();
    assertEquals("The cpm did not call the listener, that the cpm has finished.", true, listener
            .isFinished());
    assertEquals("The aborted-method of the listener was called!", false, listener.isAborted());
    assertEquals("There are not as much exceptions as expected! ", countExceptions(documentCount,
            exceptionSequence), FunctionErrorStore.getCount());
  }
View Full Code Here

    // setup CPM
    CollectionProcessingEngine cpe = setupCpm(documentCount, "NullPointerException",
            exceptionSequence, "processCas");

    // Create and register a Status Callback Listener
    TestStatusCallbackListener listener = new CollectionReaderStatusCallbackListener(cpe);
    cpe.addStatusCallbackListener(listener);
    cpeProcessNoMsg(cpe, listener);
    // check the results, if everything worked as expected
    ManageOutputDevice.setAllSystemOutputToDefault();
    assertEquals("The cpm did not call the listener, that the cpm has finished.", true, listener
            .isFinished());
    assertEquals("The aborted-method of the listener was called!", false, listener.isAborted());
    assertEquals("There are not as much exceptions as expected! ", countExceptions(documentCount,
            exceptionSequence), FunctionErrorStore.getCount());
  }
View Full Code Here

  public void testImports() throws Exception {
    CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
            new XMLInputSource(JUnitExtension.getFile("CollectionProcessingEngineImplTest/CpeImportTest.xml")));           
    CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);

    TestStatusCallbackListener listener = new TestStatusCallbackListener();
    cpe.addStatusCallbackListener(listener);

    cpe.process();

    // wait until CPE has finished
    while (!listener.isFinished()) {
      Thread.sleep(5);
    }

    // check that components were called
    final int documentCount = 1000; //this is the # of documents produced by the test CollectionReader
    Assert.assertEquals("StatusCallbackListener", documentCount, listener
            .getEntityProcessCompleteCount());
    Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
            .getCasConsumerProcessCount());
    Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
            .getAnnotatorProcessCount());
View Full Code Here

TOP

Related Classes of org.apache.uima.collection.impl.cpm.utils.TestStatusCallbackListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.