Search in sources :

Example 46 with GuidGenerator

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

the class MimeEncoderTest method createMimeOutput.

private static byte[] createMimeOutput(boolean includePayloadPart, boolean includeMetadataPart) throws Exception {
    MultiPartOutput output = new MultiPartOutput(new GuidGenerator().getUUID());
    if (includePayloadPart) {
        output.addPart(STANDARD_PAYLOAD.getBytes(), "base64", "AdaptrisMessage/payload");
    }
    if (includeMetadataPart) {
        Properties p = new Properties();
        p.setProperty(METADATA_KEY, METADATA_VALUE);
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        p.store(bytes, "");
        bytes.close();
        output.addPart(bytes.toByteArray(), "base64", "AdaptrisMessage/metadata");
    }
    output.addPart(STANDARD_PAYLOAD_NON_JUST_ALPHA.getBytes(), "base64", "Dude/SomeOtherPart");
    return output.getBytes();
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) GuidGenerator(com.adaptris.util.GuidGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 47 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeImmediateEventPoller.

@Test
public void testConsumeImmediateEventPoller() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FsImmediateEventPoller());
    fs.setQuietInterval(new TimeInterval(500L, "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);
        Thread.sleep(1000);
        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) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 48 with GuidGenerator

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

the class FsMessageConsumerTest method testBug2233_ResetWipFilesOnNonExistentDirectory.

@Test
public void testBug2233_ResetWipFilesOnNonExistentDirectory() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setCreateDirs(true);
    fs.setResetWipFiles(true);
    fs.setReacquireLockBetweenMessages(true);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    LifecycleHelper.init(sc);
    LifecycleHelper.close(sc);
}
Also used : 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) Test(org.junit.Test)

Example 49 with GuidGenerator

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

the class FsMessageConsumerTest method testConsumeBug3304OversizedFiles.

@Test
public void testConsumeBug3304OversizedFiles() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    if (fs instanceof LargeFsConsumer) {
        // The large FS consumer should (by definition) handle large files
        return;
    }
    fs.setReacquireLockBetweenMessages(true);
    AtomicBoolean pollFired = new AtomicBoolean(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> {
        pollFired.set(true);
    }));
    fs.fsWorker = new SizeLimitedWorker();
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 1;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        File largeFile = File.createTempFile("3304", null, baseDir);
        RandomAccessFile raf = new RandomAccessFile(largeFile, "rw");
        // Set the size to be 10Mb.
        raf.setLength(0x00100000 * 10);
        LifecycleHelper.prepare(sc);
        LifecycleHelper.start(sc);
        waitForPollCallback(pollFired);
        assertTrue(stub.getMessages().size() == 0);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) RandomAccessFile(java.io.RandomAccessFile) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) Assert.fail(org.junit.Assert.fail) GuidGenerator(com.adaptris.util.GuidGenerator) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) AlphabeticAscending(com.adaptris.core.fs.enhanced.AlphabeticAscending) LifecycleHelper(com.adaptris.core.util.LifecycleHelper) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CoreException(com.adaptris.core.CoreException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) CoreConstants(com.adaptris.core.CoreConstants) TimeInterval(com.adaptris.util.TimeInterval) FsException(com.adaptris.fs.FsException) StandardWorker(com.adaptris.fs.StandardWorker) Assert.assertEquals(org.junit.Assert.assertEquals) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RandomAccessFile(java.io.RandomAccessFile) 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) Test(org.junit.Test)

Example 50 with GuidGenerator

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

the class FsMessageConsumerTest method testBug1675ConsumeWithSpacesInDir.

@Test
public void testBug1675ConsumeWithSpacesInDir() throws Exception {
    String uniqueName = new GuidGenerator().safeUUID();
    String subDir = uniqueName + "Directory WithSpaces";
    String subDirEncoded = uniqueName + "Directory%20WithSpaces";
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDirEncoded);
    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.debug(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) 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) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) FsException(com.adaptris.fs.FsException) 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