ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/util/TestTimeBucketCounter.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/util/TestTimeBucketCounter.java
Status
scanned
Type
file
Name
TestTimeBucketCounter.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
ac1995e3a18f9b228e02124adee672a7
SHA1
47a059d55b17f6798a622250e12aa78b90987dee
SHA256
741378d37d6523151ca881f7ec2fe42ceb687dd577914f5721daa7c43e3a1f4d
SHA512

      
    
SHA1_git
650a6e1f60be842eeab122c8b5e0064bdccb2ec2
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestTimeBucketCounter.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.catalina.util; import org.junit.Assert; import org.junit.Test; public class TestTimeBucketCounter { static final double DELTA = 0.001; @Test public void testNextPowerOf2() { Assert.assertEquals(128, TimeBucketCounter.nextPowerOf2(100)); Assert.assertEquals(128, TimeBucketCounter.nextPowerOf2(127)); Assert.assertEquals(128, TimeBucketCounter.nextPowerOf2(128)); Assert.assertEquals(256, TimeBucketCounter.nextPowerOf2(250)); Assert.assertEquals(1024, TimeBucketCounter.nextPowerOf2(1000)); Assert.assertEquals(1024, TimeBucketCounter.nextPowerOf2(1023)); Assert.assertEquals(2048, TimeBucketCounter.nextPowerOf2(1025)); } @Test public void testCalcRatioToNextPowerOf2() { Assert.assertEquals(256 / 256d, TimeBucketCounter.ratioToPowerOf2(256), DELTA); Assert.assertEquals(256 / 200d, TimeBucketCounter.ratioToPowerOf2(200), DELTA); Assert.assertEquals(65_536 / 60_000d, TimeBucketCounter.ratioToPowerOf2(60_000), DELTA); } @Test public void testTimeBucketCounter() { TimeBucketCounter tbc = new TimeBucketCounter(60, new java.util.concurrent.ScheduledThreadPoolExecutor(1)); Assert.assertEquals(16, tbc.getNumBits()); Assert.assertEquals(1.092, tbc.getRatio(), DELTA); } @Test public void testGetMillisUntilNextBucket() throws InterruptedException { long millis; int tb1, tb2; TimeBucketCounter tbc = new TimeBucketCounter(2, new java.util.concurrent.ScheduledThreadPoolExecutor(1)); tb1 = tbc.getCurrentBucketPrefix(); millis = tbc.getMillisUntilNextBucket(); // sleep millis and get bucket Thread.sleep(millis); tb2 = tbc.getCurrentBucketPrefix(); // ensure the new time bucket is one more than the previous one Assert.assertEquals(1, tb2 - tb1); tb1 = tb2; millis = tbc.getMillisUntilNextBucket(); // sleep again Thread.sleep(millis); tb2 = tbc.getCurrentBucketPrefix(); // ensure again Assert.assertEquals(1, tb2 - tb1); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
37.19
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