Search in sources :

Example 11 with GuidGenerator

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

the class StaticIdentitySequenceNumberServiceTest method testService_PooledConnection.

@Test
public void testService_PooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    createDatabase();
    List<Service> serviceList = new ArrayList<Service>();
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            StaticIdentitySequenceNumberService service = createServiceForTests(false);
            service.setConnection(conn);
            service.setIdentity(new GuidGenerator().safeUUID());
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessageForTests();
            }
        });
        assertEquals(0, conn.currentBusyConnectionCount());
        assertEquals(poolsize, conn.currentIdleConnectionCount());
        assertEquals(poolsize, conn.currentConnectionCount());
    } finally {
        stop(serviceList.toArray(new ComponentLifecycle[0]));
        Thread.currentThread().setName(name);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ServiceException(com.adaptris.core.ServiceException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) GuidGenerator(com.adaptris.util.GuidGenerator) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Test(org.junit.Test)

Example 12 with GuidGenerator

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

the class StaticIdentitySequenceNumberServiceTest method testService_AdvancedPooledConnection.

@Test
public void testService_AdvancedPooledConnection() throws Exception {
    int maxServices = 5;
    final int iterations = 5;
    int poolsize = maxServices - 1;
    createDatabase();
    List<Service> serviceList = new ArrayList<Service>();
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
    try {
        for (int i = 0; i < maxServices; i++) {
            StaticIdentitySequenceNumberService service = createServiceForTests(false);
            service.setConnection(conn);
            service.setIdentity(new GuidGenerator().safeUUID());
            serviceList.add(service);
            start(service);
        }
        PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {

            @Override
            public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
                return createMessageForTests();
            }
        });
        assertEquals(0, conn.currentBusyConnectionCount());
        assertEquals(poolsize, conn.currentIdleConnectionCount());
        assertEquals(poolsize, conn.currentConnectionCount());
    } finally {
        stop(serviceList.toArray(new ComponentLifecycle[0]));
        Thread.currentThread().setName(name);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) Service(com.adaptris.core.Service) PooledConnectionHelper(com.adaptris.core.jdbc.PooledConnectionHelper) ServiceException(com.adaptris.core.ServiceException) ComponentLifecycle(com.adaptris.core.ComponentLifecycle) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 13 with GuidGenerator

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

the class WriteMetadataToFilesystemTest method testService_Filter.

@Test
public void testService_Filter() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = createMessage();
    WriteMetadataToFilesystem service = createService(subDir);
    RegexMetadataFilter filter = new RegexMetadataFilter();
    filter.addIncludePattern("alt_key.*");
    filter.addExcludePattern("^key.*");
    service.setMetadataFilter(filter);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    execute(service, msg);
    Properties p = readProperties(new File(propsFilename), false);
    assertFalse(p.containsKey("key5"));
    assertTrue(p.containsKey("alt_key5"));
    assertEquals("av5", p.getProperty("alt_key5"));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 14 with GuidGenerator

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

the class WriteMetadataToFilesystemTest method testService_OutputUnknown.

@Test
public void testService_OutputUnknown() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = createMessage();
    WriteMetadataToFilesystem service = createService(subDir);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    execute(service, msg);
    Properties p = readProperties(new File(propsFilename), false);
    assertTrue(p.containsKey("key5"));
    assertEquals("v5", p.getProperty("key5"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 15 with GuidGenerator

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

the class WriteMetadataToFilesystemTest method testService_OverwriteFalseFileNonExistent.

@Test
public void testService_OverwriteFalseFileNonExistent() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = createMessage();
    WriteMetadataToFilesystem service = createService(subDir);
    service.setOverwriteIfExists(false);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    execute(service, msg);
    Properties p = readProperties(new File(propsFilename), false);
    assertTrue(p.containsKey("key5"));
    assertEquals("v5", p.getProperty("key5"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) 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