
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Operating System: Other
Platform: Other
Operating System: Other
Platform: Other
|
|
|
If an exception occurs while starting a jetty context, the setup will throw an exception and
teardown won't be called even though jetty is still running. Subsequent jetty tests will fail
because jetty is still running and can't be started again.
Here's an example stack trace:
java.lang.RuntimeException: ConnectionPoolManager already configured
at
com.aex.common.manager.ConnectionPoolManager.configure(ConnectionPoolManager.java:234)
at com.aex.common.servlet.InitializeListener.contextInitialized(InitializeListener.java:67)
at
org.mortbay.jetty.servlet.WebApplicationContext.start(WebApplicationContext.java:439)
at org.mortbay.http.HttpServer.start(HttpServer.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.cactus.extension.jetty.JettyTestSetup.setUp(JettyTestSetup.java:169)
at junit.extensions.TestSetup$1.protect(TestSetup.java:18)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.extensions.TestSetup.run(TestSetup.java:23)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
The Exception is caught in the try block around TestSetup.java:18. Jetty is running at this point
but teardown is never called to stop it even though the test is over.
I'd suggest replacing the startup line in org.apache.cactus.extension.jetty.JettyTestSetup with
something like:
// Start the Jetty server
try {
server.getClass().getMethod("start", null).invoke(server, null);
} catch (Throwable ex) {
try {
boolean started = ((Boolean) server.getClass().getMethod("isStarted",
null).invoke(server, null)).booleanValue();
if (started) {
server.getClass().getMethod("stop", null).invoke(server, null);
}
} finally {
if (ex instanceof Exception) {
throw (Exception)ex;
} else {
throw (Error)ex;
}
}
}
|
|
Description
|
If an exception occurs while starting a jetty context, the setup will throw an exception and
teardown won't be called even though jetty is still running. Subsequent jetty tests will fail
because jetty is still running and can't be started again.
Here's an example stack trace:
java.lang.RuntimeException: ConnectionPoolManager already configured
at
com.aex.common.manager.ConnectionPoolManager.configure(ConnectionPoolManager.java:234)
at com.aex.common.servlet.InitializeListener.contextInitialized(InitializeListener.java:67)
at
org.mortbay.jetty.servlet.WebApplicationContext.start(WebApplicationContext.java:439)
at org.mortbay.http.HttpServer.start(HttpServer.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.cactus.extension.jetty.JettyTestSetup.setUp(JettyTestSetup.java:169)
at junit.extensions.TestSetup$1.protect(TestSetup.java:18)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.extensions.TestSetup.run(TestSetup.java:23)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
The Exception is caught in the try block around TestSetup.java:18. Jetty is running at this point
but teardown is never called to stop it even though the test is over.
I'd suggest replacing the startup line in org.apache.cactus.extension.jetty.JettyTestSetup with
something like:
// Start the Jetty server
try {
server.getClass().getMethod("start", null).invoke(server, null);
} catch (Throwable ex) {
try {
boolean started = ((Boolean) server.getClass().getMethod("isStarted",
null).invoke(server, null)).booleanValue();
if (started) {
server.getClass().getMethod("stop", null).invoke(server, null);
}
} finally {
if (ex instanceof Exception) {
throw (Exception)ex;
} else {
throw (Error)ex;
}
}
} |
Show » |
|
Thanks for this bug report. I've applied your patch but slightly modified. I
have overriden the run() method as follows:
public void run(final TestResult theResult)
{
Protectable p = new Protectable()
{
public void protect() throws Exception
{
try
{
setUp();
basicRun(theResult);
}
finally
{
tearDown();
}
}
};
theResult.runProtected(this, p);
}
And I have modified the tearDown method as follows:
protected void tearDown() throws Exception
{
if (this.server != null)
{
// First, verify if the server is running
boolean started = ((Boolean) server.getClass().getMethod(
"isStarted", null).invoke(this.server, null)).booleanValue();
// Stop the Jetty server, if started
if (started)
{
this.server.getClass().getMethod("stop", null).invoke(
this.server, null);
}
}
}
I'll be testing this over the week.
Thanks
-Vincent