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

Fix service loader for jdk21 #576

Merged
merged 6 commits into from
Jan 8, 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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-576.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Jdk21 support (round 2)
links:
- https://github.com/palantir/docker-proxy-rule/pull/576
20 changes: 16 additions & 4 deletions docker-proxy-rule-core-jdk21/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
apply plugin: 'com.palantir.external-publish-jar'
apply plugin: 'org.unbroken-dome.test-sets'

testSets {
integrationTest
}

build.dependsOn integrationTest

dependencies {
api project(':docker-proxy-rule-core')

testImplementation group: 'junit', name: 'junit'
testImplementation group: 'org.assertj', name: 'assertj-core'
testImplementation group: 'org.mockito', name: 'mockito-core'
testRuntimeOnly group: 'org.mockito', name: 'mockito-inline'
compileOnly group: 'com.google.auto.service', name: 'auto-service-annotations'
annotationProcessor group: 'com.google.auto.service', name: 'auto-service'

integrationTestImplementation project(':docker-proxy-junit-jupiter')
integrationTestImplementation group: 'com.palantir.docker.compose', name: 'docker-compose-junit-jupiter'

integrationTestImplementation group: 'junit', name: 'junit'
integrationTestImplementation group: 'org.assertj', name: 'assertj-core'
integrationTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter'
}

javaVersion {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* (c) Copyright 2019 Palantir Technologies Inc. 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
*
* 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 com.palantir.docker.proxy;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import com.palantir.docker.compose.DockerComposeExtension;
import com.palantir.docker.compose.connection.Container;
import com.palantir.docker.compose.logging.LogDirectory;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

class DockerProxyExtensionJdk21Test {
@RegisterExtension
static final DockerComposeExtension DOCKER_COMPOSE_EXTENSION = DockerComposeExtension.builder()
.file("src/integrationTest/resources/DockerProxyExtensionJdk21Test-services.yml")
.saveLogsTo(LogDirectory.circleAwareLogDirectory(DockerProxyExtensionJdk21Test.class))
.waitingForService("webserver", Container::areAllPortsOpen)
.build();

@Test
void canReachDockerContainerByContainerNameWithProjectSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromProjectName(
DOCKER_COMPOSE_EXTENSION.projectName(), DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://webserver").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void canReachDockerContainerByHostnameWithProjectSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromProjectName(
DOCKER_COMPOSE_EXTENSION.projectName(), DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://web").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void canReachDockerContainerByHostnameAndDomainNameWithProjectSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromProjectName(
DOCKER_COMPOSE_EXTENSION.projectName(), DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://web.server.here").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void canReachDockerContainerByContainerNameWithNetworkSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromNetworkName(
DOCKER_COMPOSE_EXTENSION.projectName().asString() + "_default", DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://webserver").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void canReachDockerContainerByHostnameWithNetworkSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromNetworkName(
DOCKER_COMPOSE_EXTENSION.projectName().asString() + "_default", DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://web").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void canReachDockerContainerByHostnameAndDomainNameWithNetworkSpecified() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromNetworkName(
DOCKER_COMPOSE_EXTENSION.projectName().asString() + "_default", DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://web.server.here").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void otherHostnamesStillResolve() throws IOException, InterruptedException {
DockerProxyExtension dockerProxyExtension = DockerProxyExtension.fromProjectName(
DOCKER_COMPOSE_EXTENSION.projectName(), DockerProxyExtensionJdk21Test.class);
try {
dockerProxyExtension.before();
URLConnection urlConnection = new URL("http://www.palantir.com").openConnection();
urlConnection.connect();
} finally {
dockerProxyExtension.after();
}
}

@Test
void runningProxyRuleBeforeDockerComposeRuleFails() {
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> DockerProxyExtension.fromNetworkName(
"doesnotexist", DockerProxyExtensionJdk21Test.class)
.before());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'

services:
webserver:
hostname: web
domainname: server.here
image: nginx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.palantir.docker.proxy;

import com.google.auto.service.AutoService;
import java.net.spi.InetAddressResolver;
import java.net.spi.InetAddressResolverProvider;

@AutoService(InetAddressResolverProvider.class)
public final class DockerProxyInetAddressResolverProvider extends InetAddressResolverProvider {

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading