From 450096e06d094f8315abdc566ec238d3729f184b Mon Sep 17 00:00:00 2001 From: Dave Rusek Date: Fri, 30 Sep 2022 17:14:12 -0600 Subject: [PATCH] Add regression tests for netty client factories (#2382) Motivation: We recently expanded the allowed types for the Netty client factories and in order to prevent a regression we should make sure they are used in a test and fail the build if the types are narrowed. Changes: Create two simple tests that will fail to compile of a regression occurs in the scope of the allowed types. --- .../grpc/netty/GrpcClientsCompileTest.java | 57 ++++++++++++++++ .../http/netty/HttpClientsCompileTest.java | 68 +++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/GrpcClientsCompileTest.java create mode 100644 servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpClientsCompileTest.java diff --git a/servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/GrpcClientsCompileTest.java b/servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/GrpcClientsCompileTest.java new file mode 100644 index 0000000000..00553cd7b4 --- /dev/null +++ b/servicetalk-grpc-netty/src/test/java/io/servicetalk/grpc/netty/GrpcClientsCompileTest.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2022 Apple Inc. and the ServiceTalk project authors + * + * 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 io.servicetalk.grpc.netty; + +import io.servicetalk.client.api.ServiceDiscoverer; +import io.servicetalk.client.api.ServiceDiscovererEvent; +import io.servicetalk.concurrent.api.Completable; +import io.servicetalk.concurrent.api.Publisher; + +import org.junit.jupiter.api.Test; + +import java.net.InetSocketAddress; +import java.util.Collection; + +class GrpcClientsCompileTest { + private static final String IGNORE_ADDRESS = ""; + + @Test + void testGrpcClientsAcceptsCustomServiceDiscovererEvents() { + GrpcClients.forAddress(new NullServiceDiscoverer>(), IGNORE_ADDRESS); + GrpcClients.forAddress(new NullServiceDiscoverer(), IGNORE_ADDRESS); + } + + private interface CustomServiceDiscovererEvent extends ServiceDiscovererEvent { } + + private static final class NullServiceDiscoverer> + implements ServiceDiscoverer { + + @Override + public Publisher> discover(final String inetSocketAddress) { + return Publisher.empty(); + } + + @Override + public Completable onClose() { + return Completable.completed(); + } + + @Override + public Completable closeAsync() { + return Completable.completed(); + } + } +} diff --git a/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpClientsCompileTest.java b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpClientsCompileTest.java new file mode 100644 index 0000000000..7e07169192 --- /dev/null +++ b/servicetalk-http-netty/src/test/java/io/servicetalk/http/netty/HttpClientsCompileTest.java @@ -0,0 +1,68 @@ +/* + * Copyright © 2022 Apple Inc. and the ServiceTalk project authors + * + * 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 io.servicetalk.http.netty; + +import io.servicetalk.client.api.ServiceDiscoverer; +import io.servicetalk.client.api.ServiceDiscovererEvent; +import io.servicetalk.concurrent.api.Completable; +import io.servicetalk.concurrent.api.Publisher; +import io.servicetalk.http.api.SingleAddressHttpClientBuilder; + +import org.junit.jupiter.api.Test; + +import java.net.InetSocketAddress; +import java.util.Collection; + +class HttpClientsCompileTest { + private static final String IGNORE_ADDRESS = ""; + + @Test + void testHttpClientsAcceptsBaseServiceDiscovererEvents() { + NullServiceDiscoverer> discoverer = new NullServiceDiscoverer<>(); + SingleAddressHttpClientBuilder builder = HttpClients.forSingleAddress( + discoverer, IGNORE_ADDRESS); + builder.serviceDiscoverer(discoverer); + } + + @Test + void testHttpClientsAcceptsCustomServiceDiscovererEvents() { + NullServiceDiscoverer discoverer = new NullServiceDiscoverer<>(); + SingleAddressHttpClientBuilder builder = HttpClients.forSingleAddress( + discoverer, IGNORE_ADDRESS); + builder.serviceDiscoverer(discoverer); + } + + private interface CustomServiceDiscovererEvent extends ServiceDiscovererEvent { } + + private static final class NullServiceDiscoverer> + implements ServiceDiscoverer { + + @Override + public Publisher> discover(final String inetSocketAddress) { + return Publisher.empty(); + } + + @Override + public Completable onClose() { + return Completable.completed(); + } + + @Override + public Completable closeAsync() { + return Completable.completed(); + } + } +}