コード例 #1
0
ファイル: RunStyleSelenium.java プロジェクト: hammoum/gwt
 /**
  * Get the display list of specifiers for threads that did not complete.
  *
  * @param threads the list of threads
  * @return a list of specifiers
  */
 private <T extends SeleniumThread> String getIncompleteSpecifierList(List<T> threads) {
   String list = "";
   for (SeleniumThread thread : threads) {
     if (!thread.isComplete()) {
       list += "  " + thread.getRemote().getSpecifier() + "\n";
     }
   }
   return list;
 }
コード例 #2
0
ファイル: RunStyleSelenium.java プロジェクト: hammoum/gwt
  /**
   * Iterate over a list of {@link SeleniumThread}s, waiting for them to finish.
   *
   * @param <T> the thread type
   * @param threads the list of threads
   * @param fatalExceptions true to treat all exceptions as errors, false to treat exceptions as
   *     warnings
   * @param action the action being performed by the thread
   * @param sleepTime the amount of time to sleep in milliseconds
   * @throws UnableToCompleteException if the thread times out and fatalExceptions is true
   */
  private <T extends SeleniumThread> void waitForThreadsToComplete(
      List<T> threads, boolean fatalExceptions, String action, int sleepTime)
      throws UnableToCompleteException {
    boolean allComplete;
    long endTime = System.currentTimeMillis() + LAUNCH_TIMEOUT;
    do {
      try {
        Thread.sleep(sleepTime);
      } catch (InterruptedException e) {
        // This should not happen.
        throw new UnableToCompleteException();
      }

      allComplete = true;
      synchronized (lock) {
        for (SeleniumThread thread : threads) {
          if (!thread.isComplete()) {
            allComplete = false;
          }
        }
      }

      // Check if we have timed out.
      if (!allComplete && endTime < System.currentTimeMillis()) {
        allComplete = true;
        String message =
            "The following Selenium instances did not "
                + action
                + " within "
                + LAUNCH_TIMEOUT
                + "ms:\n";
        synchronized (lock) {
          message += getIncompleteSpecifierList(threads);
        }
        if (fatalExceptions) {
          shell.getTopLogger().log(TreeLogger.ERROR, message);
          throw new UnableToCompleteException();
        } else {
          shell.getTopLogger().log(TreeLogger.WARN, message);
        }
      }
    } while (!allComplete);
  }