use of org.h2.jdbcx.JdbcDataSource in project spf4j by zolyfarkas.
the class BadSemaphoreHandler method main.
public static void main(final String[] args) throws InterruptedException, TimeoutException, SQLException {
String connectionString = args[0];
String semaphoreName = args[1];
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connectionString);
ds.setUser("sa");
ds.setPassword("sa");
JdbcSemaphore semaphore = new JdbcSemaphore(ds, semaphoreName, 3);
semaphore.acquire(1, 1L, TimeUnit.SECONDS);
System.exit(0);
}
use of org.h2.jdbcx.JdbcDataSource in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testMultiProcess2.
@Test
public void testMultiProcess2() throws SQLException, IOException, InterruptedException, ExecutionException, TimeoutException {
int port = PORT.getAndIncrement();
Server server = Server.createTcpServer(new String[] { "-tcpPort", Integer.toString(port), "-ifNotExists" }).start();
try {
File tempDB = File.createTempFile("test", "h2db");
tempDB.deleteOnExit();
String connStr = "jdbc:h2:tcp://localhost:" + port + "/nio:" + tempDB.getAbsolutePath() + ";AUTO_SERVER=TRUE";
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connStr);
ds.setUser("sa");
ds.setPassword("sa");
createSchemaObjects(ds);
JdbcSemaphore semaphore = new JdbcSemaphore(ds, "test_sem2", 1, true);
String o1 = org.spf4j.base.Runtime.jrun(DecentSemaphoreHandler.class, 10000000, connStr, "test_sem2").toString();
String o2 = org.spf4j.base.Runtime.jrun(DecentSemaphoreHandler.class, 10000000, connStr, "test_sem2").toString();
Assert.assertTrue(semaphore.tryAcquire(1, TimeUnit.SECONDS));
Assert.assertFalse(semaphore.tryAcquire(10, TimeUnit.SECONDS));
LOG.debug("P1: {}", o1);
LOG.debug("P2: {}", o2);
String[] nr1 = o1.split("\n");
String[] nr2 = o2.split("\n");
int totatl = nr1.length + nr2.length;
Set<String> numbers = new HashSet<>(totatl);
numbers.addAll(Arrays.asList(nr1));
numbers.addAll(Arrays.asList(nr2));
Assert.assertEquals(totatl, numbers.size());
} finally {
JdbcHeartBeat.stopHeartBeats();
server.shutdown();
}
}
Aggregations