예제 #1
0
  /**
   * DO NOT OVERRIDE.
   *
   * <p>DO NOT DEFINE AN @BeforeMethod Instead, override {@link #beforeMethod()}. If you must
   * override, for example, if you need to use special attributes on your annotation, then ensure
   * you protect the code with and {@link #inContainer()} call.
   */
  @BeforeMethod
  protected void __beforeMethod(Method method) throws Throwable {
    // Note that Arquillian calls the testng BeforeMethod twice (as of 1.0.2.Final, once
    // out of container and once in container. In general the expectation is to execute it
    // one time, and doing it in container allows for the expected injections and context.
    if (inContainer()) {
      try {
        // Make sure we set the db type for tests that may need it (normally done in StartupBean)
        if (null == DatabaseTypeFactory.getDefaultDatabaseType()) {
          Connection conn = null;
          try {
            conn = getConnection();
            DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
          } catch (Exception e) {
            System.err.println(
                "!!! WARNING !!! cannot set default database type, some tests may fail");
            e.printStackTrace();
          } finally {
            if (null != conn) {
              conn.close();
            }
          }
        }

        beforeMethod();
        beforeMethod(method);

      } catch (Throwable t) {
        // Arquillian is eating these, make sure they show up in some way
        System.out.println("BEFORE METHOD FAILURE, TEST DID NOT RUN!!! [" + method.getName() + "]");
        t.printStackTrace();
        throw t;
      }
    }
  }
예제 #2
0
  @BeforeMethod
  public static void startTest() {
    if (DatabaseTypeFactory.getDefaultDatabaseType() == null) {
      try {
        Connection conn = getConnection();
        DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
      } catch (Exception e) {
        System.err.println("!!! WARNING !!! cannot set default database type, some tests may fail");
        e.printStackTrace();
      }
    }

    if (stats != null) start = stats.getQueryExecutionCount();
    else start = 0;
  }
예제 #3
0
  private void initializeServer() {
    // Ensure the class is loaded and the dbType is set for our current db
    Connection conn = null;
    try {
      conn = dataSource.getConnection();
      DatabaseTypeFactory.setDefaultDatabaseType(DatabaseTypeFactory.getDatabaseType(conn));
    } catch (Exception e) {
      log.error("Could not initialize server.", e);
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (Exception e) {
          log.error("Failed to close temporary connection used for server initialization.", e);
        }
      }
    }

    // Ensure that this server is registered in the database.
    createDefaultServerIfNecessary();

    // immediately put the server into MM if configured to do so
    if (ServerCommunicationsServiceUtil.getService().getMaintenanceModeAtStartup()) {
      log.info("Server is configured to start up in MAINTENANCE mode.");
      Server server = serverManager.getServer();
      Integer[] serverId = new Integer[] {server.getId()};
      topologyManager.updateServerMode(
          LookupUtil.getSubjectManager().getOverlord(), serverId, OperationMode.MAINTENANCE);
    }

    // Establish the current server mode for the server. This will move the server to NORMAL
    // mode from DOWN if necessary.  This can also affect comm layer behavior.
    serverManager.establishCurrentServerMode();
    if ("true".equals(System.getProperty("rhq.sync.endpoint-address", "false"))) {
      try {
        serverManager.syncEndpointAddress();
      } catch (SyncEndpointAddressException e) {
        log.error("Failed to sync server endpoint address.", e);
      }
    }
  }