Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unix Domain Sockets support on NIO transport #3494

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check_netty_snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
distribution: 'temurin'
java-version: '8'
- name: Build with Gradle
run: ./gradlew clean check --no-daemon -PforceTransport=${{ matrix.transport }} -PforceNettyVersion='4.1.115.Final-SNAPSHOT'
run: ./gradlew clean check -x :reactor-netty-core:java17Test --no-daemon -PforceTransport=${{ matrix.transport }} -PforceNettyVersion='4.1.115.Final-SNAPSHOT'
2 changes: 1 addition & 1 deletion .github/workflows/check_reactor_core_3.6_snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
distribution: 'temurin'
java-version: '8'
- name: Build with Gradle
run: ./gradlew clean check --no-daemon -PforceTransport=nio -PreactorCoreVersion='3.6.12-SNAPSHOT' -PforceContextPropagationVersion='1.1.0'
run: ./gradlew clean check -x :reactor-netty-core:java17Test --no-daemon -PforceTransport=nio -PreactorCoreVersion='3.6.12-SNAPSHOT' -PforceContextPropagationVersion='1.1.0'
12 changes: 10 additions & 2 deletions .github/workflows/check_transport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: gradle/actions/wrapper-validation@d156388eb19639ec20ade50009f3d199ce1e2808
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'
- name: Set up JDK 1.8
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '8'
- name: Build with Gradle
run: ./gradlew clean check --no-daemon -x spotlessCheck -PforceTransport=${{ matrix.transport }}
- name: Build and test with Java 8
run: ./gradlew clean check -x :reactor-netty-core:java17Test --no-daemon -x spotlessCheck -PforceTransport=${{ matrix.transport }}
- name: Build and test with Java 17
if: ${{ ! startsWith(matrix.os, 'windows') }}
run: ./gradlew reactor-netty-http:test --tests reactor.netty.http.server.HttpServerTests.testHttpServerWithDomainSockets_HTTP11 -PtestToolchain=17 --no-daemon -x spotlessCheck -PforceTransport=nio
33 changes: 28 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ jobs:
fullVersion: ${{ steps.version.outputs.fullVersion }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: setup java
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'
- name: Set up JDK 1.8
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
Expand All @@ -35,7 +40,7 @@ jobs:
run: ./gradlew qualifyVersionGha
- name: run reactor-netty-core checks
id: reactor-netty-core-checks
run: ./gradlew reactor-netty-core:check
run: ./gradlew reactor-netty-core:check -x :reactor-netty-core:java17Test
reactor-netty-http:
# Notes on reactor-netty-http: this job has no access to secrets, only github token. As a result, all non-core actions are centralized here
name: reactor-netty-http
Expand Down Expand Up @@ -119,7 +124,13 @@ jobs:
environment: snapshots
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'
- name: Set up JDK 1.8
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '8'
Expand All @@ -144,7 +155,13 @@ jobs:
environment: releases
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'
- name: Set up JDK 1.8
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '8'
Expand All @@ -171,7 +188,13 @@ jobs:
environment: releases
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '17'
- name: Set up JDK 1.8
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b
with:
distribution: 'temurin'
java-version: '8'
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ plugins {
id 'org.graalvm.buildtools.native' version '0.9.25' apply false
id 'io.spring.antora.generate-antora-yml' version '0.0.1' apply false
id 'net.ltgt.errorprone' version '4.1.0' apply false
id 'me.champeau.mrjar' version '0.1.1' apply false
}

description = 'Reactive Streams Netty driver'
Expand Down Expand Up @@ -137,6 +138,7 @@ ext {
reflectionsVersion = '0.10.2'
errorproneCoreVersion = '2.10.0'
errorproneGuavaVersion = '30.0-jre'
bouncycastleVersion = '1.70'

// Antora
antoraPluginVersion = '1.0.0'
Expand Down Expand Up @@ -187,7 +189,7 @@ spotless {
// find start of gradle files by looking for either `import`, `apply`
// or start of blocks like `javadoc {` or `configure(rootProject) {`...
licenseHeaderFile('codequality/spotless/licenseSlashstarStyle.txt',
"^\\w+(\\(\\w+\\))?\\s?\\{?|import|apply")
"^\\w+(\\(\\w+\\))?\\s?\\{?|import|apply|/\\*\\*")
}
}

