예제 #1
0
  public boolean runTestPlan(String testPlanFilename) {

    jmeterResults = "";
    createJmeterEngine();
    File f = new File(testPlanFilename);
    if (!f.exists() || !f.isFile()) {
      jmeterResults += "Could not open " + testPlanFilename;
      System.out.println(jmeterResults);
      return false;
    }

    FileInputStream reader = null;
    try {
      reader = new FileInputStream(new File(testPlanFilename));
      currentHashTree = SaveService.loadTree(reader);
      // store log file in ./FitNesseRoot/files/testResults/testPlanFilename.log
      String logFile =
          new File(jmeterLogPath, (new File(testPlanFilename).getName() + ".log"))
              .getCanonicalPath();
      lastJmeterLog = logFile;

      @SuppressWarnings("deprecation") // Deliberate use of deprecated ctor
      JMeterTreeModel treeModel =
          new JMeterTreeModel(new Object()); // Create non-GUI version to avoid headless problems
      JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();
      treeModel.addSubTree(currentHashTree, root);

      // Hack to resolve ModuleControllers in non GUI mode
      SearchByClass<ReplaceableController> replaceableControllers =
          new SearchByClass<ReplaceableController>(ReplaceableController.class);
      currentHashTree.traverse(replaceableControllers);
      Collection<ReplaceableController> replaceableControllersRes =
          replaceableControllers.getSearchResults();
      for (Iterator<ReplaceableController> iter = replaceableControllersRes.iterator();
          iter.hasNext(); ) {
        ReplaceableController replaceableController = iter.next();
        replaceableController.resolveReplacementSubTree(root);
      }

      // Remove the disabled items
      // For GUI runs this is done in Start.java
      JMeter.convertSubTree(currentHashTree);

      Summariser summer = null;
      String summariserName =
          JMeterUtils.getPropDefault("summariser.name", "summary"); // $NON-NLS-1$
      if (summariserName.length() > 0) {
        // log.info("Creating summariser <" + summariserName + ">");
        // println("Creating summariser <" + summariserName + ">");
        summer = new Summariser(summariserName);
      }

      if (logFile != null) {
        ResultCollector logger = new ResultCollector(summer);
        logger.setFilename(logFile);
        currentHashTree.add(currentHashTree.getArray()[0], logger);
      } else {
        // only add Summariser if it can not be shared with the ResultCollector
        if (summer != null) {
          currentHashTree.add(currentHashTree.getArray()[0], summer);
        }
      }

      // Used for remote notification of threads start/stop,see BUG 54152
      // Summariser uses this feature to compute correctly number of threads
      // when NON GUI mode is used
      currentHashTree.add(currentHashTree.getArray()[0], new RemoteThreadsListenerTestElement());

      jEngine.configure(currentHashTree);
      jEngine.runTest();
      // reader.close();
      JOrphanUtils.closeQuietly(reader);
      Util.waitForFileToExists(logFile, 5); // wait up to 5 seconds for file to exist
      String logStr = Util.fileToString(logFile);
      // logStr = logStr.replaceAll("\n", "<br/>\n");
      jmeterResults += logStr;
      jmeterResults += "Test " + testPlanFilename + " completed.";
      System.out.println("Test " + testPlanFilename + " completed.");

    } catch (Exception e) {
      e.printStackTrace();
      jmeterResults += "\r\nException: " + e.getMessage();
      return false;
    }
    return true;
  }
예제 #2
0
 public void setJmeterHome(String homePath) {
   jmeterPropertiesFile = homePath;
   jEngine.exit();
   createJmeterEngine();
 }