Issue #1743 Ensure tests stop jetty

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2019-10-01 11:29:00 +10:00
parent 5d0032062d
commit 2ef7160418
5 changed files with 35 additions and 6 deletions

View File

@ -14,7 +14,7 @@
<name>Jetty :: Simple :: Webapp</name> <name>Jetty :: Simple :: Webapp</name>
<properties> <properties>
<jetty.port.file>${project.build.directory}/jetty-start-distro-port.txt</jetty.port.file> <jetty.port.file>${project.build.directory}/jetty-start-war-distro-port.txt</jetty.port.file>
<jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs> <jetty.jvmArgs>@jetty.jvmArgs@</jetty.jvmArgs>
<jetty.deployMode>DISTRO</jetty.deployMode> <jetty.deployMode>DISTRO</jetty.deployMode>
</properties> </properties>
@ -80,9 +80,6 @@
<dependenciesToScan> <dependenciesToScan>
<dependency>org.eclipse.jetty:jetty-maven-plugin</dependency> <dependency>org.eclipse.jetty:jetty-maven-plugin</dependency>
</dependenciesToScan> </dependenciesToScan>
<includes>
<include>**/*TestGetContent*</include>
</includes>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -110,6 +107,8 @@
<goal>start-war</goal> <goal>start-war</goal>
</goals> </goals>
<configuration> <configuration>
<stopPort>@jetty.stopPort@</stopPort>
<stopKey>@jetty.stopKey@</stopKey>
<webApp> <webApp>
<!-- starts the assembled webapp by default --> <!-- starts the assembled webapp by default -->
</webApp> </webApp>

View File

@ -16,6 +16,18 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey )
int port = Integer.parseInt( jettyStopPort )
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),port )
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()
File buildLog = new File( basedir, 'build.log' ) File buildLog = new File( basedir, 'build.log' )
assert buildLog.text.contains( 'Distro process starting' ) assert buildLog.text.contains( 'Distro process starting' )
assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent') assert buildLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent')

View File

@ -75,6 +75,8 @@
<goal>start-war</goal> <goal>start-war</goal>
</goals> </goals>
<configuration> <configuration>
<stopPort>@jetty.stopPort@</stopPort>
<stopKey>@jetty.stopKey@</stopKey>
<webApp> <webApp>
<war>${project.build.directory}/${project.artifactId}-${project.version}</war> <war>${project.build.directory}/${project.artifactId}-${project.version}</war>
</webApp> </webApp>

View File

@ -16,6 +16,17 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
System.out.println( "running postbuild.groovy port " + jettyStopPort + ", key:" + jettyStopKey )
int port = Integer.parseInt( jettyStopPort )
Socket s=new Socket(InetAddress.getByName("127.0.0.1"),port )
OutputStream out=s.getOutputStream()
out.write(( jettyStopKey +"\r\nforcestop\r\n").getBytes())
out.flush()
s.close()
File outputLog = new File( basedir, 'build.log' ) File outputLog = new File( basedir, 'build.log' )
assert outputLog.text.contains( 'Forked process starting' ) assert outputLog.text.contains( 'Forked process starting' )
assert outputLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent') assert outputLog.text.contains( 'Running org.eclipse.jetty.maven.plugin.it.IntegrationTestGetContent')

View File

@ -44,14 +44,16 @@ public class TestJettyEmbedder
public void testJettyEmbedderFromDefaults() throws Exception public void testJettyEmbedderFromDefaults() throws Exception
{ {
JettyWebAppContext webApp = new JettyWebAppContext(); JettyWebAppContext webApp = new JettyWebAppContext();
MavenServerConnector connector = new MavenServerConnector();
connector.setPort(0);
JettyEmbedder jetty = new JettyEmbedder(); JettyEmbedder jetty = new JettyEmbedder();
jetty.setHttpConnector(connector);
jetty.setExitVm(false); jetty.setExitVm(false);
jetty.setServer(null); jetty.setServer(null);
jetty.setContextHandlers(null); jetty.setContextHandlers(null);
jetty.setRequestLog(null); jetty.setRequestLog(null);
jetty.setJettyXmlFiles(null); jetty.setJettyXmlFiles(null);
jetty.setHttpConnector(null);
jetty.setJettyProperties(null); jetty.setJettyProperties(null);
jetty.setLoginServices(null); jetty.setLoginServices(null);
jetty.setContextXml(MavenTestingUtils.getTestResourceFile("embedder-context.xml").getAbsolutePath()); jetty.setContextXml(MavenTestingUtils.getTestResourceFile("embedder-context.xml").getAbsolutePath());
@ -86,13 +88,16 @@ public class TestJettyEmbedder
otherHandler.setContextPath("/other"); otherHandler.setContextPath("/other");
otherHandler.setBaseResource(Resource.newResource(MavenTestingUtils.getTestResourceDir("root"))); otherHandler.setBaseResource(Resource.newResource(MavenTestingUtils.getTestResourceDir("root")));
MavenServerConnector connector = new MavenServerConnector();
connector.setPort(0);
JettyEmbedder jetty = new JettyEmbedder(); JettyEmbedder jetty = new JettyEmbedder();
jetty.setHttpConnector(connector);
jetty.setExitVm(false); jetty.setExitVm(false);
jetty.setServer(server); jetty.setServer(server);
jetty.setContextHandlers(Arrays.asList(otherHandler)); jetty.setContextHandlers(Arrays.asList(otherHandler));
jetty.setRequestLog(null); jetty.setRequestLog(null);
jetty.setJettyXmlFiles(Arrays.asList(MavenTestingUtils.getTestResourceFile("embedder-jetty.xml"))); jetty.setJettyXmlFiles(Arrays.asList(MavenTestingUtils.getTestResourceFile("embedder-jetty.xml")));
jetty.setHttpConnector(null);
jetty.setJettyProperties(jettyProperties); jetty.setJettyProperties(jettyProperties);
jetty.setLoginServices(null); jetty.setLoginServices(null);
jetty.setContextXml(MavenTestingUtils.getTestResourceFile("embedder-context.xml").getAbsolutePath()); jetty.setContextXml(MavenTestingUtils.getTestResourceFile("embedder-context.xml").getAbsolutePath());