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

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

      
    
Rootfs path

      
    
Size
4422 (4.3 KB)
MD5
47a179557433445d600890cbffaacc28
SHA1
2a70f3e6442b5b11726654b56526e9ece056e45d
SHA256
4a04f4e679c3be8fe5822be3ef1f481569d2e742304c6da52a0b3e195cd9c006
SHA512

      
    
SHA1_git
ec0150ed3b3e5984f5992e262ee523fabd5e12e4
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestHealthCheckValve.java | 4.3 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 jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.util.buf.ByteChunk; public class TestHealthCheckValve extends TomcatBaseTest { @Test public void testServerHealthCheck() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = getProgrammaticRootContext(); HealthCheckValve healthCheckValve = new HealthCheckValve(); ctx.getParent().getPipeline().addValve(healthCheckValve); tomcat.start(); ByteChunk result = new ByteChunk(); int rc = getUrl("http://localhost:" + getPort() + "/foo", result, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); result.recycle(); rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(result.toString().contains("UP")); result.recycle(); ctx.stop(); rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_SERVICE_UNAVAILABLE, rc); Assert.assertTrue(result.toString().contains("DOWN")); healthCheckValve.setCheckContainersAvailable(false); result.recycle(); rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(result.toString().contains("UP")); } @Test public void testContextHealthCheck() throws Exception { Tomcat tomcat = getTomcatInstance(); // No file system docBase required Context ctx = getProgrammaticRootContext(); HealthCheckValve healthCheckValve = new HealthCheckValve(); ctx.getPipeline().addValve(healthCheckValve); tomcat.start(); ByteChunk result = new ByteChunk(); int rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(result.toString().contains("UP")); result.recycle(); ctx.stop(); healthCheckValve.setPath("/customhealthpath"); rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); result.recycle(); Tomcat.addServlet(ctx, "dummy", new DummyServlet()); Container wrapper = ctx.findChild("dummy"); ctx.start(); wrapper.stop(); rc = getUrl("http://localhost:" + getPort() + healthCheckValve.getPath(), result, null); Assert.assertEquals(HttpServletResponse.SC_SERVICE_UNAVAILABLE, rc); Assert.assertTrue(result.toString().contains("DOWN")); } private static final class DummyServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void service(ServletRequest request, ServletResponse response) { } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
26.98
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