Skip to content

Commit

Permalink
Minor rename / cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 28, 2023
1 parent 9f5f577 commit 1e96e06
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/http/HttpClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.net.AddressLookup;
import io.vertx.core.net.AddressResolver;

import java.util.function.Function;

Expand Down Expand Up @@ -79,7 +79,7 @@ public interface HttpClientBuilder {
* @param lookup the address lookup
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
HttpClientBuilder withLookup(AddressLookup lookup);
HttpClientBuilder withAddressResolver(AddressResolver lookup);

/**
* Build and return the client.
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/vertx/core/http/impl/HttpClientBuilderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import io.vertx.core.impl.CloseFuture;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.AddressLookup;
import io.vertx.core.spi.lookup.AddressResolver;
import io.vertx.core.net.AddressResolver;

import java.util.function.Function;

Expand All @@ -20,7 +19,7 @@ public class HttpClientBuilderImpl implements HttpClientBuilder {
private PoolOptions poolOptions;
private Handler<HttpConnection> connectHandler;
private Function<HttpClientResponse, Future<RequestOptions>> redirectHandler;
private AddressLookup addressLookup;
private AddressResolver addressResolver;

public HttpClientBuilderImpl(VertxInternal vertx) {
this.vertx = vertx;
Expand Down Expand Up @@ -51,8 +50,8 @@ public HttpClientBuilder withRedirectHandler(Function<HttpClientResponse, Future
}

@Override
public HttpClientBuilder withLookup(AddressLookup addressLookup) {
this.addressLookup = addressLookup;
public HttpClientBuilder withAddressResolver(AddressResolver addressResolver) {
this.addressResolver = addressResolver;
return this;
}

Expand All @@ -71,15 +70,15 @@ public HttpClient build() {
if (co.isShared()) {
CloseFuture closeFuture = new CloseFuture();
client = vertx.createSharedResource("__vertx.shared.httpClients", co.getName(), closeFuture, cf_ -> {
AddressResolver<?, ?, ?> resolver = addressLookup != null ? addressLookup.resolver(vertx) : null;
io.vertx.core.spi.net.AddressResolver<?, ?, ?> resolver = addressResolver != null ? addressResolver.resolver(vertx) : null;
HttpClientImpl impl = new HttpClientImpl(vertx, resolver, co, po);
cf_.add(completion -> impl.close().onComplete(completion));
return impl;
});
client = new CleanableHttpClient((HttpClientInternal) client, vertx.cleaner(), (timeout, timeunit) -> closeFuture.close());
closeable = closeFuture;
} else {
AddressResolver<?, ?, ?> resolver = addressLookup != null ? addressLookup.resolver(vertx) : null;
io.vertx.core.spi.net.AddressResolver<?, ?, ?> resolver = addressResolver != null ? addressResolver.resolver(vertx) : null;
HttpClientImpl impl = new HttpClientImpl(vertx, resolver, co, po);
closeable = impl;
client = new CleanableHttpClient(impl, vertx.cleaner(), impl::shutdown);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.vertx.core.net.impl.pool.*;
import io.vertx.core.spi.metrics.ClientMetrics;
import io.vertx.core.spi.metrics.MetricsProvider;
import io.vertx.core.spi.lookup.AddressResolver;
import io.vertx.core.spi.net.AddressResolver;

import java.lang.ref.WeakReference;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.vertx.core.http.StreamPriority;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.spi.lookup.AddressResolver;
import io.vertx.core.spi.net.AddressResolver;
import io.vertx.core.streams.WriteStream;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
package io.vertx.core.net;

import io.vertx.core.Vertx;
import io.vertx.core.spi.lookup.AddressResolver;

/**
* A generic address resolver market interface. Implementation must also implement the SPI interface {@link io.vertx.core.spi.lookup.AddressResolver}
* A generic address resolver market interface. Implementation must also implement the SPI interface {@link io.vertx.core.spi.net.AddressResolver}
* and can be cast to this type.
*/
public interface AddressLookup {
public interface AddressResolver {

/**
* Return a resolver capable of resolving addresses for a client.
*
* @param vertx the vertx instance
* @return the resolver
*/
AddressResolver<?, ?, ?> resolver(Vertx vertx);
io.vertx.core.spi.net.AddressResolver<?, ?, ?> resolver(Vertx vertx);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.vertx.core.impl.future.PromiseInternal;
import io.vertx.core.net.Address;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.spi.lookup.AddressResolver;
import io.vertx.core.spi.net.AddressResolver;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.spi.lookup;
package io.vertx.core.spi.net;

import io.vertx.core.Future;
import io.vertx.core.net.Address;
Expand Down
49 changes: 24 additions & 25 deletions src/test/java/io/vertx/core/http/ResolvingHttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.impl.HttpClientInternal;
import io.vertx.core.net.*;
import io.vertx.core.spi.lookup.AddressResolver;
import io.vertx.test.core.VertxTestBase;
import io.vertx.test.proxy.HttpProxy;
import io.vertx.test.tls.Cert;
Expand Down Expand Up @@ -114,12 +113,12 @@ static class FakeMetric {
}
}

private static class FixedAddressLookup implements AddressLookup, AddressResolver<FakeState, FakeAddress, FakeMetric> {
private static class FixedAddressResolver implements AddressResolver, io.vertx.core.spi.net.AddressResolver<FakeState, FakeAddress, FakeMetric> {

private final ConcurrentMap<String, FakeState> map = new ConcurrentHashMap<>();

@Override
public AddressResolver<?, ?, ?> resolver(Vertx vertx) {
public io.vertx.core.spi.net.AddressResolver<?, ?, ?> resolver(Vertx vertx) {
return this;
}

Expand Down Expand Up @@ -190,10 +189,10 @@ public void testResolveServers() throws Exception {
waitFor(numServers * 2);
startServers(numServers);
requestHandler = (idx, req) -> req.response().end("server-" + idx);
FixedAddressLookup resolver = new FixedAddressLookup();
FixedAddressResolver resolver = new FixedAddressResolver();
resolver.map.put("example.com", new FakeState("example.com", SocketAddress.inetSocketAddress(8080, "localhost"), SocketAddress.inetSocketAddress(8081, "localhost")));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(resolver)
.withAddressResolver(resolver)
.build();
Set<String> responses = Collections.synchronizedSet(new HashSet<>());
for (int i = 0;i < numServers * 2;i++) {
Expand All @@ -213,10 +212,10 @@ public void testResolveServers() throws Exception {
@Test
public void testResolveConnectFailure() throws Exception {
requestHandler = (idx, req) -> req.response().end("server-" + idx);
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
lookup.map.put("example.com", new FakeState("example.com", SocketAddress.inetSocketAddress(8080, "localhost"), SocketAddress.inetSocketAddress(8081, "localhost")));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
client.request(new RequestOptions().setServer(new FakeAddress("example.com"))).compose(req -> req
.send()
Expand All @@ -243,15 +242,15 @@ public void testShutdownServers() throws Exception {
int numServers = 4;
requestHandler = (idx, req) -> req.response().end("server-" + idx);
startServers(numServers);
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
lookup.map.put("example.com", new FakeState("example.com",
SocketAddress.inetSocketAddress(8080, "localhost"),
SocketAddress.inetSocketAddress(8081, "localhost"),
SocketAddress.inetSocketAddress(8082, "localhost"),
SocketAddress.inetSocketAddress(8083, "localhost")
));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
CountDownLatch latch = new CountDownLatch(numServers);
for (int i = 0;i < numServers;i++) {
Expand All @@ -277,12 +276,12 @@ public void testShutdownServers() throws Exception {
public void testResolveToSameSocketAddress() throws Exception {
requestHandler = (idx, req) -> req.response().end("server-" + idx);
startServers(1);
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
SocketAddress address = SocketAddress.inetSocketAddress(8080, "localhost");
lookup.map.put("server1.com", new FakeState("server1.com", address));
lookup.map.put("server2.com", new FakeState("server2.com", address));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
Future<Buffer> result = client.request(new RequestOptions().setServer(new FakeAddress("server1.com"))).compose(req -> req
.send()
Expand All @@ -308,11 +307,11 @@ public void testResolveToSameSocketAddressWithProxy() throws Exception {
HttpProxy proxy = new HttpProxy();
proxy.start(vertx);

FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
SocketAddress address = SocketAddress.inetSocketAddress(8080, "localhost");
lookup.map.put("example.com", new FakeState("example.com", address));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
RequestOptions request1 = new RequestOptions().setServer(new FakeAddress("example.com"));
RequestOptions request2 = new RequestOptions(request1).setProxyOptions(new ProxyOptions()
Expand All @@ -336,14 +335,14 @@ public void testResolveToSameSocketAddressWithProxy() throws Exception {
@Test
public void testResolveFailure() {
Exception cause = new Exception("Not found");
FixedAddressLookup lookup = new FixedAddressLookup() {
FixedAddressResolver lookup = new FixedAddressResolver() {
@Override
public Future<FakeState> resolve(FakeAddress address) {
return Future.failedFuture(cause);
}
};
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
client.request(new RequestOptions().setServer(new FakeAddress("foo.com"))).compose(req -> req
.send()
Expand All @@ -358,9 +357,9 @@ public Future<FakeState> resolve(FakeAddress address) {

@Test
public void testUseInvalidAddress() {
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
client.request(new RequestOptions().setServer(new Address() {
})).compose(req -> req
Expand All @@ -379,7 +378,7 @@ public void testKeepAliveTimeout() throws Exception {
startServers(1);
requestHandler = (idx, req) -> req.response().end("server-" + idx);
CountDownLatch closedLatch = new CountDownLatch(1);
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
lookup.map.put("example.com", new FakeState("example.com", SocketAddress.inetSocketAddress(8080, "localhost")));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.with(new HttpClientOptions().setKeepAliveTimeout(1))
Expand All @@ -388,7 +387,7 @@ public void testKeepAliveTimeout() throws Exception {
closedLatch.countDown();
});
})
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
client.request(new RequestOptions().setServer(new FakeAddress("example.com"))).compose(req -> req
.send()
Expand All @@ -408,12 +407,12 @@ public void testStatistics() throws Exception {
req.response().end();
});
};
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
SocketAddress addr = SocketAddress.inetSocketAddress(8080, "localhost");
lookup.map.put("example.com", new FakeState("example.com", addr));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.with(new HttpClientOptions().setKeepAliveTimeout(1))
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
awaitFuture(client.request(new RequestOptions().setServer(new FakeAddress("example.com"))).compose(req -> req
.send()
Expand All @@ -435,12 +434,12 @@ public void testInvalidation() throws Exception {
requestHandler = (idx, req) -> {
req.response().end("" + idx);
};
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
SocketAddress addr1 = SocketAddress.inetSocketAddress(8080, "localhost");
SocketAddress addr2 = SocketAddress.inetSocketAddress(8081, "localhost");
lookup.map.put("example.com", new FakeState("example.com", addr1));
HttpClientInternal client = (HttpClientInternal) vertx.httpClientBuilder()
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
String res = awaitFuture(client.request(new RequestOptions().setServer(new FakeAddress("example.com"))).compose(req -> req
.send()
Expand Down Expand Up @@ -492,7 +491,7 @@ private void testSSL(RequestOptions request, boolean expectFailure, boolean veri
requestHandler = (idx, req) -> {
req.response().end("" + idx);
};
FixedAddressLookup lookup = new FixedAddressLookup();
FixedAddressResolver lookup = new FixedAddressResolver();
SocketAddress addr1 = SocketAddress.inetSocketAddress(8080, "localhost");
lookup.map.put("example.com", new FakeState("example.com", addr1));
HttpClient client = vertx.httpClientBuilder()
Expand All @@ -501,7 +500,7 @@ private void testSSL(RequestOptions request, boolean expectFailure, boolean veri
.setTrustOptions(Trust.SERVER_JKS.get())
.setVerifyHost(verifyHost)
)
.withLookup(lookup)
.withAddressResolver(lookup)
.build();
try {
String res = awaitFuture(client.request(request).compose(req -> req
Expand Down

0 comments on commit 1e96e06

Please sign in to comment.