Working out some maven command line testing failures on JDK 1.5.0_18

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@864 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-09-10 21:00:22 +00:00
parent c62db0a278
commit ba847598ac
6 changed files with 179 additions and 26 deletions

View File

@ -0,0 +1,40 @@
#!/bin/bash
M2REPO=$HOME/.m2/repository
function jettydep()
{
echo "$M2REPO/org/eclipse/jetty/$1/7.0.1-SNAPSHOT/$1-7.0.1-SNAPSHOT.jar"
}
function slf4jdep()
{
echo "$M2REPO/org/slf4j/$1/1.5.6/$1-1.5.6.jar"
}
CP="target/classes:target/test-classes"
CP="$CP:"`jettydep "jetty-util"`
CP="$CP:"`jettydep "jetty-io"`
CP="$CP:"`jettydep "jetty-http"`
CP="$CP:"`jettydep "jetty-xml"`
CP="$CP:"`jettydep "jetty-server"`
CP="$CP:"`jettydep "jetty-security"`
CP="$CP:"`jettydep "jetty-servlet"`
CP="$CP:"`jettydep "jetty-webapp"`
CP="$CP:"`jettydep "jetty-deploy"`
CP="$CP:"`jettydep "jetty-continuation"`
CP="$CP:$M2REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar"
CP="$CP:"`slf4jdep "slf4j-api"`
CP="$CP:"`slf4jdep "jcl-over-slf4j"`
CP="$CP:"`slf4jdep "log4j-over-slf4j"`
CP="$CP:$M2REPO/junit/junit/3.8.2/junit-3.8.2.jar"
TESTBASEDIR=`pwd`
EXTRA=""
# EXTRA="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
java -cp $CP $EXTRA \
"-Dbasedir=$TESTBASEDIR" \
junit.textui.TestRunner \
org.eclipse.jetty.logging.CentralizedLoggingTest

View File

@ -32,7 +32,11 @@ public class CentralizedLoggingTest extends TestCase
{
for (LogEvent expectedEvent : expectedLogs)
{
assertTrue("LogEvent not found: " + expectedEvent,capturedEvents.contains(expectedEvent));
if (!capturedEvents.contains(expectedEvent))
{
capturedEvents.dump();
fail("LogEvent not found: " + expectedEvent);
}
}
}

View File

@ -26,7 +26,9 @@ import org.eclipse.jetty.logging.impl.Severity;
import org.eclipse.jetty.logging.impl.TestAppender;
import org.eclipse.jetty.logging.impl.TestAppender.LogEvent;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
@ -42,10 +44,25 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
{
for (LogEvent expectedEvent : expectedLogs)
{
assertTrue("LogEvent not found: " + expectedEvent,capturedEvents.contains(expectedEvent));
if (!capturedEvents.contains(expectedEvent))
{
capturedEvents.dump();
fail("LogEvent not found: " + expectedEvent);
}
}
}
private Handler createWebapp(String contextPath, String webappName)
{
File webappFile = MavenTestingUtils.getTestResourceFile("webapps/" + webappName);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath(contextPath);
webapp.setWar(webappFile.getAbsolutePath());
return webapp;
}
protected Server createWebAppServer(String contextPath, String webappName) throws Exception
{
if (!CentralizedWebAppLoggingConfiguration.isLoggerConfigured())
@ -89,36 +106,54 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
System.setProperty("java.io.tmpdir",testTmpDir.getAbsolutePath());
}
public void testEmbeddedWebappLog4j() throws Exception
public void testEmbeddedAll() throws Exception
{
Server server = createWebAppServer("/log4j","dummy-webapp-logging-log4j.war");
if (!CentralizedWebAppLoggingConfiguration.isLoggerConfigured())
{
String loggerConfigFilename = MavenTestingUtils.getTestResourceFile("logger/testing.properties").getAbsolutePath();
CentralizedWebAppLoggingConfiguration.setLoggerConfigurationFilename(loggerConfigFilename);
}
CentralLoggerConfig root = CentralizedWebAppLoggingConfiguration.getLoggerRoot();
testAppender = (TestAppender)root.findAppender(TestAppender.class);
testAppender.reset();
Server server = new Server();
List<Configuration> serverConfigs = new ArrayList<Configuration>();
serverConfigs.add(new CentralizedWebAppLoggingConfiguration());
server.setAttribute(WebAppContext.SERVER_CONFIG,serverConfigs);
Connector connector = new SelectChannelConnector();
connector.setPort(0);
server.setConnectors(new Connector[]
{ connector });
ContextHandlerCollection handlers = new ContextHandlerCollection();
handlers.addHandler(createWebapp("/log4j","dummy-webapp-logging-log4j.war"));
handlers.addHandler(createWebapp("/slf4j","dummy-webapp-logging-slf4j.war"));
handlers.addHandler(createWebapp("/clogging","dummy-webapp-logging-commons.war"));
handlers.addHandler(createWebapp("/javalogging","dummy-webapp-logging-java.war"));
server.setHandler(handlers);
server.start();
SimpleRequest.get(server,"/log4j/logging");
SimpleRequest.get(server,"/slf4j/logging");
SimpleRequest.get(server,"/clogging/logging");
SimpleRequest.get(server,"/javalogging/logging");
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(log4j) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(log4j) GET requested",null) };
assertContainsLogEvents(testAppender,expectedLogs);
}
public void testEmbeddedWebappSlf4j() throws Exception
{
Server server = createWebAppServer("/slf4j","dummy-webapp-logging-slf4j.war");
server.start();
SimpleRequest.get(server,"/slf4j/logging");
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(slf4j) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(slf4j) GET requested",null) };
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(log4j) GET requested",null),
new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(slf4j) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(slf4j) GET requested",null),
new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(commons-logging) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(commons-logging) GET requested",null),
new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(java) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(java) GET requested",null) };
assertContainsLogEvents(testAppender,expectedLogs);
}
@ -156,4 +191,38 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
assertContainsLogEvents(testAppender,expectedLogs);
}
public void testEmbeddedWebappLog4j() throws Exception
{
Server server = createWebAppServer("/log4j","dummy-webapp-logging-log4j.war");
server.start();
SimpleRequest.get(server,"/log4j/logging");
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(log4j) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(log4j) GET requested",null) };
assertContainsLogEvents(testAppender,expectedLogs);
}
public void testEmbeddedWebappSlf4j() throws Exception
{
Server server = createWebAppServer("/slf4j","dummy-webapp-logging-slf4j.war");
server.start();
SimpleRequest.get(server,"/slf4j/logging");
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(null,-1,Severity.DEBUG,"LoggingServlet","LoggingServlet(slf4j) initialized",null),
new LogEvent(null,-1,Severity.INFO,"LoggingServlet","LoggingServlet(slf4j) GET requested",null) };
assertContainsLogEvents(testAppender,expectedLogs);
}
}

