Search in sources :

Example 11 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class JdbcServiceListTest method testServiceList_ExceptionRollsback.

@Test
public void testServiceList_ExceptionRollsback() throws Exception {
    createDatabase();
    JdbcServiceList service = createServiceCollection();
    DatabaseConnection c = createJdbcConnection();
    c.setAutoCommit(false);
    c.setDebugMode(true);
    service.setConnection(c);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName("testServiceList_ExceptionRollsback");
    try {
        service.add(createSequenceNumberService(null, getName(), SequenceNumberCase.DEFAULT_ID));
        service.add(new NullService() {

            @Override
            public void doService(AdaptrisMessage msg) throws ServiceException {
                throw new ServiceException("testServiceList_ExceptionRollsback throws an Exception");
            }
        });
        try {
            execute(service, msg);
        } catch (ServiceException expected) {
        }
        assertTrue(msg.getObjectHeaders().containsKey(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY));
        Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
        assertTrue(conn.isClosed());
        // Here, we will expect there to be in row inserted.
        // getCurrentSequenceNumber returns -1 in that instance, C-Styley
        assertEquals(-1, getCurrentSequenceNumber(SequenceNumberCase.DEFAULT_ID));
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) Connection(java.sql.Connection) AdvancedJdbcPooledConnection(com.adaptris.core.jdbc.AdvancedJdbcPooledConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) JdbcPooledConnection(com.adaptris.core.jdbc.JdbcPooledConnection) JdbcConnection(com.adaptris.core.jdbc.JdbcConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 12 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectWithDebugMode.

@Test
public void testConnectWithDebugMode() throws Exception {
    DatabaseConnection conn = configure(createConnection());
    conn.setDebugMode(true);
    LifecycleHelper.init(conn);
    conn.connect();
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 13 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testSetConnectionRetryInterval.

@Test
public void testSetConnectionRetryInterval() throws Exception {
    DatabaseConnection con = createConnection();
    assertNull(con.getConnectionRetryInterval());
    assertEquals(60000, con.connectionRetryInterval());
    TimeInterval t = new TimeInterval(1L, TimeUnit.HOURS);
    con.setConnectionRetryInterval(t);
    assertEquals(t, con.getConnectionRetryInterval());
    assertEquals(t.toMilliseconds(), con.connectionRetryInterval());
    con.setConnectionRetryInterval(null);
    assertNull(con.getConnectionRetryInterval());
    assertEquals(60000, con.connectionRetryInterval());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Example 14 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectWithProperties.

@Test
public void testConnectWithProperties() throws Exception {
    DatabaseConnection con = configure(createConnection());
    con.setConnectionProperties(new KeyValuePairSet());
    LifecycleHelper.init(con);
    LifecycleHelper.start(con);
    con.connect();
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) Test(org.junit.Test)

Example 15 with DatabaseConnection

use of com.adaptris.core.jdbc.DatabaseConnection in project interlok by adaptris.

the class DatabaseConnectionCase method testConnectWithoutAlwaysValidate.

@Test
public void testConnectWithoutAlwaysValidate() throws Exception {
    DatabaseConnection conn = configure(createConnection());
    conn.setAlwaysValidateConnection(false);
    LifecycleHelper.init(conn);
    conn.connect();
}
Also used : DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Test(org.junit.Test)

Aggregations

DatabaseConnection (com.adaptris.core.jdbc.DatabaseConnection)20 Test (org.junit.Test)20 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 AdvancedJdbcPooledConnection (com.adaptris.core.jdbc.AdvancedJdbcPooledConnection)3 JdbcConnection (com.adaptris.core.jdbc.JdbcConnection)3 JdbcPooledConnection (com.adaptris.core.jdbc.JdbcPooledConnection)3 Connection (java.sql.Connection)3 NullService (com.adaptris.core.NullService)2 ServiceException (com.adaptris.core.ServiceException)2 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1 TimeInterval (com.adaptris.util.TimeInterval)1