Search in sources :

Example 1 with PooledDataSource

use of org.spf4j.pool.jdbc.PooledDataSource in project spf4j by zolyfarkas.

the class JdbcSemaphoreTest method testSingleProcess.

@Test
@SuppressFBWarnings("AFBR_ABNORMAL_FINALLY_BLOCK_RETURN")
public void testSingleProcess() throws SQLException, IOException, InterruptedException, TimeoutException, ObjectCreationException, ObjectDisposeException {
    JdbcDataSource hds = new JdbcDataSource();
    hds.setURL("jdbc:h2:mem:test" + MEM_IDX.getAndIncrement() + ";DB_CLOSE_DELAY=-1");
    hds.setUser("sa");
    hds.setPassword("sa");
    PooledDataSource ds = createPooledDS(hds);
    createSchemaObjects(ds);
    try (Connection conn = ds.getConnection()) {
        // only to keep the schema arround in thsi section
        JdbcHeartBeat heartbeat = JdbcHeartBeat.getHeartBeatAndSubscribe(ds, HeartBeatTableDesc.DEFAULT, (JdbcHeartBeat.LifecycleHook) null);
        try {
            long lb = heartbeat.getLastRunDB();
            LOG.debug("last TS = {}", Instant.ofEpochMilli(lb));
            heartbeat.beat();
            testReleaseAck(ds, "testSem", 2);
            testReleaseAck(ds, "testSem2", 2);
        } finally {
            heartbeat.close();
        }
    } finally {
        ds.close();
    }
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) PooledDataSource(org.spf4j.pool.jdbc.PooledDataSource) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Connection (java.sql.Connection)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 Test (org.junit.Test)1 PooledDataSource (org.spf4j.pool.jdbc.PooledDataSource)1