From 3f172067c4e43accc64422d027df2bac4c5a0055 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 20 Jan 2012 11:12:26 -0700 Subject: [PATCH 01/10] Fixing tests so that when run on a CI within jetty itself, --- jetty-start/pom.xml | 4 ++-- .../java/org/eclipse/jetty/start/MainTest.java | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jetty-start/pom.xml b/jetty-start/pom.xml index 9fcfa2c2cc8..7d622d115e6 100644 --- a/jetty-start/pom.xml +++ b/jetty-start/pom.xml @@ -34,8 +34,8 @@ - junit - junit + org.eclipse.jetty.toolchain + jetty-test-helper test diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 8e2f1f071bb..63143c7c377 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -13,12 +13,13 @@ package org.eclipse.jetty.start; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; +import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.List; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.junit.Before; import org.junit.Test; @@ -34,18 +35,13 @@ public class MainTest @Before public void setUp() throws Exception { - System.setProperty("jetty.home",this.getClass().getResource("/jetty.home").getFile()); + File testJettyHome = MavenTestingUtils.getTestResourceDir("jetty.home"); + System.setProperty("jetty.home",testJettyHome.getAbsolutePath()); } - /** - * Test method for {@link org.eclipse.jetty.start.StartIniParser#loadStartIni(java.lang.String)}. - * @throws IOException - */ @Test public void testLoadStartIni() throws IOException { - URL startIni = this.getClass().getResource("/jetty.home/"); - System.setProperty("jetty.home",startIni.getFile()); Main main = new Main(); List args = main.parseStartIniFiles(); assertEquals("Expected 5 uncommented lines in start.ini",9,args.size()); From 3df95d45c27c924c1f0e76c4c16a3f796ddf2470 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 20 Jan 2012 11:27:38 -0700 Subject: [PATCH 02/10] Making --dry-run work with paths that have spaces --- .../java/org/eclipse/jetty/start/Main.java | 19 +++++++++++-------- .../jetty/test/monitor/ProgramConfigTest.java | 8 +------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 69112f8f319..34715f9a7bd 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -663,17 +663,19 @@ public class Main { StringBuilder cmd = new StringBuilder(); cmd.append(findJavaBin()); - for (String x : _jvmArgs) - cmd.append(' ').append(x); - cmd.append(" -Djetty.home=").append(_jettyHome); + for (String x : _jvmArgs) { + cmd.append(" \"").append(x).append("\""); + } + cmd.append(" \"-Djetty.home=").append(_jettyHome).append("\""); for (String p : _sysProps) { - cmd.append(" -D").append(p); + cmd.append(" \"-D").append(p); String v = System.getProperty(p); if (v != null && v.length() > 0) cmd.append('=').append(v); + cmd.append("\""); } - cmd.append(" -cp ").append(classpath.toString()); + cmd.append(" -cp \"").append(classpath.toString()).append("\""); cmd.append(" ").append(_config.getMainClassname()); // Check if we need to pass properties as a file @@ -681,15 +683,16 @@ public class Main if (properties.size() > 0) { File prop_file = File.createTempFile("start",".properties"); - if (!_dryRun) + if (!_dryRun) { prop_file.deleteOnExit(); + } properties.store(new FileOutputStream(prop_file),"start.jar properties"); - cmd.append(" ").append(prop_file.getAbsolutePath()); + cmd.append(" \"").append(prop_file.getAbsolutePath()).append("\""); } for (String xml : xmls) { - cmd.append(' ').append(xml); + cmd.append(" \"").append(xml).append("\""); } return cmd.toString(); diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/monitor/ProgramConfigTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/monitor/ProgramConfigTest.java index 20c170f0cef..5d658b28f2a 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/monitor/ProgramConfigTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/monitor/ProgramConfigTest.java @@ -13,15 +13,11 @@ package org.eclipse.jetty.test.monitor; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import javax.management.MBeanServerConnection; - import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.http.HttpMethods; @@ -35,7 +31,6 @@ import org.eclipse.jetty.monitor.jmx.MonitorAction; import org.eclipse.jetty.monitor.triggers.GreaterThanAttrEventTrigger; import org.eclipse.jetty.monitor.triggers.LessThanOrEqualToAttrEventTrigger; import org.eclipse.jetty.monitor.triggers.OrEventTrigger; -import org.eclipse.jetty.toolchain.jmx.JmxServiceConnection; import org.eclipse.jetty.toolchain.test.JettyDistro; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -98,7 +93,7 @@ public class ProgramConfigTest @Override public void execute(EventTrigger trigger, EventState state, long timestamp) { - System.out.println(counter.incrementAndGet()); + counter.incrementAndGet(); } }; JMXMonitor.addMonitorActions(action); @@ -121,7 +116,6 @@ public class ProgramConfigTest } gate.await(); JMXMonitor.removeMonitorActions(action); - assertTrue(true); } protected static void runTest(String requestUrl, long count) From 5c08b066224505403f10c69acc85ad5416fa4a96 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 23 Jan 2012 10:19:08 +1100 Subject: [PATCH 03/10] improved test --- .../org/eclipse/jetty/util/DateCacheTest.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java index 15284fd2493..76a061dbe1c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/DateCacheTest.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import java.util.Locale; import java.util.TimeZone; @@ -69,12 +70,26 @@ public class DateCacheTest // Test string is cached dc = new DateCache(); - String s1=dc.format(System.currentTimeMillis()); - dc.format(1); - String s2=dc.format(System.currentTimeMillis()); - dc.format(System.currentTimeMillis()+10*60*60); - String s3=dc.format(System.currentTimeMillis()); - assertTrue(s1==s2 || s2==s3); + long now = 1000L*(System.currentTimeMillis()%1000L)+123; + // format a time for now + String s1=dc.format(now); + + // format a time in the past (this should not reset cached date) + dc.format(now-2000); + + // format a time a little later than now + String s2=dc.format(now+10); + + // format a time in future (this should reset cached data) + dc.format(now+2000); + + // format time a little later than now + String s3=dc.format(now+20); + + assertEquals(s1,s2); + assertEquals(s2,s3); + assertTrue(s1==s2); + assertFalse(s2==s3); } } From bc5ac3622aa39b6e60b96ab24b0fb11c09535172 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 23 Jan 2012 13:13:28 +1100 Subject: [PATCH 04/10] 369349 replace quotes with a space escape method --- .../java/org/eclipse/jetty/start/Main.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 34715f9a7bd..a221c34eb60 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -664,39 +664,40 @@ public class Main StringBuilder cmd = new StringBuilder(); cmd.append(findJavaBin()); for (String x : _jvmArgs) { - cmd.append(" \"").append(x).append("\""); + cmd.append(x); } - cmd.append(" \"-Djetty.home=").append(_jettyHome).append("\""); + cmd.append(" -Djetty.home=").append(escapeSpaces(_jettyHome)); for (String p : _sysProps) { - cmd.append(" \"-D").append(p); + cmd.append(" -D").append(p); String v = System.getProperty(p); if (v != null && v.length() > 0) - cmd.append('=').append(v); - cmd.append("\""); + cmd.append("=").append(escapeSpaces(v)); } - cmd.append(" -cp \"").append(classpath.toString()).append("\""); - cmd.append(" ").append(_config.getMainClassname()); + cmd.append(" -cp ").append(classpath.toString()); + cmd.append(" ").append(_config.getMainClassname()); // Check if we need to pass properties as a file Properties properties = Config.getProperties(); if (properties.size() > 0) { File prop_file = File.createTempFile("start",".properties"); - if (!_dryRun) { + if (!_dryRun) prop_file.deleteOnExit(); - } properties.store(new FileOutputStream(prop_file),"start.jar properties"); - cmd.append(" \"").append(prop_file.getAbsolutePath()).append("\""); + cmd.append(" ").append(escapeSpaces(prop_file.getAbsolutePath())); } for (String xml : xmls) - { - cmd.append(" \"").append(xml).append("\""); - } + cmd.append(" ").append(escapeSpaces(xml)); return cmd.toString(); } + + private static String escapeSpaces(String s) + { + return s.replace(" ","\\ "); + } private String findJavaBin() { From ae5ddb2930ac2e247047e0c51f83a8b94f94353f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 23 Jan 2012 14:31:25 +1100 Subject: [PATCH 05/10] 369216 turned off the shared resource cache --- jetty-webapp/src/main/config/etc/webdefault.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jetty-webapp/src/main/config/etc/webdefault.xml b/jetty-webapp/src/main/config/etc/webdefault.xml index 99ee5feda99..213138b35fe 100644 --- a/jetty-webapp/src/main/config/etc/webdefault.xml +++ b/jetty-webapp/src/main/config/etc/webdefault.xml @@ -157,10 +157,12 @@ useFileMappedBuffer true +