Author: markt
Date: Fri Oct 26 19:25:50 2012
New Revision: 1402622

URL: http://svn.apache.org/viewvc?rev=1402622&view=rev
Log:
Fix EOL for test case.
Copy fix to similar code in JULI.

Modified:
    tomcat/trunk/java/org/apache/juli/DateFormatCache.java
    tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java   
(contents, props changed)

Modified: tomcat/trunk/java/org/apache/juli/DateFormatCache.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/DateFormatCache.java?rev=1402622&r1=1402621&r2=1402622&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/DateFormatCache.java (original)
+++ tomcat/trunk/java/org/apache/juli/DateFormatCache.java Fri Oct 26 19:25:50 
2012
@@ -101,14 +101,14 @@ public class DateFormatCache {
     private class Cache {
 
         /* Second formatted in most recent invocation */
-        private long previousSeconds = 0L;
+        private long previousSeconds = Long.MIN_VALUE;
         /* Formatted timestamp generated in most recent invocation */
         private String previousFormat = "";
 
         /* First second contained in cache */
-        private long first = 0L;
+        private long first = Long.MIN_VALUE;
         /* Last second contained in cache */
-        private long last = 0L;
+        private long last = Long.MIN_VALUE;
         /* Index of "first" in the cyclic cache */
         private int offset = 0;
         /* Helper object to be able to call SimpleDateFormat.format(). */
@@ -165,14 +165,16 @@ public class DateFormatCache {
                 for (int i = 1; i < seconds - last; i++) {
                     cache[(index + cacheSize - i) % cacheSize] = null;
                 }
-                first = seconds - cacheSize;
+                first = seconds - (cacheSize - 1);
                 last = seconds;
+                offset = (index + 1) % cacheSize;
             } else if (seconds < first) {
                 for (int i = 1; i < first - seconds; i++) {
                     cache[(index + i) % cacheSize] = null;
                 }
                 first = seconds;
-                last = seconds + cacheSize;
+                last = seconds + (cacheSize - 1);
+                offset = index;
             }
 
             /* Last step: format new timestamp either using

Modified: tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java?rev=1402622&r1=1402621&r2=1402622&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java Fri 
Oct 26 19:25:50 2012
@@ -1,92 +1,92 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.catalina.valves;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestAccessLogValve {
-
-    @Test
-    public void testBug54044() throws Exception {
-
-        final int cacheSize = 10;
-
-        SimpleDateFormat sdf =
-                new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss", Locale.US);
-        sdf.setTimeZone(TimeZone.getDefault());
-
-        AccessLogValve.DateFormatCache dfc =
-                new AccessLogValve.DateFormatCache(
-                        cacheSize, Locale.US, null);
-
-        // Create an array to hold the expected values
-        String[] expected = new String[cacheSize];
-
-        // Fill the cache & populate the expected values
-        for (int secs = 0; secs < (cacheSize); secs++) {
-            dfc.getFormat(secs * 1000);
-            expected[secs] = generateExpected(sdf, secs);
-        }
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-
-        // Cause the cache to roll-around by one and then confirm
-        dfc.getFormat(cacheSize * 1000);
-        expected[0] = generateExpected(sdf, cacheSize);
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-        // Jump 2 ahead and then confirm (skipped value should be null)
-        dfc.getFormat((cacheSize + 2)* 1000);
-        expected[1] = null;
-        expected[2] = generateExpected(sdf, cacheSize + 2);
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-        // Back 1 to fill in the gap
-        dfc.getFormat((cacheSize + 1)* 1000);
-        expected[1] = generateExpected(sdf, cacheSize + 1);
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-        // Return to 1 and confirm skipped value is null
-        dfc.getFormat(1 * 1000);
-        expected[1] = generateExpected(sdf, 1);
-        expected[2] = null;
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-        // Go back one further
-        dfc.getFormat(0);
-        expected[0] = generateExpected(sdf, 0);
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-
-        // Jump ahead far enough that the entire cache will need tp be cleared
-        dfc.getFormat(42 * 1000);
-        for (int i = 0; i < cacheSize; i++) {
-            expected[i] = null;
-        }
-        expected[0] = generateExpected(sdf, 42);
-        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
-    }
-
-    private String generateExpected(SimpleDateFormat sdf, long secs) {
-        return "[" + sdf.format(new Date(secs * 1000)) + " +0000]";
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.valves;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAccessLogValve {
+
+    @Test
+    public void testBug54044() throws Exception {
+
+        final int cacheSize = 10;
+
+        SimpleDateFormat sdf =
+                new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss", Locale.US);
+        sdf.setTimeZone(TimeZone.getDefault());
+
+        AccessLogValve.DateFormatCache dfc =
+                new AccessLogValve.DateFormatCache(
+                        cacheSize, Locale.US, null);
+
+        // Create an array to hold the expected values
+        String[] expected = new String[cacheSize];
+
+        // Fill the cache & populate the expected values
+        for (int secs = 0; secs < (cacheSize); secs++) {
+            dfc.getFormat(secs * 1000);
+            expected[secs] = generateExpected(sdf, secs);
+        }
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+
+        // Cause the cache to roll-around by one and then confirm
+        dfc.getFormat(cacheSize * 1000);
+        expected[0] = generateExpected(sdf, cacheSize);
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+        // Jump 2 ahead and then confirm (skipped value should be null)
+        dfc.getFormat((cacheSize + 2)* 1000);
+        expected[1] = null;
+        expected[2] = generateExpected(sdf, cacheSize + 2);
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+        // Back 1 to fill in the gap
+        dfc.getFormat((cacheSize + 1)* 1000);
+        expected[1] = generateExpected(sdf, cacheSize + 1);
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+        // Return to 1 and confirm skipped value is null
+        dfc.getFormat(1 * 1000);
+        expected[1] = generateExpected(sdf, 1);
+        expected[2] = null;
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+        // Go back one further
+        dfc.getFormat(0);
+        expected[0] = generateExpected(sdf, 0);
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+
+        // Jump ahead far enough that the entire cache will need tp be cleared
+        dfc.getFormat(42 * 1000);
+        for (int i = 0; i < cacheSize; i++) {
+            expected[i] = null;
+        }
+        expected[0] = generateExpected(sdf, 42);
+        Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
+    }
+
+    private String generateExpected(SimpleDateFormat sdf, long secs) {
+        return "[" + sdf.format(new Date(secs * 1000)) + " +0000]";
+    }
+}

Propchange: tomcat/trunk/test/org/apache/catalina/valves/TestAccessLogValve.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to