Skip to content

Commit

Permalink
Issue #6043 - Reimplement UnixSocket support based on Java 16.
Browse files Browse the repository at this point in the history
Replaced unix.socket.tmp with better named jetty.unixdomain.dir property.
Defaulted jetty.unixdomain.dir property to system property user.home under Windows.
Simplified code that runs Unix-Domain tests.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Aug 4, 2021
1 parent 1b5ce37 commit 82106cf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Expand Up @@ -99,7 +99,7 @@ def mavenBuild(jdk, cmdline, mvnName) {
"MAVEN_OPTS=-Xms2g -Xmx4g -Djava.awt.headless=true"]) {
configFileProvider(
[configFile(fileId: 'oss-settings.xml', variable: 'GLOBAL_MVN_SETTINGS')]) {
sh "mvn --no-transfer-progress -s $GLOBAL_MVN_SETTINGS -Dmaven.repo.local=.repository -Pci -V -B -e -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=/tmp/unixsocket"
sh "mvn --no-transfer-progress -s $GLOBAL_MVN_SETTINGS -Dmaven.repo.local=.repository -Pci -V -B -e -Djetty.testtracker.log=true $cmdline"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile-autobahn
Expand Up @@ -80,7 +80,7 @@ def mavenBuild(jdk, cmdline, mvnName, junitPublishDisabled) {
mavenOpts: mavenOpts,
mavenLocalRepo: localRepo) {
// Some common Maven command line + provided command line
sh "mvn -Pci -V -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline -Dunix.socket.tmp=" + env.JENKINS_HOME
sh "mvn -Pci -V -B -e -fae -Dmaven.test.failure.ignore=true -Djetty.testtracker.log=true $cmdline"
}
}

Expand Down
Expand Up @@ -52,6 +52,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@EnabledForJreRange(min = JRE.JAVA_16)
public class UnixDomainTest
Expand Down Expand Up @@ -84,7 +85,10 @@ private void start(Handler handler) throws Exception
{
server = new Server();
UnixDomainServerConnector connector = new UnixDomainServerConnector(server, factories);
unixDomainPath = Files.createTempFile(Path.of("/tmp"), "unixdomain_", ".sock");
String dir = System.getProperty("jetty.unixdomain.dir");
assertNotNull(dir);
unixDomainPath = Files.createTempFile(Path.of(dir), "unix_", ".sock");
assertTrue(unixDomainPath.toAbsolutePath().toString().length() < 108, "Unix-Domain path too long");
Files.delete(unixDomainPath);
connector.setUnixDomainPath(unixDomainPath);
server.addConnector(connector);
Expand Down
Expand Up @@ -18,7 +18,6 @@
import java.net.ConnectException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -32,7 +31,6 @@
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.unixsocket.client.HttpClientTransportOverUnixSockets;
import org.eclipse.jetty.unixsocket.server.UnixSocketConnector;
import org.eclipse.jetty.util.StringUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
Expand All @@ -45,9 +43,9 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.condition.OS.LINUX;
import static org.junit.jupiter.api.condition.OS.MAC;

Expand All @@ -65,18 +63,11 @@ public void before() throws Exception
{
server = null;
httpClient = null;
String unixSocketTmp = System.getProperty("unix.socket.tmp");
if (StringUtil.isNotBlank(unixSocketTmp))
sockFile = Files.createTempFile(Paths.get(unixSocketTmp), "unix", ".sock");
else
sockFile = Files.createTempFile("unix", ".sock");
if (sockFile.toAbsolutePath().toString().length() > UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH)
{
Path tmp = Paths.get("/tmp");
assumeTrue(Files.exists(tmp) && Files.isDirectory(tmp));
sockFile = Files.createTempFile(tmp, "unix", ".sock");
}
assertTrue(Files.deleteIfExists(sockFile), "temp sock file cannot be deleted");
String dir = System.getProperty("jetty.unixdomain.dir");
assertNotNull(dir);
sockFile = Files.createTempFile(Path.of(dir), "unix_", ".sock");
assertTrue(sockFile.toAbsolutePath().toString().length() < UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH, "Unix-Domain path too long");
Files.delete(sockFile);
}

@AfterEach
Expand Down
15 changes: 13 additions & 2 deletions pom.xml
Expand Up @@ -12,6 +12,7 @@
<inceptionYear>1995</inceptionYear>

<properties>
<jetty.unixdomain.dir>/tmp</jetty.unixdomain.dir>
<compiler.source>11</compiler.source>
<compiler.target>11</compiler.target>
<compiler.release>11</compiler.release>
Expand Down Expand Up @@ -44,7 +45,6 @@
<jboss.logging.version>3.4.1.Final</jboss.logging.version>
<jetty.perf-helper.version>1.0.6</jetty.perf-helper.version>
<ant.version>1.10.9</ant.version>
<unix.socket.tmp></unix.socket.tmp>
<!-- OSGI import-package -->
<osgi.slf4j.import.packages>org.slf4j;version="[1.7,3.0)", org.slf4j.event;version="[1.7,3.0)", org.slf4j.helpers;version="[1.7,3.0)", org.slf4j.spi;version="[1.7,3.0)"</osgi.slf4j.import.packages>

Expand Down Expand Up @@ -685,7 +685,7 @@
<runOrder>alphabetical</runOrder>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
<unix.socket.tmp>${unix.socket.tmp}</unix.socket.tmp>
<jetty.unixdomain.dir>${jetty.unixdomain.dir}</jetty.unixdomain.dir>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
<jetty.testtracker.log>${jetty.testtracker.log}</jetty.testtracker.log>
</systemPropertyVariables>
Expand Down Expand Up @@ -1245,6 +1245,17 @@
</dependencyManagement>

<profiles>
<profile>
<id>unix-domain-windows</id>
<activation>
<os>
<name>Windows</name>
</os>
</activation>
<properties>
<jetty.unixdomain.dir>${user.home}</jetty.unixdomain.dir>
</properties>
</profile>
<profile>
<id>errorprone</id>
<build>
Expand Down
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.jetty.unixsocket.server.UnixSocketConnector;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.StatusCode;
Expand All @@ -63,8 +62,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class DistributionTests extends AbstractJettyHomeTest
{
Expand Down Expand Up @@ -279,20 +278,11 @@ private void testSimpleWebAppWithJSPOverHTTP2(boolean ssl) throws Exception
@DisabledOnOs(OS.WINDOWS) // jnr not supported on windows
public void testUnixSocket() throws Exception
{
Path tmpSockFile;
String unixSocketTmp = System.getProperty("unix.socket.tmp");
if (StringUtil.isNotBlank(unixSocketTmp))
tmpSockFile = Files.createTempFile(Paths.get(unixSocketTmp), "unix", ".sock");
else
tmpSockFile = Files.createTempFile("unix", ".sock");
if (tmpSockFile.toAbsolutePath().toString().length() > UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH)
{
Path tmp = Paths.get("/tmp");
assumeTrue(Files.exists(tmp) && Files.isDirectory(tmp));
tmpSockFile = Files.createTempFile(tmp, "unix", ".sock");
}
Path sockFile = tmpSockFile;
assertTrue(Files.deleteIfExists(sockFile), "temp sock file cannot be deleted");
String dir = System.getProperty("jetty.unixdomain.dir");
assertNotNull(dir);
Path sockFile = Files.createTempFile(Path.of(dir), "unix_", ".sock");
assertTrue(sockFile.toAbsolutePath().toString().length() < UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH, "Unix-Domain path too long");
Files.delete(sockFile);

String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
Expand Down
Expand Up @@ -17,7 +17,6 @@
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -52,20 +51,19 @@
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.unixsocket.client.HttpClientTransportOverUnixSockets;
import org.eclipse.jetty.unixsocket.server.UnixSocketConnector;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.SocketAddressResolver;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.Assumptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.eclipse.jetty.http.client.Transport.UNIX_SOCKET;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TransportScenario
{
Expand All @@ -86,20 +84,10 @@ public TransportScenario(final Transport transport) throws IOException
{
this.transport = transport;

Path unixSocketTmp;
String tmpProp = System.getProperty("unix.socket.tmp");
if (StringUtil.isBlank(tmpProp))
unixSocketTmp = MavenTestingUtils.getTargetPath();
else
unixSocketTmp = Paths.get(tmpProp);
sockFile = Files.createTempFile(unixSocketTmp, "unix", ".sock");
if (sockFile.toAbsolutePath().toString().length() > UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH)
{
Files.delete(sockFile);
Path tmp = Paths.get("/tmp");
assumeTrue(Files.exists(tmp) && Files.isDirectory(tmp));
sockFile = Files.createTempFile(tmp, "unix", ".sock");
}
String dir = System.getProperty("jetty.unixdomain.dir");
assertNotNull(dir);
sockFile = Files.createTempFile(Path.of(dir), "unix_", ".sock");
assertTrue(sockFile.toAbsolutePath().toString().length() < UnixSocketConnector.MAX_UNIX_SOCKET_PATH_LENGTH, "Unix-Domain path too long");
Files.delete(sockFile);

// Disable UNIX_SOCKET due to jnr/jnr-unixsocket#69.
Expand Down

0 comments on commit 82106cf

Please sign in to comment.