ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/valves/TestAccessLogValveDateFormatCache.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/valves/TestAccessLogValveDateFormatCache.java
Status
scanned
Type
file
Name
TestAccessLogValveDateFormatCache.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3543 (3.5 KB)
MD5
5ab3e0883879c575b477e21722878726
SHA1
a9c9cd0fb020a972fd39f4d3985c59f3e10f41d0
SHA256
36ad7ac6ff41d46e95ae44903dd8202d44c8202acc20eaa7c49fea06d012be80
SHA512

      
    
SHA1_git
1399c0cbe76990d25a64c008074afebc28f6f5d7
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestAccessLogValveDateFormatCache.java | 3.5 KB |

/* * 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 TestAccessLogValveDateFormatCache { // Note that there is a similar test: // org.apache.juli.TestDateFormatCache.testBug54044() @Test public void testBug54044() throws Exception { final int cacheSize = 10; SimpleDateFormat sdf = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]", 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 to 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)); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
28.47
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9