Expand Down
5 changes: 3 additions & 2 deletions docs/modules/ROOT/pages/http-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,14 @@ You may also need to configure the Reactor Netty `ObservationHandlers` using the

[[unix-domain-sockets]]
== Unix Domain Sockets
The `HTTP` client supports Unix Domain Sockets (UDS) when native transport is in use.
The `HTTP` client supports Unix Domain Sockets (UDS) when native transport is in use for all java versions
and when NIO transport is in use for java 17 and above.

The following example shows how to use UDS support:

{examples-link}/uds/Application.java
----
include::{examples-dir}/uds/Application.java[lines=18..33]
include::{examples-dir}/uds/Application.java[lines=18..38]
----
<1> Specifies `DomainSocketAddress` that will be used

Expand Down
5 changes: 3 additions & 2 deletions docs/modules/ROOT/pages/http-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,14 @@ You may also need to configure the Reactor Netty `ObservationHandlers` using the

[[unix-domain-sockets]]
== Unix Domain Sockets
The `HTTP` server supports Unix Domain Sockets (UDS) when native transport is in use.
The `HTTP` server supports Unix Domain Sockets (UDS) when native transport is in use for all java versions
and when NIO transport is in use for java 17 and above.

The following example shows how to use UDS support:

{examples-link}/uds/Application.java
----
include::{examples-dir}/uds/Application.java[lines=18..33]
include::{examples-dir}/uds/Application.java[lines=18..38]
----
<1> Specifies `DomainSocketAddress` that will be used

Expand Down
5 changes: 3 additions & 2 deletions docs/modules/ROOT/pages/tcp-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,15 @@ You may also need to configure the Reactor Netty `ObservationHandlers` using the

[[unix-domain-sockets]]
== Unix Domain Sockets
The `TCP` client supports Unix Domain Sockets (UDS) when native transport is in use.
The `TCP` client supports Unix Domain Sockets (UDS) when native transport is in use for all java versions
and when NIO transport is in use for java 17 and above.

The following example shows how to use UDS support:

{examples-link}/uds/Application.java
[%unbreakable]
----
include::{examples-dir}/uds/Application.java[lines=18..33]
include::{examples-dir}/uds/Application.java[lines=18..38]
----
<1> Specifies `DomainSocketAddress` that will be used

Expand Down
5 changes: 3 additions & 2 deletions docs/modules/ROOT/pages/tcp-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,14 @@ You may also need to configure the Reactor Netty `ObservationHandlers` using the

[[unix-domain-sockets]]
== Unix Domain Sockets
The `TCP` server supports Unix Domain Sockets (UDS) when native transport is in use.
The `TCP` server supports Unix Domain Sockets (UDS) when native transport is in use for all java versions
and when NIO transport is in use for java 17 and above.

The following example shows how to use UDS support:

{examples-link}/uds/Application.java
[%unbreakable]
----
include::{examples-dir}/uds/Application.java[lines=18..33]
include::{examples-dir}/uds/Application.java[lines=18..38]
----
<1> Specifies `DomainSocketAddress` that will be used
80 changes: 80 additions & 0 deletions gradle/toolchains.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed 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
*
* https://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.
*/
/**
* Copied from https://github.com/spring-projects/spring-framework/blob/main/gradle/toolchains.gradle
*/
/**
* Apply the JVM Toolchain conventions
* See https://docs.gradle.org/current/userguide/toolchains.html
*
* One can choose the toolchain to use for compiling and running the TEST sources.
* These options apply to Java, Kotlin and Groovy test sources when available.
* {@code "./gradlew check -PtestToolchain=22"} will use a JDK22
* toolchain for compiling and running the test SourceSet.
*
* By default, the main build will fall back to using the a JDK 17
* toolchain (and 17 language level) for all main sourceSets.
* See {@link org.springframework.build.JavaConventions}.
*
* Gradle will automatically detect JDK distributions in well-known locations.
* The following command will list the detected JDKs on the host.
* {@code
* $ ./gradlew -q javaToolchains
* }
*
* We can also configure ENV variables and let Gradle know about them:
* {@code
* $ echo JDK17
* /opt/openjdk/java17
* $ echo JDK22
* /opt/openjdk/java22
* $ ./gradlew -Porg.gradle.java.installations.fromEnv=JDK17,JDK22 check
* }
*
* @author Brian Clozel
* @author Sam Brannen
*/

