Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit ef82324

Browse files
pavelbucekGerrit Code Review
authored andcommitted
Merge "J-577: Improved error message + increased the minimal heap size for Tomcat of shutdown hook leak test."
2 parents cd29515 + 9baa815 commit ef82324

File tree

4 files changed

+102
-24
lines changed

4 files changed

+102
-24
lines changed

test-framework/maven/container-runner-maven-plugin/src/main/groovy/org/glassfish/jersey/test/maven/runner/RunnerMojo.groovy

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*/
4040
package org.glassfish.jersey.test.maven.runner
4141

42-
import org.apache.maven.plugin.Mojo
42+
import com.google.common.collect.EvictingQueue
4343
import org.apache.maven.plugin.MojoExecutionException
4444
import org.apache.maven.plugin.MojoFailureException
4545
import org.apache.maven.plugins.annotations.Parameter
@@ -54,7 +54,7 @@ import java.util.regex.Pattern
5454
*
5555
* @author Stepan Vavra (stepan.vavra at oracle.com)
5656
*/
57-
trait RunnerMojo implements Mojo {
57+
trait RunnerMojo implements SuperRunnerMojo {
5858

5959
/**
6060
* The Maven project to analyze.
@@ -106,7 +106,10 @@ trait RunnerMojo implements Mojo {
106106
@Parameter(defaultValue = "false", name = "skipStartAndStop", property = "jersey.runner.skipStartAndStop")
107107
boolean skipStartAndStop
108108

109-
@Parameter(defaultValue = "\${project.build.directory}/tmp")
109+
/**
110+
* The location of a directory where a content of executed shell scripts is dumped.
111+
*/
112+
@Parameter(defaultValue = "\${project.build.directory}/tmp", name = "scriptsDirectory")
110113
String scriptsDirectory
111114

112115
/**
@@ -179,9 +182,10 @@ trait RunnerMojo implements Mojo {
179182
outputStream.write(shellContent)
180183
outputStream.close()
181184

182-
def lastLine = ""
185+
def lastLinesQueue = EvictingQueue.<String>create(lastLinesCount)
186+
183187
process.in.eachLine {
184-
lastLine = it
188+
lastLinesQueue.add(it)
185189
if (getLog()?.isDebugEnabled() && it.startsWith("+")) {
186190
getLog().debug(it)
187191
} else {
@@ -194,7 +198,7 @@ trait RunnerMojo implements Mojo {
194198
if (process.exitValue() != 0 && exceptionOnError) {
195199
throw new ShellMojoExecutionException("The shell script: '" + shell + "' ended with non-zero exit value!",
196200
process.exitValue(),
197-
lastLine)
201+
lastLinesQueue)
198202
}
199203

200204
return process.exitValue()

test-framework/maven/container-runner-maven-plugin/src/main/groovy/org/glassfish/jersey/test/maven/runner/ShellMojoExecutionException.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
*/
4040
package org.glassfish.jersey.test.maven.runner;
4141

42+
import java.util.Collection;
43+
4244
import org.apache.maven.plugin.MojoExecutionException;
4345

4446
/**
@@ -51,35 +53,44 @@ public class ShellMojoExecutionException extends MojoExecutionException {
5153
/**
5254
* The error code the shell script exited with.
5355
*/
54-
private int errorCode;
56+
private final int errorCode;
5557

5658
/**
57-
* The last line of the output of the executed shell script.
59+
* The last lines of the output of the executed shell script.
5860
*/
59-
private String lastLine;
60-
61-
public ShellMojoExecutionException(final String message, final Throwable cause, final int errorCode, final String lastLine) {
62-
super(message
63-
+ "\nError exit code: " + errorCode + "."
64-
+ "\nThe last line of stderr/stdout output is: " + lastLine,
65-
cause);
66-
this.errorCode = errorCode;
67-
this.lastLine = lastLine;
68-
}
61+
private final Collection<String> lastLines;
6962

70-
public ShellMojoExecutionException(final String message, final int errorCode, final String lastLine) {
63+
/**
64+
* Constructs shell mojo exection exception.
65+
*
66+
* @param message The message that will be prepended to a default mojo exectuion exception message.
67+
* @param errorCode The error code.
68+
* @param lastLines The collection of last lines that will be also part of the exception message.
69+
*/
70+
public ShellMojoExecutionException(final String message, final int errorCode, final Collection<String> lastLines) {
7171
super(message
7272
+ "\nError exit code: " + errorCode + "."
73-
+ "\nThe last line of stderr/stdout output is: " + lastLine);
73+
+ "\nThe last " + lastLines.size() + " lines of stderr/stdout output are: "
74+
+ "\n" + lastLinesToString(lastLines));
7475
this.errorCode = errorCode;
75-
this.lastLine = lastLine;
76+
this.lastLines = lastLines;
7677
}
7778

7879
public int getErrorCode() {
7980
return errorCode;
8081
}
8182

82-
public String getLastLine() {
83-
return lastLine;
83+
public Collection<String> getLastLines() {
84+
return lastLines;
85+
}
86+
87+
private static String lastLinesToString(Collection<String> collection) {
88+
StringBuilder sb = new StringBuilder();
89+
int lineNumber = 1;
90+
for (String string : collection) {
91+
sb.append("Line ").append(lineNumber++).append(": ");
92+
sb.append(string).append("\n");
93+
}
94+
return sb.toString();
8495
}
8596
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.test.maven.runner
42+
43+
import org.apache.maven.plugin.Mojo
44+
import org.apache.maven.plugins.annotations.Parameter
45+
46+
/**
47+
* This trait serves as a field container only as a workaround for failing Traits with more than 10 fields (see
48+
* http://stackoverflow.com/questions/27259633/using-groovy-trait-in-grails-test-fails)
49+
*
50+
* @author Stepan Vavra (stepan.vavra at oracle.com)
51+
*/
52+
trait SuperRunnerMojo implements Mojo {
53+
54+
/**
55+
* The number of lines of stderr/stdout to print when an execution failure occurs.
56+
*/
57+
@Parameter(defaultValue = "10", name = "lastLinesCount")
58+
int lastLinesCount
59+
60+
void setLastLinesCount(final int lastLinesCount) {
61+
this.lastLinesCount = lastLinesCount
62+
}
63+
}

tests/mem-leaks/test-cases/shutdown-hook-leak/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<properties>
5858
<memleak.jvm.maxheap>128m</memleak.jvm.maxheap>
59-
<memleak.tomcat.maxheap>64m</memleak.tomcat.maxheap>
59+
<memleak.tomcat.maxheap>128m</memleak.tomcat.maxheap>
6060
<memleak.test.timeout>120000</memleak.test.timeout>
6161
</properties>
6262

0 commit comments

Comments
 (0)