Search in sources :

Example 91 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsMessageProducerTest method testProduceWithMetadataFilenameCreator.

@Test
public void testProduceWithMetadataFilenameCreator() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(true);
    fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File dir = new File(parentDir, subdir);
        start(fs);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
        msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
        fs.produce(msg);
        assertEquals(1, dir.listFiles().length);
    } finally {
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        stop(fs);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) Test(org.junit.Test)

Example 92 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testConsumeNotReprocessed.

@Test
public void testConsumeNotReprocessed() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    AtomicBoolean pollFired = new AtomicBoolean(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(500L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
        if (e == 0) {
            pollFired.set(true);
        }
    }));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        // The next call back should be on the next poll, when messages == 0;
        waitForPollCallback(pollFired);
        // that we don't reprocess them.
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : StandaloneConsumer(com.adaptris.core.StandaloneConsumer) FilenameFilter(java.io.FilenameFilter) RandomAccessFile(java.io.RandomAccessFile) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PollerImp(com.adaptris.core.PollerImp) ArrayList(java.util.ArrayList) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) GuidGenerator(com.adaptris.util.GuidGenerator) PrintStream(java.io.PrintStream) LifecycleHelper(com.adaptris.core.util.LifecycleHelper) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TempFileUtils(com.adaptris.core.stubs.TempFileUtils) List(java.util.List) CoreConstants(com.adaptris.core.CoreConstants) Assert.assertFalse(org.junit.Assert.assertFalse) TimeInterval(com.adaptris.util.TimeInterval) Assert.assertEquals(org.junit.Assert.assertEquals) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 93 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testConsume.

@Test
public void testConsume() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 94 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testBug2100_OriginalNameContainsWip.

@Test
public void testBug2100_OriginalNameContainsWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testBug2100_OriginalNameContainsWip");
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
        for (AdaptrisMessage msg : stub.getMessages()) {
            assertFalse("original name should not contain '.wip'", msg.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY).endsWith(".wip"));
        }
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 95 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testHasChanged_Size.

@Test
public void testHasChanged_Size() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    File f = createFile(TempFileUtils.createTrackedFile(getName(), "", fs), PANGRAM_1);
    ProcessedItem item = new ProcessedItem(f.getAbsolutePath(), f.lastModified(), 0);
    ProcessedItemCache cache = new InlineItemCache();
    fs.setPoller(new Never());
    fs.setProcessedItemCache(cache);
    StandaloneConsumer consumer = new StandaloneConsumer(fs);
    try {
        start(consumer);
        cache.update(item);
        ProcessedItem changed = new ProcessedItem(f.getAbsolutePath(), f.lastModified(), f.length());
        assertTrue(fs.hasChanged(changed));
        cache.update(changed);
        assertFalse(fs.hasChanged(changed));
    } finally {
        stop(consumer);
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Aggregations

GuidGenerator (com.adaptris.util.GuidGenerator)134 Test (org.junit.Test)120 File (java.io.File)91 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)61 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)30 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)27 TimeInterval (com.adaptris.util.TimeInterval)25 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)23 FilenameFilter (java.io.FilenameFilter)21 ArrayList (java.util.ArrayList)20 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)18 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 Properties (java.util.Properties)15 Adapter (com.adaptris.core.Adapter)14 CoreException (com.adaptris.core.CoreException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)9 ServiceException (com.adaptris.core.ServiceException)8 IOException (java.io.IOException)8