From 0c4a266d60b657baf1a7cd27c9ed70cdd938bacd Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 4 Jun 2013 09:04:12 -0700 Subject: [PATCH 1/3] Fixing JDK5 test error with comparison of query string --- .../org/eclipse/jetty/servlet/DispatcherTest.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java index 8f3d61ebeaf..e6a8b4923c1 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DispatcherTest.java @@ -18,8 +18,10 @@ package org.eclipse.jetty.servlet; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThat; import java.io.IOException; import java.util.Arrays; @@ -55,6 +57,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.UrlEncoded; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -585,8 +588,15 @@ public class DispatcherTest assertTrue(requestAttributeNames.containsAll(expectedAttributeNames)); assertEquals(null, request.getPathInfo()); - assertEquals(null, request.getPathTranslated()); - assertTrue(request.getQueryString().startsWith("do=end&else=%D0%B2%D1%8B%D0%B1%D1%80%D0%B0%D0%BD%D0%BE%3D%D0%A2%D0%B5%D0%BC%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D1%83%D1%80%D0%B0&test=1&foreign=")); + assertEquals(null, request.getPathTranslated()); + + UrlEncoded query = new UrlEncoded(request.getQueryString()); + assertThat(query.getString("do"), is("end")); + // Russian for "selected=Temperature" + String russian = new UrlEncoded(query.getString("else")).encode(); + assertThat(russian, is("%D0%B2%D1%8B%D0%B1%D1%80%D0%B0%D0%BD%D0%BE=%D0%A2%D0%B5%D0%BC%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D1%83%D1%80%D0%B0")); + assertThat(query.getString("test"), is("1")); + assertThat(query.containsKey("foreign"), is(true)); String[] vals = request.getParameterValues("foreign"); assertTrue(vals!=null); From 559069cdd64f19113c7a2a44485be621306bb02f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 4 Jun 2013 09:57:04 -0700 Subject: [PATCH 2/3] JDK5 fix for bad JarFile resource caching during deploy tests --- .../ScanningAppProviderRuntimeUpdatesTest.java | 12 ++++++++++-- .../jetty/deploy/test/XmlConfiguredJetty.java | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java index c127b7a5eff..34d36151ab2 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java @@ -25,10 +25,12 @@ import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.toolchain.test.OS; +import org.eclipse.jetty.toolchain.test.TestTracker; import org.eclipse.jetty.toolchain.test.TestingDir; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.Resource; import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -43,6 +45,9 @@ public class ScanningAppProviderRuntimeUpdatesTest { private static final Logger LOG = Log.getLogger(ScanningAppProviderRuntimeUpdatesTest.class); + @Rule + public TestTracker tracker = new TestTracker(); + @Rule public TestingDir testdir = new TestingDir(); private static XmlConfiguredJetty jetty; @@ -52,6 +57,9 @@ public class ScanningAppProviderRuntimeUpdatesTest @Before public void setupEnvironment() throws Exception { + testdir.ensureEmpty(); + Resource.setDefaultUseCaches(false); + jetty = new XmlConfiguredJetty(testdir); jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml"); @@ -90,7 +98,7 @@ public class ScanningAppProviderRuntimeUpdatesTest public void waitForDirectoryScan() { - int scan=_scans.get()+2*_providers; + int scan=_scans.get()+(2*_providers); do { try @@ -167,8 +175,8 @@ public class ScanningAppProviderRuntimeUpdatesTest waitForDirectoryScan(); System.out.println("Updating war files"); - jetty.copyContext("foo.xml","foo.xml"); // essentially "touch" the context xml jetty.copyWebapp("foo-webapp-2.war","foo.war"); + jetty.copyContext("foo.xml","foo.xml"); // essentially "touch" the context xml // This should result in the existing foo.war being replaced with the new foo.war waitForDirectoryScan(); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java index d538e8d1dae..c2f61be5b51 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.deploy.test; +import static org.hamcrest.Matchers.*; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -213,6 +215,7 @@ public class XmlConfiguredJetty if (context.getContextPath().equals(expectedPath)) { found = true; + Assert.assertThat("Context[" + context.getContextPath() + "].state", context.getState(), is("STARTED")); break; } } From 4b458792c90bddc134f830a00fc9a1535e589bb2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 4 Jun 2013 10:42:32 -0700 Subject: [PATCH 3/3] JDK5 build fix with Resource caching and path lookups --- .../ReloadedSessionMissingClassTest.java | 29 ++++++++----------- .../session/WebAppObjectInSessionTest.java | 2 ++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java index 54094cd206f..3021e8d7c68 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/ReloadedSessionMissingClassTest.java @@ -18,9 +18,7 @@ package org.eclipse.jetty.server.session; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.File; import java.io.FileWriter; @@ -32,35 +30,32 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.http.HttpMethods; -import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.TestingDir; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.StdErrLog; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.Rule; import org.junit.Test; /** * ReloadedSessionMissingClassTest - * - * - * */ public class ReloadedSessionMissingClassTest { + @Rule + public TestingDir testdir = new TestingDir(); @Test public void testSessionReloadWithMissingClass() throws Exception { ((StdErrLog)Log.getLogger(org.eclipse.jetty.server.session.JDBCSessionManager.class)).setHideStacks(true); + Resource.setDefaultUseCaches(false); String contextPath = "/foo"; - File srcDir = new File(System.getProperty("basedir"), "src"); - File targetDir = new File(System.getProperty("basedir"), "target"); - File testDir = new File (srcDir, "test"); - File resourcesDir = new File (testDir, "resources"); - File unpackedWarDir = new File (targetDir, "foo"); - if (unpackedWarDir.exists()) - IO.delete(unpackedWarDir); - unpackedWarDir.mkdir(); + File unpackedWarDir = testdir.getDir(); + testdir.ensureEmpty(); File webInfDir = new File (unpackedWarDir, "WEB-INF"); webInfDir.mkdir(); @@ -81,8 +76,8 @@ public class ReloadedSessionMissingClassTest w.write(xml); w.close(); - File foobarJar = new File (resourcesDir, "foobar.jar"); - File foobarNOfooJar = new File (resourcesDir, "foobarNOfoo.jar"); + File foobarJar = MavenTestingUtils.getTestResourceFile("foobar.jar"); + File foobarNOfooJar = MavenTestingUtils.getTestResourceFile("foobarNOfoo.jar"); URL[] foobarUrls = new URL[]{foobarJar.toURI().toURL()}; URL[] barUrls = new URL[]{foobarNOfooJar.toURI().toURL()}; diff --git a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java index bc6d47cac69..fe6675b2012 100644 --- a/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java +++ b/tests/test-sessions/test-jdbc-sessions/src/test/java/org/eclipse/jetty/server/session/WebAppObjectInSessionTest.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.server.session; +import org.eclipse.jetty.util.resource.Resource; import org.junit.Test; /** @@ -30,6 +31,7 @@ public class WebAppObjectInSessionTest extends AbstractWebAppObjectInSessionTest public AbstractTestServer createServer(int port) { + Resource.setDefaultUseCaches(false); return new JdbcTestServer(port); }