Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Wiki Markup
    Run all JMeter tests. */
    	publicprivate void executeexecuteTest(File test) throws [MojoExecutionException], [MojoFailureException] \{ initSystemProps(); try \{
    			[DirectoryScanner] scanner = new [DirectoryScanner]();
    			scanner.setBasedir(srcDir);
    			scanner.setIncludes(includes == null ? new String\[\] \{ "\*\*/\*.jmx" \}
    					: includes.toArray(new String\[\] \{\}));
    			if (excludes != null) \{
    				scanner.setExcludes(excludes.toArray(new String\[\] \{\}));
    			\}
    			scanner.scan();
    			for (String file : scanner.getIncludedFiles()) \{
    				executeTest(new File(srcDir, file));
    			\}
    			checkForErrors(); \} finally \{
    			saveServiceProps.delete(); \}
    	\} \{
                    /...    cut out from mail
                            try \{
                                    // This mess is necessary because the only way to know when JMeter
                                    // is done is to wait for all of the threads that it spawned to exit.
                                    new JMeter().start(args.toArray(new String\[\]\{\}));
                                    [BufferedReader] in = new [BufferedReader](new [FileReader](jmeterLog));
                                    while (!checkForEndOfTest(in)) \{
                                            try \{
                                                    Thread.sleep(1000);
                                            \} catch (InterruptedException e) \{
                                                    break;
                                            \}
                                    \}
                                    in.close();
                            \} catch (ExitException e) \{
                                    if (e.getCode() != 0) \{
                                            throw new [MojoExecutionException]("Test failed", e);
                                    \}
                            \} finally \{
                                    System.setSecurityManager(oldManager);
                                    Thread.setDefaultUncaughtExceptionHandler(oldHandler);
                            \}
                    \} catch (IOException e) \{
                            throw new [MojoExecutionException]("Can't execute test", e);
                    \}
            \}
    \\
            private boolean checkForEndOfTest(BufferedReader in) throws [MojoExecutionException] \{
                    boolean testEnded = false;
                    try \{
                            String line;
                            while ( (line = in.readLine()) != null) \{
                                    if (line.indexOf("Test has ended") != -1) \{
                                            testEnded = true;
                                            break;
                                    \}
                            \}
                    \} catch (IOException e) \{
                            throw new [MojoExecutionException]("Can't read log file", e);
                    \}
                    return testEnded;
            \}
    \\

private void checkForErrors() throws MojoExecutionException, MojoFailureException { try {
BufferedReader in = new BufferedReader(new FileReader(jmeterLog));
String line;
while ( (line = in.readLine()) != null) {
if (PAT_ERROR.matcher(line).find()) {
throw new MojoFailureException("There were test errors");
}
}
in.close(); } catch (IOException e) {
throw new MojoExecutionException("Can't read log file", e); }
}

...