Skip to content

Commit 450096e

Browse files
author
Dave Rusek
authored
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.
1 parent f29e8bd commit 450096e

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright © 2022 Apple Inc. and the ServiceTalk project authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.servicetalk.grpc.netty;
17+
18+
import io.servicetalk.client.api.ServiceDiscoverer;
19+
import io.servicetalk.client.api.ServiceDiscovererEvent;
20+
import io.servicetalk.concurrent.api.Completable;
21+
import io.servicetalk.concurrent.api.Publisher;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import java.net.InetSocketAddress;
26+
import java.util.Collection;
27+
28+
class GrpcClientsCompileTest {
29+
private static final String IGNORE_ADDRESS = "";
30+
31+
@Test
32+
void testGrpcClientsAcceptsCustomServiceDiscovererEvents() {
33+
GrpcClients.forAddress(new NullServiceDiscoverer<ServiceDiscovererEvent<InetSocketAddress>>(), IGNORE_ADDRESS);
34+
GrpcClients.forAddress(new NullServiceDiscoverer<CustomServiceDiscovererEvent>(), IGNORE_ADDRESS);
35+
}
36+
37+
private interface CustomServiceDiscovererEvent extends ServiceDiscovererEvent<InetSocketAddress> { }
38+
39+
private static final class NullServiceDiscoverer<E extends ServiceDiscovererEvent<InetSocketAddress>>
40+
implements ServiceDiscoverer<String, InetSocketAddress, E> {
41+
42+
@Override
43+
public Publisher<Collection<E>> discover(final String inetSocketAddress) {
44+
return Publisher.empty();
45+
}
46+
47+
@Override
48+
public Completable onClose() {
49+
return Completable.completed();
50+
}
51+
52+
@Override
53+
public Completable closeAsync() {
54+
return Completable.completed();
55+
}
56+
}
57+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright © 2022 Apple Inc. and the ServiceTalk project authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.servicetalk.http.netty;
17+
18+
import io.servicetalk.client.api.ServiceDiscoverer;
19+
import io.servicetalk.client.api.ServiceDiscovererEvent;
20+
import io.servicetalk.concurrent.api.Completable;
21+
import io.servicetalk.concurrent.api.Publisher;
22+
import io.servicetalk.http.api.SingleAddressHttpClientBuilder;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import java.net.InetSocketAddress;
27+
import java.util.Collection;
28+
29+
class HttpClientsCompileTest {
30+
private static final String IGNORE_ADDRESS = "";
31+
32+
@Test
33+
void testHttpClientsAcceptsBaseServiceDiscovererEvents() {
34+
NullServiceDiscoverer<ServiceDiscovererEvent<InetSocketAddress>> discoverer = new NullServiceDiscoverer<>();
35+
SingleAddressHttpClientBuilder<String, InetSocketAddress> builder = HttpClients.forSingleAddress(
36+
discoverer, IGNORE_ADDRESS);
37+
builder.serviceDiscoverer(discoverer);
38+
}
39+
40+
@Test
41+
void testHttpClientsAcceptsCustomServiceDiscovererEvents() {
42+
NullServiceDiscoverer<CustomServiceDiscovererEvent> discoverer = new NullServiceDiscoverer<>();
43+
SingleAddressHttpClientBuilder<String, InetSocketAddress> builder = HttpClients.forSingleAddress(
44+
discoverer, IGNORE_ADDRESS);
45+
builder.serviceDiscoverer(discoverer);
46+
}
47+
48+
private interface CustomServiceDiscovererEvent extends ServiceDiscovererEvent<InetSocketAddress> { }
49+
50+
private static final class NullServiceDiscoverer<E extends ServiceDiscovererEvent<InetSocketAddress>>
51+
implements ServiceDiscoverer<String, InetSocketAddress, E> {
52+
53+
@Override
54+
public Publisher<Collection<E>> discover(final String inetSocketAddress) {
55+
return Publisher.empty();
56+
}
57+
58+
@Override
59+
public Completable onClose() {
60+
return Completable.completed();
61+
}
62+
63+
@Override
64+
public Completable closeAsync() {
65+
return Completable.completed();
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)