/**
   * 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.");
  }
  /**
   * This method tests the functionality of connection with non-exist name in high stress.
   *
   * @throws Exception if any error occurs.
   */
  public void testStressForConnectionWithNonExistName() throws Exception {

    long startTime = System.currentTimeMillis();

    persistence =
        new MockPersistence("InformixProjectPersistence.CustomNamespace.NoConnectionName");
    for (int i = 0; i < COUNT; ++i) {
      Connection conn = null;
      try {
        conn = persistence.openConnection();
        assertFalse("Fails to initialize the connection.", conn.getAutoCommit());
      } finally {
        if (conn != null) {
          conn.close();
        }
      }
    }

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