Package org.adbcj

Examples of org.adbcj.ConnectionManager


  @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);
    }
  }
View Full Code Here


//  }

  @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();
    }
  }
View Full Code Here

*
*/
public class PopulateLarge {

  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();
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) throws Exception {
    ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager("adbcj:mysql://localhost/adbcjtck", "adbcjtck", "adbcjtck");

    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 close future was not invoked");

    connectionManager.close(true);
  }
View Full Code Here


public class Test {

  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);
  }
View Full Code Here

   * @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");
  }
View Full Code Here

   * @param args
   * @throws InterruptedException
   * @throws DbException
   */
  public static void main(String[] args) throws DbException, InterruptedException {
    ConnectionManager cm = ConnectionManagerProvider.createConnectionManager("adbcj:postgresql-mina://localhost/adbcjtck", "adbcjtck", "adbcjtck");
    Connection connection = cm.connect().get();
 
    final ResultSet rs = connection.executeQuery("SELECT * FROM large").get();
    for (Row row : rs) {
      System.out.println(row.get(0) + " " + row.get(1));
    }
    cm.close(true).get();
  }
View Full Code Here

TOP

Related Classes of org.adbcj.ConnectionManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.