use of org.adbcj.ConnectionManager 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.ConnectionManager in project adbcj by mheath.
the class PgTest method main.
/**
* @param args
* @throws InterruptedException
* @throws org.adbcj.DbException
*/
public static void main(String[] args) throws DbException, InterruptedException {
ConnectionManager cm = ConnectionManagerProvider.createConnectionManager("adbcj:postgresql-netty://localhost/adbcjtck", "adbcjtck", "adbcjtck");
Connection connection = cm.connect().get();
final DbFuture<ResultSet> future = connection.executeQuery("SELECT * FROM simple_values");
final DbFuture<ResultSet> future2 = connection.executeQuery("SELECT * FROM large");
ResultSet rs = future.get();
ResultSet rs2 = future2.get();
for (Row row : rs) {
System.out.println(row.get(0) + " " + row.get(1));
}
for (Row row : rs2) {
System.out.println(row.get(0) + " " + row.get(1));
}
connection.close(true).get();
cm.close(true).get();
System.out.println("Closed");
}
use of org.adbcj.ConnectionManager in project adbcj by mheath.
the class PopulateLarge method main.
public static void main(String[] args) throws Exception {
ConnectionManager mysqlCM = ConnectionManagerProvider.createConnectionManager("adbcj:mysqlnetty://localhost/adbcjtck", "adbcjtck", "adbcjtck");
ConnectionManager pgCM = ConnectionManagerProvider.createConnectionManager("adbcj:postgresql-netty://localhost/adbcjtck", "adbcjtck", "adbcjtck");
Connection mysql = mysqlCM.connect().getUninterruptably();
Connection pg = pgCM.connect().getUninterruptably();
final String insertTemplate = "INSERT INTO large (a, b, c) VALUES ('%s', '%s', '%s')";
for (int i = 0; i < 998; i++) {
String a = randString();
String b = randString();
String c = randString();
final String insert = String.format(insertTemplate, a, b, c);
mysql.executeUpdate(insert).get();
pg.executeUpdate(insert).get();
}
// mysql.close(false).get();
// pg.close(false).get();
// mysqlCM.close(true);
// pgCM.close(true);
}
use of org.adbcj.ConnectionManager 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();
}
}
use of org.adbcj.ConnectionManager in project adbcj by mheath.
the class Test method main.
public static void main(String[] args) throws DbException, Exception {
ConnectionManager cm = ConnectionManagerProvider.createConnectionManager("adbcj:mysqlnetty://localhost/test", "foo", "dawg");
Connection connection = cm.connect().get();
connection.close(true);
}
Aggregations