示例#1
0
  public void test_prepCall() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt =
          conn.prepareCall(
              "SELECT 1",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY,
              ResultSet.HOLD_CURSORS_OVER_COMMIT);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt =
          conn.prepareCall(
              "SELECT 1",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY,
              ResultSet.HOLD_CURSORS_OVER_COMMIT);
      Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.close();
  }
  public void test_error_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setPoolPreparedStatements(false);
  }
  public void test_setConnectionInitSqls() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setConnectionInitSqls(null);
  }
  public void test_change_connectProperties_2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setConnectionProperties("x=12;;");
  }
  public void test_getValidConnectionCheckerClassName() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.getValidConnectionCheckerClassName();
  }
  public void test_error_6() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setMaxActive(1);
  }
示例#7
0
  public void test_prepCall_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt =
          conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt =
          conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.getConnectionHolder().toString();
    conn.getConnectionHolder().setLastActiveTimeMillis(0);
    conn.getConnectionHolder().toString();
    conn.getConnectionHolder().getUseCount();
    conn.getConnectionHolder().getTimeMillis();

    conn.close();
  }
  public void test_change_minIdle() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setMinIdle(1);
  }
  public void test_error_7() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setPassword(dataSource.getPassword());
    dataSource.setPassword("xx");
  }
  @SuppressWarnings("deprecation")
  public void test_error_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setMaxIdle(1);
  }
  public void test_0() throws Exception {
    DruidPooledConnection conn1 = this.dataSource.tryGetConnection();
    Assert.assertNotNull(conn1);

    DruidPooledConnection conn2 = this.dataSource.tryGetConnection();
    Assert.assertNull(conn2);

    conn1.close();
  }
  public void test_setConnectionProperties() throws Exception {
    dataSource.setConnectionProperties(null);
    dataSource.setLogWriter(null);
    dataSource.getLogWriter();

    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();
  }
  public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
      DruidPooledConnection conn = dataSource.getConnection();

      PreparedStatement pstmt = conn.prepareStatement(sql);
      pstmt.execute();
      pstmt.close();
      conn.close();
    }

    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);

    Statement stmt = conn.createStatement();
    stmt.addBatch(sql);

    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);

    SQLException stmtErrror = null;
    try {
      stmt.executeBatch();
    } catch (SQLException ex) {
      stmtErrror = ex;
    }
    Assert.assertNotNull(stmtErrror);
    Assert.assertSame(exception, stmtErrror);

    SQLException commitError = null;
    try {
      conn.commit();
    } catch (SQLException ex) {
      commitError = ex;
    }

    Assert.assertNotNull(commitError);
    Assert.assertSame(exception, commitError.getCause());

    conn.close();
  }
示例#14
0
  public void test_handleException() throws Exception {
    DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
    conn.close();

    SQLException error = new SQLException();
    try {
      conn.handleException(error);
    } catch (SQLException ex) {
      Assert.assertEquals(error, ex);
    }
  }
示例#15
0
  public void test_checkOpen_error() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();
    {
      Exception error = null;
      try {
        conn.checkState();
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
示例#16
0
  public void test_setClientInfo_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.close();

    {
      SQLException error = null;
      try {
        conn.setClientInfo(new Properties());
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
示例#17
0
  public void test_removeStatementEventListener() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();
    {
      Exception error = null;
      try {
        conn.removeStatementEventListener(null);
      } catch (IllegalStateException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
  public void test_error_10() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    {
      Exception error = null;
      try {
        dataSource.addConnectionProperty("x", "11");
      } catch (Exception ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
示例#19
0
  public void test_prepareStatement_error5() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    {
      SQLException error = null;
      try {
        conn.prepareStatement(null, new int[0]);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
  public void test_error_12() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    {
      Exception error = null;
      try {
        dataSource.setDriverClassName("");
      } catch (Exception ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
  public void test_prepareStatement_error() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    {
      Exception error = null;
      try {
        dataSource.setUsername("xxx");
      } catch (Exception ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
示例#22
0
  public void test_basic() throws Exception {
    DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
    conn.close();

    Assert.assertEquals(true, dataSource.isResetStatEnable());
    dataSource.setResetStatEnable(false);
    Assert.assertEquals(false, dataSource.isResetStatEnable());
    Assert.assertEquals(1, dataSource.getConnectCount());
    dataSource.resetStat();
    Assert.assertEquals(1, dataSource.getConnectCount());

    dataSource.setResetStatEnable(true);
    dataSource.resetStat();
    Assert.assertEquals(0, dataSource.getConnectCount());
  }
示例#23
0
  public void test_releaseSavepoint_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getConnection().close();
    {
      SQLException error = null;
      try {
        conn.releaseSavepoint(null);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
示例#24
0
  public void test_create_2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getConnection().close();
    {
      SQLException error = null;
      try {
        conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
示例#25
0
  public void test_preCall_error_2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getConnection().close();
    {
      SQLException error = null;
      try {
        conn.prepareCall("SELECT 1");
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
示例#26
0
  public void test_preCall_error_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getConnection().close();
    {
      SQLException error = null;
      try {
        conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
示例#27
0
  public void test_handleException_2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.getConnection().close();

    {
      SQLException error = null;
      try {
        conn.handleException(new RuntimeException());
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
  public void test_error_5() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.close();

    dataSource.setInitialSize(dataSource.getInitialSize());

    {
      Exception error = null;
      try {
        dataSource.setInitialSize(10);
      } catch (Exception ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }
  }
示例#29
0
  public void test_prepareStatement_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
      Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.close();
  }
示例#30
0
  public void test_setAutoCommit() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getAutoCommit();
    conn.setAutoCommit(true);
    conn.getConnection().close();
    {
      SQLException error = null;
      try {
        conn.setAutoCommit(false);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }