/**
   * This method tests the functionality of connection in high stress.
   *
   * @throws Exception if any error occurs.
   */
  public void testStressForConnection() throws Exception {

    long startTime = System.currentTimeMillis();

    for (int i = 0; i < COUNT; ++i) {
      Connection conn = null;
      try {
        conn =
            new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection();
        conn.setAutoCommit(false);
        StressHelper.doDMLQuery(conn, QUERY1, new Object[] {});
        persistence.closeConnection(conn);
        assertTrue("Fails to close the connection.", conn.isClosed());
        conn =
            new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection();
        conn.setAutoCommit(true);
        Object[][] rows =
            StressHelper.doQuery(
                conn, QUERY2, new Object[] {}, new DataType[] {StressHelper.STRING_TYPE});
        assertEquals("Fails to commit the changes in database.", "property 1", rows[0][0]);
        StressHelper.doDMLQuery(conn, QUERY3, new Object[] {});
        conn.close();
      } finally {
        if (conn != null && !conn.isClosed()) {
          conn.close();
        }
      }
    }

    long endTime = System.currentTimeMillis();
    System.out.println(
        "The stress test for connection costs: " + (endTime - startTime) + " milliseconds.");
  }
  /**
   * This method tests the functionality of connection with failure in high stress.
   *
   * @throws Exception if any error occurs.
   */
  public void testStressForConnectionWithFailure() throws Exception {

    long startTime = System.currentTimeMillis();

    for (int i = 0; i < COUNT; ++i) {
      Connection conn = null;
      try {

        conn =
            new DBConnectionFactoryImpl(DBConnectionFactoryImpl.class.getName()).createConnection();
        conn.setAutoCommit(true);
        persistence.closeConnection(conn);
        fail("PersistenceException is expected");

      } catch (PersistenceException pe) {
        // expect

      } finally {
        if (conn != null && !conn.isClosed()) {
          conn.close();
        }
      }
    }

    long endTime = System.currentTimeMillis();
    System.out.println(
        "The stress test for connection with failure costs: "
            + (endTime - startTime)
            + " milliseconds.");
  }