ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/http/TestFastHttpDateFormat.java

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

      
    
Rootfs path

      
    
Size
3036 (3.0 KB)
MD5
2b0339a3b01ae5dfac8e5b9e1b131e4e
SHA1
bd42ce4d74145e0ddb0af7c36acccbe8d3eab6cf
SHA256
4f3f6334a7d17d7c04400ff4277a98b793164b53b53b820a1f7ddfa32cb8de67
SHA512

      
    
SHA1_git
02f7b9717e4a6adfceae4643e47bc5071cc0766e
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestFastHttpDateFormat.java | 3.0 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.tomcat.util.http; import org.junit.Assert; import org.junit.Test; public class TestFastHttpDateFormat { @Test public void testGetCurrentDate() { /* * Run three iterations of the test. The runs are offset by 1300 seconds to ensure that FastHttpDateFormat is * using a 1s window aligned with the start of a second. */ for (int i = 0; i < 3; i++) { if (i > 0) { try { Thread.sleep(1300); } catch (InterruptedException e) { Assert.fail("InterruptedException observed"); } } String d1 = FastHttpDateFormat.getCurrentDate(); long start = System.currentTimeMillis() / 1000; long t1 = start; long t2 = 0; long t3 = 0; String d2 = d1; /* * Run this test for 3s. Should normally see 3 changes of date. Because d1 and t1 are not set atomically, * it is possible for them to be inconsistent. That inconsistency can lead to one more or one less change * than typically expected. Therefore, the test accepts 2, 3 or 4 changes. */ int changes = 0; while (t1 - start < 3) { // Copy results to next slot, dropping the oldest (t3 and d2) d2 = d1; t3 = t2; t2 = t1; // Get current results. The date must be obtained before the current time. d1 = FastHttpDateFormat.getCurrentDate(); t1 = System.currentTimeMillis() / 1000; // Has the formatted date changed if (!d2.equals(d1)) { changes++; // Then the second must have changed if (t1 == t2 && t2 == t3) { Assert.fail("Formatted date changed within the same second"); } } } Assert.assertTrue("Saw [" + changes + "] changes in formatted date", changes > 1 && changes < 5); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
34.59
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