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

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

      
    
Rootfs path

      
    
Size
3316 (3.2 KB)
MD5
f6559433fb87b9d31ff1e9226b92add6
SHA1
90e7dc102995f9d65bc5ea2281437141c92b9987
SHA256
2ecf21c053aad17546c272f9a6bbff4dfaf10f1f792744fd64d4367388fb46a4
SHA512

      
    
SHA1_git
aee821c837464bea1cf4935474ffadf41f82e64d
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestPersistentValve.java | 3.2 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.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import jakarta.servlet.ServletException; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.tomcat.unittest.TesterRequest; import org.apache.tomcat.unittest.TesterResponse; public class TestPersistentValve { @Test public void testSemaphore() throws Exception { // Create the test objects PersistentValve pv = new PersistentValve(); Request request = new TesterRequest(); Response response = new TesterResponse(); TesterValve testerValve = new TesterValve(); // Configure the test objects request.setRequestedSessionId("1234"); // Plumb the test objects together pv.setContainer(request.getContext()); pv.setNext(testerValve); // Call the necessary lifecycle methods pv.init(); // Run the test Thread[] threads = new Thread[5]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(() -> { try { pv.invoke(request, response); } catch (IOException | ServletException e) { throw new RuntimeException(e); } }); } for (int i = 0; i < threads.length; i++) { threads[i].start(); } for (int i = 0; i < threads.length; i++) { threads[i].join(); } Assert.assertEquals(1, testerValve.getMaximumConcurrency()); } private static class TesterValve extends ValveBase { private static AtomicInteger maximumConcurrency = new AtomicInteger(); private static AtomicInteger concurrency = new AtomicInteger(); @Override public void invoke(Request request, Response response) throws IOException, ServletException { int c = concurrency.incrementAndGet(); maximumConcurrency.getAndUpdate((v) -> c > v ? c : v); try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore } concurrency.decrementAndGet(); } public int getMaximumConcurrency() { return maximumConcurrency.get(); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.1
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 8 8