use of org.adbcj.DbSessionFuture in project adbcj by mheath.
the class ConnectTest method testNonImmediateClose.
public void testNonImmediateClose() throws Exception {
Connection connection = connectionManager.connect().get();
List<DbSessionFuture<ResultSet>> futures = new ArrayList<DbSessionFuture<ResultSet>>();
for (int i = 0; i < 5; i++) {
futures.add(connection.executeQuery(String.format("SELECT *, %d FROM simple_values", i)));
}
try {
connection.close(false).get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
for (DbSessionFuture<ResultSet> future : futures) {
if (future.isDone()) {
// Will throw exception if failed
future.get();
} else {
throw new AssertionError("future " + future + " did not complete in time");
}
}
throw new AssertionError("finalizeClose future failed to complete");
}
assertTrue(connection.isClosed(), "Connection should be closed");
for (DbSessionFuture<ResultSet> future : futures) {
assertTrue(future.isDone(), "Request did not finish before connection was closed: " + future);
assertFalse(future.isCancelled(), "Future was cancelled and should have been");
}
}
use of org.adbcj.DbSessionFuture in project adbcj by mheath.
the class ConnectSpecialCaseTest method testImmediateClose.
// @Parameters({"url", "user", "password"})
// @Test(timeOut=60000)
// public void testConnectCancel(String url, String user, String password) throws Exception {
// StringBuilder urlBuilder = new StringBuilder();
//
// URI connectUrl = new URI(url);
// String scheme = connectUrl.getScheme();
// while (scheme != null) {
// urlBuilder.append(scheme).append(":");
// connectUrl = new URI(connectUrl.getSchemeSpecificPart());
// scheme = connectUrl.getScheme();
// }
//
// urlBuilder.append("//").append(UNREACHABLE_HOST);
// urlBuilder.append(connectUrl.getPath());
//
// final boolean[] callbacks = {false};
// final CountDownLatch latch = new CountDownLatch(1);
//
// ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager(urlBuilder.toString(), "dummyuser", "dummypassword");
// try {
// DbFuture<Connection> connectFuture = connectionManager.connect().addListener(new DbListener<Connection>() {
// public void onCompletion(DbFuture<Connection> future) throws Exception {
// callbacks[0] = true;
// latch.countDown();
// }
// });
// assertTrue(connectFuture.cancel(true), "Connection to unreachable host was not canceled");
// assertTrue(connectFuture.isCancelled());
// assertTrue(latch.await(1, TimeUnit.SECONDS), "Callback was not invoked in time");
// assertTrue(callbacks[0], "Connect future callback was not invoked with connect cancellation");
// } finally {
// connectionManager.finalizeClose(true);
// }
// }
@Parameters({ "url", "user", "password" })
@Test(timeOut = 60000)
public void testImmediateClose(String url, String user, String password) throws InterruptedException {
ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager(url, user, password);
try {
Connection lockingConnection = connectionManager.connect().get();
connectionManager.setPipeliningEnabled(false);
Connection connection = connectionManager.connect().get();
lockingConnection.beginTransaction();
TestUtils.selectForUpdate(lockingConnection).get();
List<DbSessionFuture<ResultSet>> futures = new ArrayList<DbSessionFuture<ResultSet>>();
connection.beginTransaction();
TestUtils.selectForUpdate(connection);
for (int i = 0; i < 5; i++) {
futures.add(connection.executeQuery(String.format("SELECT *, %d FROM simple_values", i)));
}
logger.debug("Closing connection");
connection.close(true).get();
logger.debug("Closed");
logger.debug("Closing locking connection");
lockingConnection.rollback().get();
lockingConnection.close(true).get();
logger.debug("Locking connection finalizeClose");
assertTrue(connection.isClosed(), "Connection should be closed");
for (DbSessionFuture<ResultSet> future : futures) {
assertTrue(future.isCancelled(), "Future should have been cancelled at finalizeClose: " + future);
assertTrue(future.isDone(), "Request did not finish before connection was closed: " + future);
}
} finally {
connectionManager.close(true).get();
}
}
Aggregations