Search in sources :

Example 76 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeWithAlphabeticSort.

@Test
public void testConsumeWithAlphabeticSort() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setFileSorter(new AlphabeticAscending());
    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")));
        AdaptrisMessage first = stub.getMessages().get(0);
        AdaptrisMessage last = stub.getMessages().get(9);
        String firstFilename = first.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY);
        String lastFilename = last.getMetadataValue(CoreConstants.ORIGINAL_NAME_KEY);
        assertTrue(firstFilename.compareTo(lastFilename) < 0);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) AlphabeticAscending(com.adaptris.core.fs.enhanced.AlphabeticAscending) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 77 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeWithQuietPeriod.

@Test
public void testConsumeWithQuietPeriod() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setQuietInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    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")));
    } 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) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) 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 78 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeWithResetWipFile.

@Test
public void testConsumeWithResetWipFile() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(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);
        baseDir.mkdirs();
        createFiles(baseDir, ".xml.wip", count);
        LifecycleHelper.init(sc);
        Perl5FilenameFilter p5 = new Perl5FilenameFilter(".*\\.xml");
        assertTrue("Files renamed in " + baseDir.getCanonicalPath(), baseDir.listFiles((FilenameFilter) p5).length > 0);
    } finally {
        // sc.stop();
        LifecycleHelper.close(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) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) 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 79 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeWithLastModifiedSort.

@Test
public void testConsumeWithLastModifiedSort() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setFileSorter(new LastModifiedAscending());
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 5;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        createFiles(baseDir, ".xml", count, 100);
        start(sc);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
        AdaptrisMessage first = stub.getMessages().get(0);
        AdaptrisMessage last = stub.getMessages().get(count - 1);
        String firstLastModified = first.getMetadataValue(CoreConstants.FILE_LAST_MODIFIED_KEY);
        String lastLastModified = last.getMetadataValue(CoreConstants.FILE_LAST_MODIFIED_KEY);
        assertTrue(Long.valueOf(firstLastModified).longValue() <= Long.valueOf(lastLastModified).longValue());
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) Test(org.junit.Test)

Example 80 with GuidGenerator

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

the class FsMessageConsumerTest method testBug2233_ResetWipFilesOnInvalidDirectory.

@Test
public void testBug2233_ResetWipFilesOnInvalidDirectory() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    File dir = FsHelper.createFileReference(FsHelper.createUrlFromString(fs.getBaseDirectoryUrl(), true));
    // attempting to fix the timing issues.
    dir.getParentFile().mkdirs();
    // makes it a file, so it should be invalid now.
    dir.createNewFile();
    fs.setCreateDirs(false);
    fs.setResetWipFiles(true);
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    try {
        LifecycleHelper.init(sc);
    } catch (CoreException e) {
        log.warn(e.getMessage(), e);
        assertNull(e.getCause());
        assertTrue(e.getMessage().matches("^Failed to list files in.*Cannot reset WIP files"));
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) 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