You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by Peter Andersen <pa...@lenio.dk> on 2008/10/15 11:37:29 UTC

maven-jmeter-plugin call to jmeter leaking threads

Hi

Using jmeter from maven-jmeter-plugin as sugested on:

http://jlorenzen.blogspot.com/2008_03_01_archive.html

The problem is that maven hang after the test has ended.

Some debugging shows that the maven-jmeter-plugin call to jmeter  
course jmeter to leak threads,
I have done the following change to the maven-jmeter-plugin that fixes  
the problem, using checkForEndOfTest method below.

Hope someone can use this to improve the plugin.

--
Med venlig hilsen / Best Regards
Peter Andersen
pan@lenio.dk
Lenio A/S
+45 3061 0012

Code changes to org.apache.jmeter.JMeterMojo.java:

	private void executeTest(File test) throws MojoExecutionException {
		/...	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;
	}






---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org


Re: maven-jmeter-plugin call to jmeter leaking threads

Posted by sebb <se...@gmail.com>.
The JMeter Maven plugin is not a part of JMeter; as far as I can tell
it originates here:

http://wiki.apache.org/jakarta-jmeter/JMeterMavenPlugin

I'm not sure if it is maintained anywhere else.

I suggest adding the proposed fixes to the Wiki page - anyone can
create a login and edit these (that's how the plugin was added).

On 15/10/2008, Peter Andersen <pa...@lenio.dk> wrote:
> Hi
>
>  Using jmeter from maven-jmeter-plugin as sugested on:
>
>  http://jlorenzen.blogspot.com/2008_03_01_archive.html
>
>  The problem is that maven hang after the test has ended.
>
>  Some debugging shows that the maven-jmeter-plugin call to jmeter course
> jmeter to leak threads,
>  I have done the following change to the maven-jmeter-plugin that fixes the
> problem, using checkForEndOfTest method below.
>
>  Hope someone can use this to improve the plugin.
>
>  --
>  Med venlig hilsen / Best Regards
>  Peter Andersen
>  pan@lenio.dk
>  Lenio A/S
>  +45 3061 0012
>
>  Code changes to org.apache.jmeter.JMeterMojo.java:
>
>         private void executeTest(File test) throws MojoExecutionException {
>                 /...    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;
>         }
>
>
>
>
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail:
> jmeter-dev-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail:
> jmeter-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org