Search in sources :

Example 51 with GuidGenerator

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

the class FsMessageConsumerTest method testBug2100_OriginalNameContainsWip.

@Test
public void testBug2100_OriginalNameContainsWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    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) 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 52 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeIgnoresWip.

@Test
public void testConsumeIgnoresWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener();
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    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", count);
        createFiles(baseDir, ".xml.wip", count);
        start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.wip");
        assertEquals(count, baseDir.listFiles((FilenameFilter) wip).length);
        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 53 with GuidGenerator

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

the class FsMessageProducerTest method testSetFsWorker.

@Test
public void testSetFsWorker() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer producer = createProducer(subdir);
    assertEquals(NioWorker.class, producer.getFsWorker().getClass());
    OverwriteIfExistsWorker worker = new OverwriteIfExistsWorker();
    producer.setFsWorker(worker);
    assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
    assertEquals(worker, producer.getFsWorker());
    try {
        producer.setFsWorker(null);
        fail();
    } catch (IllegalArgumentException | NullPointerException expected) {
    }
    assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
    assertEquals(worker, producer.getFsWorker());
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) OverwriteIfExistsWorker(com.adaptris.fs.OverwriteIfExistsWorker) Test(org.junit.Test)

Example 54 with GuidGenerator

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

the class FsMessageProducerTest method testCreateName.

@Test
public void testCreateName() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer producer = createProducer(subdir);
    assertEquals(producer.getClass().getCanonicalName(), producer.createName());
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 55 with GuidGenerator

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

the class FsMessageProducerTest method testProduceWithTempDir.

@Test
public void testProduceWithTempDir() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    String tmpDir = new GuidGenerator().safeUUID();
    String tempDir = PROPERTIES.getProperty(BASE_TEMP_DIR) + "/" + tmpDir;
    FsProducer producer = createProducer(subdir);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    File tmpParentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_TEMP_DIR), true));
    try {
        producer.setTempDirectory(tempDir);
        StandaloneProducer sp = new StandaloneProducer(producer);
        ServiceCase.execute(sp, new DefaultMessageFactory().newMessage(TEXT));
        File f = new File(tmpParentDir, tmpDir);
        assertTrue(f.exists());
        assertTrue(f.isDirectory());
        assertEquals(1, new File(parentDir, subdir).listFiles().length);
        assertEquals(0, new File(tmpParentDir, tmpDir).listFiles().length);
    } finally {
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        FileUtils.deleteQuietly(new File(tmpParentDir, tmpDir));
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) StandaloneProducer(com.adaptris.core.StandaloneProducer) 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