Issue #1602 - Attempting to add testcase.
* Attempt to replicate reproduction case reported by @janbartel Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
4c26ba7998
commit
3eb8b1d59b
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
/**
|
||||
* A SCI that tosses an Error to intentionally to cause issues with the DeploymentManager
|
||||
* @see <a href="https://github.com/eclipse/jetty.project/issues/1602">Issue #1602</a>
|
||||
*/
|
||||
public class DeploymentErrorInitializer implements ServletContainerInitializer
|
||||
{
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException
|
||||
{
|
||||
throw new NoClassDefFoundError("Intentional.Failure");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.AppLifeCycle;
|
||||
import org.eclipse.jetty.deploy.DeploymentManager;
|
||||
import org.eclipse.jetty.deploy.providers.WebAppProvider;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DeploymentErrorTest
|
||||
{
|
||||
private static Server server;
|
||||
private static URI serverURI; // TODO: test that we can not access webapp.
|
||||
private static DeploymentManager deploymentManager;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
server = new Server();
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
connector.setPort(0);
|
||||
server.addConnector(connector);
|
||||
|
||||
// Empty handler collections
|
||||
ContextHandlerCollection contexts = new ContextHandlerCollection();
|
||||
HandlerCollection handlers = new HandlerCollection();
|
||||
handlers.setHandlers(new Handler[]
|
||||
{ contexts, new DefaultHandler() });
|
||||
server.setHandler(handlers);
|
||||
|
||||
// Deployment Manager
|
||||
deploymentManager = new DeploymentManager();
|
||||
deploymentManager.setContexts(contexts);
|
||||
Path testClasses = MavenTestingUtils.getTargetPath("test-classes");
|
||||
System.setProperty("maven.test.classes", testClasses.toAbsolutePath().toString());
|
||||
Path docroots = MavenTestingUtils.getTestResourcePathDir("docroots");
|
||||
System.setProperty("test.docroots", docroots.toAbsolutePath().toString());
|
||||
WebAppProvider appProvider = new WebAppProvider();
|
||||
appProvider.setMonitoredDirResource(new PathResource(docroots.resolve("deployerror")));
|
||||
appProvider.setScanInterval(1);
|
||||
deploymentManager.addAppProvider(appProvider);
|
||||
server.addBean(deploymentManager);
|
||||
|
||||
// Setup Configurations
|
||||
Configuration.ClassList classlist = Configuration.ClassList
|
||||
.setServerDefault(server);
|
||||
classlist.addAfter(
|
||||
"org.eclipse.jetty.webapp.FragmentConfiguration",
|
||||
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
|
||||
"org.eclipse.jetty.plus.webapp.PlusConfiguration");
|
||||
classlist.addBefore(
|
||||
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
|
||||
"org.eclipse.jetty.annotations.AnnotationConfiguration");
|
||||
|
||||
server.start();
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownServer() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorDeploy() throws Exception
|
||||
{
|
||||
assertThat("app not started", deploymentManager.getApps(AppLifeCycle.STARTED), empty());
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
List<App> apps = new ArrayList<>();
|
||||
apps.addAll(deploymentManager.getApps());
|
||||
assertThat("Apps tracked", apps.size(), is(1));
|
||||
App app = apps.get(0);
|
||||
assertThat("App.handler.isFailed", app.getContextHandler().isFailed(), is(true));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<Set name="contextPath">/badapp</Set>
|
||||
<Set name="war"><SystemProperty name="test.docroots"/>/deployerror/badapp/</Set>
|
||||
<Set name="extraClasspath"><SystemProperty name="maven.test.classes"/></Set>
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.containerInitializerExclusionPattern</Arg>
|
||||
<Arg>org.jboss.*</Arg>
|
||||
</Call>
|
||||
</Configure>
|
|
@ -0,0 +1 @@
|
|||
org.eclipse.jetty.test.DeploymentErrorInitializer
|
|
@ -0,0 +1,7 @@
|
|||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
<display-name>Intentional Deployment Error WebApp</display-name>
|
||||
</web-app>
|
Loading…
Reference in New Issue