Author: kkolinko
Date: Sat Jan 16 03:16:02 2016
New Revision: 1724909
URL: http://svn.apache.org/viewvc?rev=1724909&view=rev
Log:
Implement Tomcat class. Switch tests from using Embedded class to Tomcat class.
By the way, with this change I no longer see failures or crashes when testing
with the APR connector. So this issue is fixed as well.
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/connector/TestConnector.java
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/core/TestApplicationHttpRequest.java
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TestTomcat.java
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/Tomcat.java
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/connector/TestConnector.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/connector/TestConnector.java?rev=1724909&r1=1724908&r2=1724909&view=diff
==============================================================================
---
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/connector/TestConnector.java
(original)
+++
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/connector/TestConnector.java
Sat Jan 16 03:16:02 2016
@@ -20,7 +20,7 @@ import org.junit.Test;
import static org.junit.Assert.assertTrue;
-import org.apache.catalina.startup.Embedded;
+import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
/**
@@ -30,10 +30,9 @@ public class TestConnector extends Tomca
@Test
public void testPort() throws Exception {
- Embedded tomcat = getTomcatInstance();
+ Tomcat tomcat = getTomcatInstance();
- // Connector connector1 = tomcat.getConnector();
- Connector connector1 = tomcat.findConnectors()[0];
+ Connector connector1 = tomcat.getConnector();
connector1.setPort(0);
tomcat.start();
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/core/TestApplicationHttpRequest.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/core/TestApplicationHttpRequest.java?rev=1724909&r1=1724908&r2=1724909&view=diff
==============================================================================
---
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/core/TestApplicationHttpRequest.java
(original)
+++
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/core/TestApplicationHttpRequest.java
Sat Jan 16 03:16:02 2016
@@ -31,8 +31,6 @@ import org.junit.Assert;
import org.junit.Test;
import org.apache.catalina.Context;
-import org.apache.catalina.Host;
-import org.apache.catalina.startup.Embedded;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.tomcat.util.buf.ByteChunk;
@@ -180,17 +178,14 @@ public class TestApplicationHttpRequest
private void doQueryStringTest(String originalQueryString, String
forwardQueryString,
Map<String,String[]> expected) throws Exception {
- Embedded tomcat = getTomcatInstance();
+ Tomcat tomcat = getTomcatInstance();
// // No file system docBase required
// Context ctx = tomcat.addContext("", null);
// Must have a real docBase - just use temp
- // FIXME: Implement getHost() method.
// FIXME: Implement support for null docBase (r1681953)
- Host host = (Host) tomcat.getContainer().findChildren()[0];
- Tomcat helper = new Tomcat();
- Context ctx = helper.addContext(host, "",
+ Context ctx = tomcat.addContext("",
System.getProperty("java.io.tmpdir"));
if (forwardQueryString == null) {
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TestTomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TestTomcat.java?rev=1724909&r1=1724908&r2=1724909&view=diff
==============================================================================
---
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TestTomcat.java
(original)
+++
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TestTomcat.java
Sat Jan 16 03:16:02 2016
@@ -248,18 +248,15 @@ public class TestTomcat extends TomcatBa
*/
@Test
public void testProgrammatic() throws Exception {
- Embedded tomcat = getTomcatInstance();
+ Tomcat tomcat = getTomcatInstance();
// // No file system docBase required
// org.apache.catalina.Context ctx = tomcat.addContext("", null);
// Must have a real docBase - just use temp
- // FIXME: Implement getHost() method.
// FIXME: Implement support for null docBase (r1681953)
- Host host = (Host) tomcat.getContainer().findChildren()[0];
- Tomcat helper = new Tomcat();
- org.apache.catalina.Context ctx =
- helper.addContext(host, "",
System.getProperty("java.io.tmpdir"));
+ org.apache.catalina.Context ctx = tomcat.addContext("",
+ System.getProperty("java.io.tmpdir"));
// You can customize the context by calling
// its API
@@ -275,21 +272,16 @@ public class TestTomcat extends TomcatBa
@Test
public void testSingleWebapp() throws Exception {
- Embedded tomcat = getTomcatInstance();
+ Tomcat tomcat = getTomcatInstance();
File appDir = new File(getBuildDirectory(), "webapps/examples");
- // tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
-
- // FIXME: Implement getHost() method.
- Host host = (Host) tomcat.getContainer().findChildren()[0];
- Tomcat helper = new Tomcat();
- helper.addWebapp(host, "/examples", appDir.getAbsolutePath());
+ tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
tomcat.start();
- ByteChunk res = getUrl("http://localhost:" + getPort()
- + "/examples/servlets/servlet/HelloWorldExample");
+ ByteChunk res = getUrl("http://localhost:" + getPort() +
+ "/examples/servlets/servlet/HelloWorldExample");
String text = res.toString();
assertTrue(text, text.indexOf("<h1>Hello World!</h1>") > 0);
}
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/Tomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/Tomcat.java?rev=1724909&r1=1724908&r2=1724909&view=diff
==============================================================================
---
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/Tomcat.java
(original)
+++
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/Tomcat.java
Sat Jan 16 03:16:02 2016
@@ -125,34 +125,37 @@ import org.apache.catalina.realm.RealmBa
* @author Costin Manolache
*/
public class Tomcat {
-//FIXME
+
// // Some logging implementations use weak references for loggers so there
is
// // the possibility that logging configuration could be lost if GC runs
just
// // after Loggers are configured but before they are used. The purpose of
// // this Map is to retain strong references to explicitly configured
loggers
// // so that configuration is not lost.
// private final Map<String, Logger> pinnedLoggers = new HashMap<String,
Logger>();
-//
-// // Single engine, service, server, connector - few cases need more,
-// // they can use server.xml
-// protected StandardServer server;
-// protected StandardService service;
-// protected StandardEngine engine;
-// protected Connector connector; // for more - customize the classes
-//
-// // To make it a bit easier to config for the common case
-// // ( one host, one context ).
-// protected Host host;
-//
-// // TODO: it's easy to add support for more hosts - but is it
-// // really needed ?
-//
-// // TODO: allow use of in-memory connector
-//
-// protected int port = 8080;
-// protected String hostname = "localhost";
-// protected String basedir;
-//
+
+ // Single engine, service, server, connector - few cases need more,
+ // they can use server.xml
+ protected StandardServer server;
+ protected StandardService service;
+ protected StandardEngine engine;
+ protected Connector connector; // for more - customize the classes
+
+ // To make it a bit easier to config for the common case
+ // ( one host, one context ).
+ protected Host host;
+
+ // TODO: it's easy to add support for more hosts - but is it
+ // really needed ?
+
+ // TODO: allow use of in-memory connector
+
+ protected int port = 8080;
+ protected String hostname = "localhost";
+ protected String basedir;
+
+ private volatile boolean initialized;
+ private volatile boolean started;
+
// // Default in-memory realm, will be set by default on the Engine. Can be
// // replaced at engine level or over-ridden at Host or Context level
// @Deprecated // Will be removed in Tomcat 8.0.x.
@@ -162,44 +165,44 @@ public class Tomcat {
// new HashMap<String, List<String>>();
// private final Map<String, Principal> userPrincipals =
// new HashMap<String, Principal>();
-//
-// public Tomcat() {
-// // NOOP
-// }
-//
-// /**
-// * Tomcat needs a directory for temp files. This should be the
-// * first method called.
-// *
-// * By default, if this method is not called, we use:
-// * - system properties - catalina.base, catalina.home
-// * - $HOME/tomcat.$PORT
-// * ( /tmp doesn't seem a good choice for security ).
-// *
-// *
-// * TODO: better default ? Maybe current dir ?
-// * TODO: disable work dir if not needed ( no jsp, etc ).
-// */
-// public void setBaseDir(String basedir) {
-// this.basedir = basedir;
-// }
-//
-// /**
-// * Set the port for the default connector. Must
-// * be called before start().
-// */
-// public void setPort(int port) {
-// this.port = port;
-// }
-//
-// /**
-// * The the hostname of the default host, default is
-// * 'localhost'.
-// */
-// public void setHostname(String s) {
-// hostname = s;
-// }
-//
+
+ public Tomcat() {
+ // NOOP
+ }
+
+ /**
+ * Tomcat needs a directory for temp files. This should be the
+ * first method called.
+ *
+ * By default, if this method is not called, we use:
+ * - system properties - catalina.base, catalina.home
+ * - $HOME/tomcat.$PORT
+ * ( /tmp doesn't seem a good choice for security ).
+ *
+ *
+ * TODO: better default ? Maybe current dir ?
+ * TODO: disable work dir if not needed ( no jsp, etc ).
+ */
+ public void setBaseDir(String basedir) {
+ this.basedir = basedir;
+ }
+
+ /**
+ * Set the port for the default connector. Must
+ * be called before start().
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ /**
+ * The the hostname of the default host, default is
+ * 'localhost'.
+ */
+ public void setHostname(String s) {
+ hostname = s;
+ }
+
// /**
// * This is equivalent to adding a web application to Tomcat's
webapps
// * directory. The equivalent of the default web.xml will be applied to
the
@@ -213,39 +216,39 @@ public class Tomcat {
// public Context addWebapp(String contextPath, String docBase) throws
ServletException {
// return addWebapp(getHost(), contextPath, docBase);
// }
-//
-//
-// /**
-// * Add a context - programmatic mode, no web.xml used.
-// *
-// * API calls equivalent with web.xml:
-// *
-// * context-param
-// * ctx.addParameter("name", "value");
-// *
-// *
-// * error-page
-// * ErrorPage ep = new ErrorPage();
-// * ep.setErrorCode(500);
-// * ep.setLocation("/error.html");
-// * ctx.addErrorPage(ep);
-// *
-// * ctx.addMimeMapping("ext", "type");
-// *
-// * Note: If you reload the Context, all your configuration will be lost.
If
-// * you need reload support, consider using a LifecycleListener to provide
-// * your configuration.
-// *
-// * TODO: add the rest
-// *
-// * @param contextPath "" for root context.
-// * @param docBase base dir for the context, for static files. Must
exist,
-// * relative to the server home
-// */
-// public Context addContext(String contextPath, String docBase) {
-// return addContext(getHost(), contextPath, docBase);
-// }
-//
+
+
+ /**
+ * Add a context - programmatic mode, no web.xml used.
+ *
+ * API calls equivalent with web.xml:
+ *
+ * context-param
+ * ctx.addParameter("name", "value");
+ *
+ *
+ * error-page
+ * ErrorPage ep = new ErrorPage();
+ * ep.setErrorCode(500);
+ * ep.setLocation("/error.html");
+ * ctx.addErrorPage(ep);
+ *
+ * ctx.addMimeMapping("ext", "type");
+ *
+ * Note: If you reload the Context, all your configuration will be lost. If
+ * you need reload support, consider using a LifecycleListener to provide
+ * your configuration.
+ *
+ * TODO: add the rest
+ *
+ * @param contextPath "" for root context.
+ * @param docBase base dir for the context, for static files. Must exist,
+ * relative to the server home
+ */
+ public Context addContext(String contextPath, String docBase) {
+ return addContext(getHost(), contextPath, docBase);
+ }
+
// /**
// * Equivalent with
// * <servlet><servlet-name><servlet-class>.
@@ -324,50 +327,66 @@ public class Tomcat {
}
-// /**
-// * Initialise the server.
-// *
-// * @throws LifecycleException
-// */
-// public void init() throws Exception {
-// getServer();
-// getConnector();
-// server.init();
-// }
-//
-//
-// /**
-// * Start the server.
-// *
-// * @throws LifecycleException
-// */
-// public void start() throws LifecycleException {
-// getServer();
-// getConnector();
-// server.start();
-// }
-//
-// /**
-// * Stop the server.
-// *
-// * @throws LifecycleException
-// */
-// public void stop() throws LifecycleException {
-// getServer();
-// server.stop();
-// }
-//
-//
-// /**
-// * Destroy the server. This object cannot be used once this method has
been
-// * called.
-// */
-// public void destroy() throws LifecycleException {
-// getServer();
-// server.destroy();
-// // Could null out objects here
-// }
-//
+ /**
+ * Initialise the server.
+ *
+ * @throws LifecycleException
+ */
+ public void init() throws LifecycleException {
+ getServer();
+ getConnector();
+ if (!initialized) {
+ initialized = true;
+ try {
+ server.init();
+ } catch (LifecycleException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new LifecycleException(e);
+ }
+ }
+ }
+
+
+ /**
+ * Start the server.
+ *
+ * @throws LifecycleException
+ */
+ public void start() throws LifecycleException {
+ if (!started) {
+ init();
+ started = true;
+ server.start();
+ }
+ }
+
+ /**
+ * Stop the server.
+ *
+ * @throws LifecycleException
+ */
+ public void stop() throws LifecycleException {
+ if (started) {
+ started = false;
+ server.stop();
+ }
+ }
+
+
+ /**
+ * Destroy the server. This object cannot be used once this method has been
+ * called.
+ */
+ public void destroy() throws LifecycleException {
+ if (initialized) {
+ stop();
+ initialized = false;
+ // server.destroy();
+ // Could null out objects here
+ }
+ }
+
// /**
// * Add a user for the in-memory realm. All created apps use this
// * by default, can be replaced using setRealm().
@@ -388,69 +407,77 @@ public class Tomcat {
// }
// roles.add(role);
// }
-//
-// // ------- Extra customization -------
-// // You can tune individual tomcat objects, using internal APIs
-//
-// /**
-// * Get the default http connector. You can set more
-// * parameters - the port is already initialized.
-// *
-// * Alternatively, you can construct a Connector and set any params,
-// * then call addConnector(Connector)
-// *
-// * @return A connector object that can be customized
-// */
-// public Connector getConnector() {
-// getServer();
-// if (connector != null) {
-// return connector;
-// }
-//
-// // The same as in standard Tomcat configuration.
-// // This creates an APR HTTP connector if AprLifecycleListener has
been
-// // configured (created) and Tomcat Native library is available.
-// // Otherwise it creates a BIO HTTP connector (Http11Protocol).
-// connector = new Connector("HTTP/1.1");
-// connector.setPort(port);
-// service.addConnector( connector );
-// return connector;
-// }
-//
-// public void setConnector(Connector connector) {
-// this.connector = connector;
-// }
-//
-// /**
-// * Get the service object. Can be used to add more
-// * connectors and few other global settings.
-// */
-// public Service getService() {
-// getServer();
-// return service;
-// }
-//
-// /**
-// * Sets the current host - all future webapps will
-// * be added to this host. When tomcat starts, the
-// * host will be the default host.
-// *
-// * @param host
-// */
-// public void setHost(Host host) {
-// this.host = host;
-// }
-//
-// public Host getHost() {
-// if (host == null) {
-// host = new StandardHost();
-// host.setName(hostname);
-//
-// getEngine().addChild( host );
-// }
-// return host;
-// }
-//
+
+ // ------- Extra customization -------
+ // You can tune individual tomcat objects, using internal APIs
+
+ /**
+ * Get the default http connector. You can set more
+ * parameters - the port is already initialized.
+ *
+ * Alternatively, you can construct a Connector and set any params,
+ * then call addConnector(Connector)
+ *
+ * @return A connector object that can be customized
+ */
+ public Connector getConnector() {
+ getServer();
+ if (connector != null) {
+ return connector;
+ }
+
+ // The same as in standard Tomcat configuration.
+ // This creates an APR HTTP connector if AprLifecycleListener has been
+ // configured (created) and Tomcat Native library is available.
+ // Otherwise it creates a BIO HTTP connector (Http11Protocol).
+ try {
+ connector = new Connector("HTTP/1.1");
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ // Never happens. Connector() declares that it can throw
+ // an Exception, but never throws one.
+ throw new RuntimeException(e);
+ }
+ connector.setPort(port);
+ service.addConnector( connector );
+ return connector;
+ }
+
+ public void setConnector(Connector connector) {
+ this.connector = connector;
+ }
+
+ /**
+ * Get the service object. Can be used to add more
+ * connectors and few other global settings.
+ */
+ public Service getService() {
+ getServer();
+ return service;
+ }
+
+ /**
+ * Sets the current host - all future webapps will
+ * be added to this host. When tomcat starts, the
+ * host will be the default host.
+ *
+ * @param host
+ */
+ public void setHost(Host host) {
+ this.host = host;
+ }
+
+ public Host getHost() {
+ if (host == null) {
+ host = new StandardHost();
+ host.setName(hostname);
+
+ getEngine().addChild( host );
+ }
+ return host;
+ }
+
// /**
// * Set a custom realm for auth. If not called, a simple
// * default will be used, using an internal map.
@@ -464,47 +491,48 @@ public class Tomcat {
// defaultRealm = realm;
// }
//
-//
-// /**
-// * Access to the engine, for further customization.
-// */
-// public Engine getEngine() {
-// if(engine == null ) {
-// getServer();
-// engine = new StandardEngine();
-// engine.setName( "Tomcat" );
-// engine.setDefaultHost(hostname);
-// if (defaultRealm == null) {
-// initSimpleAuth();
-// }
-// engine.setRealm(defaultRealm);
-// service.setContainer(engine);
-// }
-// return engine;
-// }
-//
-// /**
-// * Get the server object. You can add listeners and few more
-// * customizations. JNDI is disabled by default.
-// */
-// public Server getServer() {
-//
-// if (server != null) {
-// return server;
-// }
-//
-// initBaseDir();
-//
-// System.setProperty("catalina.useNaming", "false");
-//
-// server = new StandardServer();
-// server.setPort( -1 );
-//
-// service = new StandardService();
-// service.setName("Tomcat");
-// server.addService( service );
-// return server;
-// }
+
+ /**
+ * Access to the engine, for further customization.
+ */
+ public Engine getEngine() {
+ if(engine == null ) {
+ getServer();
+ engine = new StandardEngine();
+ engine.setName( "Tomcat" );
+ engine.setDefaultHost(hostname);
+ // @Deprecated
+ // if (defaultRealm == null) {
+ // initSimpleAuth();
+ // }
+ // engine.setRealm(defaultRealm);
+ service.setContainer(engine);
+ }
+ return engine;
+ }
+
+ /**
+ * Get the server object. You can add listeners and few more
+ * customizations. JNDI is disabled by default.
+ */
+ public Server getServer() {
+
+ if (server != null) {
+ return server;
+ }
+
+ initBaseDir();
+
+ System.setProperty("catalina.useNaming", "false");
+
+ server = new StandardServer();
+ server.setPort(-1);
+
+ service = new StandardService();
+ service.setName("Tomcat");
+ server.addService(service);
+ return server;
+ }
public Context addContext(Host host, String contextPath, String dir) {
return addContext(host, contextPath, contextPath, dir);
@@ -519,11 +547,11 @@ public class Tomcat {
ctx.setDocBase(dir);
((Lifecycle) ctx).addLifecycleListener(new FixContextListener());
-// if (host == null) {
-// getHost().addChild(ctx);
-// } else {
+ if (host == null) {
+ getHost().addChild(ctx);
+ } else {
host.addChild(ctx);
-// }
+ }
return ctx;
}
@@ -555,11 +583,11 @@ public class Tomcat {
// // prevent it from looking ( if it finds one - it'll have dup error )
// ctxCfg.setDefaultWebXml(noDefaultWebXmlPath());
-// if (host == null) {
-// getHost().addChild(ctx);
-// } else {
+ if (host == null) {
+ getHost().addChild(ctx);
+ } else {
host.addChild(ctx);
-// }
+ }
return ctx;
}
@@ -638,36 +666,35 @@ public class Tomcat {
//
// };
// }
-//
-// protected void initBaseDir() {
-// String catalinaHome = System.getProperty(Globals.CATALINA_HOME_PROP);
-// if (basedir == null) {
-// basedir = System.getProperty(Globals.CATALINA_BASE_PROP);
-// }
-// if (basedir == null) {
-// basedir = catalinaHome;
-// }
-// if (basedir == null) {
-// // Create a temp dir.
-// basedir = System.getProperty("user.dir") +
-// "/tomcat." + port;
-// File home = new File(basedir);
-// home.mkdir();
-// if (!home.isAbsolute()) {
-// try {
-// basedir = home.getCanonicalPath();
-// } catch (IOException e) {
-// basedir = home.getAbsolutePath();
-// }
-// }
-// }
-// if (catalinaHome == null) {
-// System.setProperty(Globals.CATALINA_HOME_PROP, basedir);
-// }
-// System.setProperty(Globals.CATALINA_BASE_PROP, basedir);
-// }
-//
-// static final String[] silences = new String[] {
+
+ protected void initBaseDir() {
+ String catalinaHome = System.getProperty(Globals.CATALINA_HOME_PROP);
+ if (basedir == null) {
+ basedir = System.getProperty(Globals.CATALINA_BASE_PROP);
+ }
+ if (basedir == null) {
+ basedir = catalinaHome;
+ }
+ if (basedir == null) {
+ // Create a temp dir.
+ basedir = System.getProperty("user.dir") + "/tomcat." + port;
+ File home = new File(basedir);
+ home.mkdir();
+ if (!home.isAbsolute()) {
+ try {
+ basedir = home.getCanonicalPath();
+ } catch (IOException e) {
+ basedir = home.getAbsolutePath();
+ }
+ }
+ }
+ if (catalinaHome == null) {
+ System.setProperty(Globals.CATALINA_HOME_PROP, basedir);
+ }
+ System.setProperty(Globals.CATALINA_BASE_PROP, basedir);
+ }
+
+ // static final String[] silences = new String[] {
// "org.apache.coyote.http11.Http11Protocol",
// "org.apache.catalina.core.StandardService",
// "org.apache.catalina.core.StandardEngine",
@@ -730,9 +757,9 @@ public class Tomcat {
*/
private Context createContext(Host host, String url) {
String contextClass = StandardContext.class.getName();
-// if (host == null) {
-// host = this.getHost();
-// }
+ if (host == null) {
+ host = this.getHost();
+ }
if (host instanceof StandardHost) {
contextClass = ((StandardHost) host).getContextClass();
}
Modified:
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1724909&r1=1724908&r2=1724909&view=diff
==============================================================================
---
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java
(original)
+++
tomcat/tc6.0.x/branches/tomcat6-testing_20160106/test/org/apache/catalina/startup/TomcatBaseTest.java
Sat Jan 16 03:16:02 2016
@@ -46,10 +46,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.apache.catalina.Container;
-import org.apache.catalina.Engine;
-import org.apache.catalina.Host;
-import org.apache.catalina.Lifecycle;
-import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Manager;
import org.apache.catalina.Server;
@@ -68,7 +64,7 @@ import org.apache.tomcat.util.buf.ByteCh
* don't have to keep writing the cleanup code.
*/
public abstract class TomcatBaseTest extends LoggingBaseTest {
- private Embedded tomcat;
+ private Tomcat tomcat;
private boolean accessLogEnabled = false;
public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
@@ -76,7 +72,7 @@ public abstract class TomcatBaseTest ext
/**
* Make Tomcat instance accessible to sub-classes.
*/
- public Embedded getTomcatInstance() {
+ public Tomcat getTomcatInstance() {
return tomcat;
}
@@ -84,8 +80,7 @@ public abstract class TomcatBaseTest ext
* Sub-classes need to know port so they can connect
*/
public int getPort() {
- // return tomcat.getConnector().getLocalPort();
- return tomcat.findConnectors()[0].getLocalPort();
+ return tomcat.getConnector().getLocalPort();
}
/**
@@ -114,10 +109,6 @@ public abstract class TomcatBaseTest ext
assertNull("ServerFactory.server field is not null", f.get(null));
tomcat = new TomcatWithFastSessionIDs();
- tomcat.setServer(ServerFactory.getServer());
-
- Engine engine = tomcat.createEngine();
- tomcat.addEngine(engine);
String protocol = getProtocol();
Connector connector = new Connector(protocol);
@@ -128,7 +119,8 @@ public abstract class TomcatBaseTest ext
connector.setPort(0);
// Mainly set to reduce timeouts during async tests
connector.setAttribute("connectionTimeout", "3000");
- tomcat.addConnector(connector);
+ tomcat.getService().addConnector(connector);
+ tomcat.setConnector(connector);
// Add AprLifecycleListener if we are using the Apr connector
if (protocol.contains("Apr")) {
@@ -137,15 +129,11 @@ public abstract class TomcatBaseTest ext
listener.setSSLRandomSeed("/dev/urandom");
server.addLifecycleListener(listener);
connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
- // FIXME: In Tomcat 6 Embedded.start() does not fire INIT_EVENT on
Server
- listener.lifecycleEvent(new LifecycleEvent(server,
Lifecycle.INIT_EVENT));
}
File catalinaBase = getTemporaryDirectory();
- tomcat.setCatalinaBase(catalinaBase.getAbsolutePath());
-
- Host host = tomcat.createHost("localhost", appBase.getAbsolutePath());
- engine.addChild(host);
+ tomcat.setBaseDir(catalinaBase.getAbsolutePath());
+ tomcat.getHost().setAppBase(appBase.getAbsolutePath());
accessLogEnabled = Boolean.parseBoolean(
System.getProperty("tomcat.test.accesslog", "false"));
@@ -159,8 +147,7 @@ public abstract class TomcatBaseTest ext
AccessLogValve alv = new AccessLogValve();
alv.setDirectory(accessLogDirectory);
alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
- // tomcat.getHost().getPipeline().addValve(alv);
- host.getPipeline().addValve(alv);
+ tomcat.getHost().getPipeline().addValve(alv);
}
// Cannot delete the whole tempDir, because logs are there,
@@ -185,7 +172,7 @@ public abstract class TomcatBaseTest ext
@Override
public void tearDown() throws Exception {
try {
- if (tomcat.started) {
+ if (tomcat.server != null) {
tomcat.stop();
tomcat.destroy();
}
@@ -793,7 +780,7 @@ public abstract class TomcatBaseTest ext
return rc;
}
- private static class TomcatWithFastSessionIDs extends Embedded {
+ private static class TomcatWithFastSessionIDs extends Tomcat {
@Override
public void start() throws LifecycleException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]