View File

@ -22,8 +22,6 @@ import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URI;
import junit.framework.Assert;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.IO;
@ -33,6 +31,8 @@ import org.eclipse.jetty.util.IO;
*/
public class SimpleRequest
{
private static final boolean CONN_TRACE = false;
/**
* Issue an HTTP GET to the server, on the path specified.
*
@ -81,28 +81,42 @@ public class SimpleRequest
{
System.out.println("GET: " + fullUri.toASCIIString());
trace("Opening Connection ...");
HttpURLConnection conn = (HttpURLConnection)fullUri.toURL().openConnection();
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
trace("Connecting ...");
conn.connect();
Assert.assertEquals(fullUri.toASCIIString() + " Response Code (200 OK)",200,conn.getResponseCode());
trace("Connected.");
InputStream in = null;
InputStreamReader reader = null;
try
{
trace("Getting InputStream ...");
in = conn.getInputStream();
trace("Got InputStream.");
reader = new InputStreamReader(in);
trace("Reading InputStream to String ...");
String response = IO.toString(reader);
trace("Checking Response Code ...");
if (conn.getResponseCode() != 200)
{
System.out.printf("Got HTTP Response %d, expecting %d.%n",conn.getResponseCode(),200);
System.out.println(response);
}
else if ((response != null) && (response.trim().length() > 0))
{
System.out.println(response);
}
trace("Returning response.");
return response;
}
finally
@ -111,4 +125,13 @@ public class SimpleRequest
IO.close(in);
}
}
private static void trace(String format, Object... args)
{
if (CONN_TRACE)
{
System.out.printf(format,args);
System.out.println();
}
}
}

View File

@ -183,6 +183,10 @@ public class XmlConfiguredJetty
}
Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + serverPort + ">",(1 <= this.serverPort) && (this.serverPort <= 65535));
// Uncomment to have server start and continue to run (without exiting)
// System.out.printf("Listening to port %d%n",this.serverPort);
// server.join();
}
public int getServerPort()

View File

@ -61,6 +61,10 @@ public class TestAppender implements Appender
{
if (name.equals("log")) // standard jetty logger
{
if (t != null)
{
t.printStackTrace(System.err);
}
return; // skip storing it.
}
events.add(new LogEvent(date,ms,severity,name,message,t));
@ -112,4 +116,13 @@ public class TestAppender implements Appender
{
/* nothing to do here */
}
public void dump()
{
System.out.printf("Captured %s event(s)%n",events.size());
for (LogEvent event : events)
{
System.out.println(event);
}
}
}