def testToolchainConfigured() {
return project.hasProperty('testToolchain') && project.testToolchain
}

def testToolchainLanguageVersion() {
if (testToolchainConfigured()) {
return JavaLanguageVersion.of(project.testToolchain.toString())
}
return JavaLanguageVersion.of(8)
}

plugins.withType(JavaPlugin).configureEach {
// Configure a specific Java Toolchain for compiling and running tests if the 'testToolchain' property is defined
if (testToolchainConfigured()) {
def testLanguageVersion = testToolchainLanguageVersion()
tasks.withType(JavaCompile).matching { it.name.contains("Test") }.configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testLanguageVersion
}
}
tasks.withType(Test).configureEach{
javaLauncher = javaToolchains.launcherFor {
languageVersion = testLanguageVersion
if (testLanguageVersion.canCompileOrRun(JavaLanguageVersion.of(17))) {
jvmArgs = ["-XX:+AllowRedefinitionToAddDeleteMethods"]
}
}
}
}
}
35 changes: 35 additions & 0 deletions reactor-netty-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'me.champeau.gradle.japicmp'
apply plugin: 'de.undercouch.download'
apply plugin: 'biz.aQute.bnd.builder'
apply plugin: 'me.champeau.mrjar'

multiRelease {
targetVersions 8, 17
}

ext {
bndOptions = [
Expand All @@ -48,6 +53,7 @@ sourceSets {
}

configurations {
java17Implementation.extendsFrom(implementation)
shaded
contextPropagationTestImplementation.extendsFrom(implementation)
contextPropagationTestRuntimeOnly.extendsFrom(runtimeOnly)
Expand Down Expand Up @@ -143,6 +149,11 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testRuntimeOnly "org.slf4j:jcl-over-slf4j:$slf4jVersion"

if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
// Necessary for generating SelfSignedCertificate on Java version >= 15
testRuntimeOnly "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"
}

// JSR-305 annotations
testFixturesCompileOnly "com.google.code.findbugs:jsr305:$jsr305Version"
testFixturesApi("ch.qos.logback:logback-classic:$logbackVersion")
Expand Down Expand Up @@ -175,6 +186,18 @@ jar {
attributes("Automatic-Module-Name": "reactor.netty.core")
}
bnd(bndOptions)

bundle {
// workaround for multi-version JARs
// see https://github.com/bndtools/bnd/issues/2227
bnd '''\
-fixupmessages: '^Classes found in the wrong directory: .*'
'''.stripIndent()
}
}

java17Test {
jvmArgs = ["-XX:+AllowRedefinitionToAddDeleteMethods"]
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
Expand Down Expand Up @@ -272,12 +295,24 @@ shadowJar {
}
bnd(bndOptions)

bundle {
// workaround for multi-version JARs
// see https://github.com/bndtools/bnd/issues/2227
bnd '''\
-fixupmessages: '^Classes found in the wrong directory: .*'
'''.stripIndent()
}

enableRelocation true
relocationPrefix "reactor.netty.internal.shaded"
archiveClassifier.set('')

dependsOn(project.tasks.jar)

into('META-INF/versions/17') {
from sourceSets.java17.output
}

manifest {
inheritFrom project.tasks.jar.manifest
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2019-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,6 +47,9 @@ void testPackages() throws Exception {
try (Stream<Path> stream = Files.list(root.resolve("reactor"))) {
assertThatFileList(stream).containsOnly("netty");
}
try (Stream<Path> stream = Files.list(root.resolve("META-INF"))) {
assertThatFileList(stream).containsOnly("native-image", "services", "versions", "MANIFEST.MF");
}
}

@Test
Expand Down Expand Up @@ -88,7 +91,8 @@ void testManifestContent() throws IOException {
.contains(
"Implementation-Title: reactor-netty-core",
"Implementation-Version: " + version,
"Automatic-Module-Name: reactor.netty.core"
"Automatic-Module-Name: reactor.netty.core",
"Multi-Release: true"
);
assertThat(lines)
.as("OSGI content")
Expand Down
Loading