use of org.adbcj.Connection in project adbcj by mheath.
the class ConnectSpecialCaseTest method testConnectBadCredentials.
@Parameters({ "url", "user", "password" })
@Test(timeOut = 60000)
public void testConnectBadCredentials(String url, String user, String password) throws InterruptedException {
final boolean[] callbacks = { false };
final CountDownLatch latch = new CountDownLatch(1);
ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager(url, user, "__BADPASSWORD__");
try {
DbFuture<Connection> connectFuture = connectionManager.connect().addListener(new DbListener<Connection>() {
public void onCompletion(DbFuture<Connection> future) throws Exception {
callbacks[0] = true;
latch.countDown();
}
});
try {
connectFuture.get();
fail("Connect should have failed because of bad credentials");
} catch (DbException e) {
assertTrue(connectFuture.isDone(), "Connect future should be marked done even though it failed");
assertTrue(!connectFuture.isCancelled(), "Connect future should not be marked as cancelled");
}
assertTrue(latch.await(1, TimeUnit.SECONDS), "Callback was not invoked in time");
assertTrue(callbacks[0], "Connect future callback was not invoked with connect failure");
} finally {
connectionManager.close(true);
}
}
use of org.adbcj.Connection in project adbcj by mheath.
the class ConnectTest method testConnectImmediateClose.
public void testConnectImmediateClose() throws Exception {
final boolean[] callbacks = { false, false };
final CountDownLatch latch = new CountDownLatch(2);
DbFuture<Connection> connectFuture = connectionManager.connect().addListener(new DbListener<Connection>() {
public void onCompletion(DbFuture<Connection> future) throws Exception {
// Indicate that callback has been invoked
callbacks[0] = true;
latch.countDown();
}
});
Connection connection = connectFuture.get(5, TimeUnit.SECONDS);
assertTrue(!connection.isClosed());
DbFuture<Void> closeFuture = connection.close(true).addListener(new DbListener<Void>() {
public void onCompletion(DbFuture<Void> future) throws Exception {
// Indicate that callback has been invoked
callbacks[1] = true;
latch.countDown();
}
});
closeFuture.get(5, TimeUnit.SECONDS);
assertTrue(connection.isClosed());
latch.await(1, TimeUnit.SECONDS);
assertTrue(callbacks[0], "Callback on connection future was not invoked");
assertTrue(callbacks[1], "Callback on finalizeClose future was not invoked");
}
use of org.adbcj.Connection 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.Connection in project adbcj by mheath.
the class ConnectTest method testConnectNonImmediateClose.
public void testConnectNonImmediateClose() throws DbException, InterruptedException {
final boolean[] callbacks = { false };
final CountDownLatch latch = new CountDownLatch(1);
Connection connection = connectionManager.connect().get();
assertTrue(!connection.isClosed());
connection.close(true).addListener(new DbListener<Void>() {
public void onCompletion(DbFuture<Void> future) throws Exception {
// Indicate that finalizeClose callback has been invoked
callbacks[0] = true;
latch.countDown();
}
}).get();
assertTrue(connection.isClosed());
latch.await(1, TimeUnit.SECONDS);
assertTrue(callbacks[0], "Callback on finalizeClose future was not invoked");
}
use of org.adbcj.Connection in project adbcj by mheath.
the class SelectTest method testMultipleSelectStatements.
public void testMultipleSelectStatements() throws Exception {
Connection connection = connectionManager.connect().get();
List<DbFuture<ResultSet>> futures = new LinkedList<DbFuture<ResultSet>>();
for (int i = 0; i < 1000; i++) {
futures.add(connection.executeQuery(String.format("SELECT *, %d FROM simple_values", i)));
}
for (DbFuture<ResultSet> future : futures) {
try {
future.get(5, TimeUnit.MINUTES);
} catch (TimeoutException e) {
throw new AssertionError("Timed out waiting on future: " + future);
}
}
}
Aggregations