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();
}
}
Aggregations