@Test public void testDocumentText() throws Exception { BaleenCollectionReader bcr = getCollectionReader(MimeReader.PARAM_FOLDER, tmpDir.toAbsolutePath().toString()); bcr.initialize(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertTrue(jCas.getDocumentText().startsWith("I'm going to eat you!")); bcr.close(); } }
@Override public final void close() throws IOException { monitor.startFunction("close"); doClose(); monitor.finishFunction("close"); }
@Override public final Progress[] getProgress() { monitor.startFunction("getProgress"); Progress[] ret = doGetProgress(); monitor.finishFunction("getProgress"); return ret; }
@Override public void destroy() { super.destroy(); try { close(); } catch (IOException e) { getMonitor().warn("Close on destroy", e); } }
@Test public void testDeleteFile() throws Exception { BaleenCollectionReader bcr = getCollectionReader(FolderReader.PARAM_FOLDERS, new String[] {inputDir.getPath()}); assertFalse(bcr.doHasNext()); File f = new File(inputDir, TEXT1_FILE); f.createNewFile(); // Wait for file to be written and change detected Thread.sleep(TIMEOUT); f.delete(); // Wait for file to be written and change detected Thread.sleep(TIMEOUT); assertFalse(bcr.doHasNext()); bcr.close(); }
@Test public void testCreateFile() throws Exception { BaleenCollectionReader bcr = getCollectionReader(FolderReader.PARAM_FOLDERS, new String[] {inputDir.getPath()}); assertFalse(bcr.doHasNext()); File f = new File(inputDir, TEXT1_FILE); f.createNewFile(); // Wait for file to be written and change detected Thread.sleep(TIMEOUT); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertFilesEquals(f.getPath(), getSource(jCas)); assertFalse(bcr.doHasNext()); bcr.close(); }
@Test public void testPopWait() throws Exception { BaleenCollectionReader bcr = getCollectionReader( EmailReader.PARAM_PROTOCOL, "pop3", EmailReader.PARAM_WAIT, 5, EmailReader.PARAM_SERVER, greenMail.getPop3().getBindTo(), EmailReader.PARAM_PORT, greenMail.getPop3().getPort(), EmailReader.PARAM_USER, "to@localhost.com", EmailReader.PARAM_PASS, "password", EmailReader.PARAM_PROCESS, "content"); bcr.initialize(); assertFalse(bcr.doHasNext()); GreenMailUtil.sendTextEmailTest( "to@localhost.com", "from@localhost.com", GreenMailUtil.random(), GreenMailUtil.random()); assertFalse(bcr.doHasNext()); // Should be a 5 second delay before it returns true Thread.sleep(5000); assertTrue(bcr.doHasNext()); bcr.close(); }
@Test public void testSubDirectoriesNonRecursive() throws Exception { File subdir = new File(inputDir, "subdir"); subdir.mkdir(); File f1 = new File(subdir, TEXT1_FILE); f1.createNewFile(); File f2 = new File(inputDir, TEST2_FILE); f2.createNewFile(); BaleenCollectionReader bcr = getCollectionReader( FolderReader.PARAM_FOLDERS, new String[] {inputDir.getPath()}, FolderReader.PARAM_RECURSIVE, false); assertTrue(bcr.hasNext()); bcr.getNext(jCas.getCas()); assertFilesEquals(f2.getPath(), getSource(jCas)); jCas.reset(); File f3 = new File(inputDir, TEST3_FILE); f3.createNewFile(); Thread.sleep(TIMEOUT); assertTrue(bcr.hasNext()); bcr.getNext(jCas.getCas()); assertFilesEquals(f3.getPath(), getSource(jCas)); bcr.close(); f1.delete(); f2.delete(); subdir.delete(); }
@Test public void test() throws Exception { setup(); BaleenCollectionReader bcr = getCollectionReader( SqlRowReader.PARAM_SQL_CONNECTION, "jdbc:h2:mem:test", SqlRowReader.PARAM_SQL_TABLE, "my_table", SqlRowReader.PARAM_SQL_IGNORE, "ignore_me", SqlRowReader.PARAM_TEXT_COLUMNS, new String[] {"text_column1", "text_column2"}); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 1); jCas.reset(); assertFalse(bcr.hasNext()); insert(); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 2); assertFalse(bcr.hasNext()); teardown(); }
/** * Override of the UIMA hasNext() method with logic to continuously check for new documents until * one is found. This prevents the collection reader from exiting (unless asked to), and so * creates a persistent collection reader and pipeline. */ @Override public final boolean hasNext() throws IOException, CollectionException { monitor.startFunctionTrace("hasNext"); boolean next = doHasNext(); monitor.finishFunctionTrace("hasNext"); return next; }
public void close() throws IOException { sender.destroy(); reader.close(); } }
public void run() throws UIMAException, IOException { sender.process(getIn()); reader.getNext(getOut()); }
@Override public final void getNext(JCas jCas) throws IOException, CollectionException { monitor.startFunction("getNext"); MetricsFactory.getInstance() .getPipelineMetrics(monitor.getPipelineName()) .startDocumentProcess(); doGetNext(jCas); monitor.finishFunction("getNext"); monitor.persistCounts(); }
@Override public final void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); // This will do initialization of resources, // but won't be included in the metrics String pipelineName = UimaUtils.getPipelineName(context); monitor = new UimaMonitor(pipelineName, this.getClass()); support = new UimaSupport( pipelineName, this.getClass(), history, monitor, UimaUtils.isMergeDistinctEntities(context)); monitor.startFunction("initialize"); doInitialize(context); monitor.finishFunction("initialize"); }
@Test public void testPopNoMessages() throws Exception { BaleenCollectionReader bcr = getCollectionReader( EmailReader.PARAM_PROTOCOL, "pop3", EmailReader.PARAM_WAIT, 5, EmailReader.PARAM_SERVER, greenMail.getPop3().getBindTo(), EmailReader.PARAM_PORT, greenMail.getPop3().getPort(), EmailReader.PARAM_USER, "to@localhost.com", EmailReader.PARAM_PASS, "password"); bcr.initialize(); assertFalse(bcr.doHasNext()); bcr.close(); }
@Test public void testExistingFiles() throws Exception { File f1 = new File(inputDir, TEXT1_FILE); f1.createNewFile(); File f2 = new File(inputDir, TEST2_FILE); f2.createNewFile(); BaleenCollectionReader bcr = getCollectionReader(FolderReader.PARAM_FOLDERS, new String[] {inputDir.getPath()}); assertNextSourceNotNull(bcr); assertNextSourceNotNull(bcr); assertFalse(bcr.doHasNext()); bcr.close(); }
@Override public void destroy() { super.destroy(); try { close(); } catch (IOException e) { getMonitor().warn("Close on destroy", e); } }
"ignore_me"); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 1); jCas.reset(); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 1); jCas.reset(); assertFalse(bcr.hasNext()); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 2); jCas.reset(); assertTrue(bcr.hasNext()); bcr.getNext(jCas); testJcas(jCas, 2); jCas.reset(); assertFalse(bcr.hasNext());