[tomcat] branch 9.0.x updated: Add UDS test case

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 9.0.x updated: Add UDS test case

remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 997dab6  Add UDS test case
997dab6 is described below

commit 997dab63f0e2892faed76df2bde2084f5ea99185
Author: remm <[hidden email]>
AuthorDate: Mon Jan 18 12:11:53 2021 +0100

    Add UDS test case
   
    And a Java 16 compat flag.
---
 java/org/apache/tomcat/util/compat/JreCompat.java  |  9 +++++++
 .../apache/tomcat/util/net/TestXxxEndpoint.java    | 29 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java b/java/org/apache/tomcat/util/compat/JreCompat.java
index 73a109f..00f0fb7 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -45,6 +45,7 @@ public class JreCompat {
 
     private static final JreCompat instance;
     private static final boolean graalAvailable;
+    private static final boolean jre16Available;
     private static final boolean jre11Available;
     private static final boolean jre9Available;
     private static final StringManager sm = StringManager.getManager(JreCompat.class);
@@ -69,12 +70,15 @@ public class JreCompat {
         if (Jre16Compat.isSupported()) {
             instance = new Jre16Compat();
             jre9Available = true;
+            jre16Available = true;
         } else if (Jre9Compat.isSupported()) {
             instance = new Jre9Compat();
             jre9Available = true;
+            jre16Available = false;
         } else {
             instance = new JreCompat();
             jre9Available = false;
+            jre16Available = false;
         }
         jre11Available = instance.jarFileRuntimeMajorVersion() >= 11;
 
@@ -116,6 +120,11 @@ public class JreCompat {
     }
 
 
+    public static boolean isJre16Available() {
+        return jre16Available;
+    }
+
+
     // Java 8 implementation of Java 9 methods
 
     /**
diff --git a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
index ab08bf7..4cbd8b2 100644
--- a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
+++ b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
@@ -19,8 +19,12 @@ package org.apache.tomcat.util.net;
 import java.io.File;
 import java.net.InetAddress;
 import java.net.ServerSocket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Test;
 
 import org.apache.catalina.connector.Connector;
@@ -32,6 +36,7 @@ import org.apache.tomcat.jni.Library;
 import org.apache.tomcat.jni.OS;
 import org.apache.tomcat.jni.Pool;
 import org.apache.tomcat.jni.Socket;
+import org.apache.tomcat.util.compat.JreCompat;
 
 /**
  * Test case for the Endpoint implementations. The testing framework will ensure
@@ -195,4 +200,28 @@ public class TestXxxEndpoint extends TomcatBaseTest {
         Assert.assertNull(e);
         tomcat.getConnector().start();
     }
+
+    @Test
+    public void testUnixDomainSocket() throws Exception {
+
+        Tomcat tomcat = getTomcatInstance();
+        Connector c = tomcat.getConnector();
+        Assume.assumeTrue("SSL renegotiation has to be supported for this test",
+                c.getProtocolHandlerClassName().contains("Nio")
+                && JreCompat.isJre16Available());
+
+        final String unixDomainSocketPath = "/tmp/testUnixDomainSocket";
+        Assert.assertTrue(c.setProperty("unixDomainSocketPath", unixDomainSocketPath));
+        tomcat.start();
+
+        SocketAddress sa = JreCompat.getInstance().getUnixDomainSocketAddress(unixDomainSocketPath);
+        ByteBuffer response = ByteBuffer.allocate(1024);
+        try (SocketChannel socket = JreCompat.getInstance().openUnixDomainSocketChannel()) {
+            socket.connect(sa);
+            socket.write(ByteBuffer.wrap("OPTIONS * HTTP/1.0\r\n\r\n".getBytes()));
+            socket.read(response);
+        }
+
+        Assert.assertTrue((new String(response.array(), 0, response.position()).startsWith("HTTP/1.1 200")));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]