Skip to content

Commit

Permalink
Fixes broken test codes and add new test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenchickenlove committed Nov 21, 2024
1 parent 09efa86 commit 25ff1af
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private void resolveProxyConfig(SessionProtocol protocol, Endpoint endpoint, Cli
final InetSocketAddress proxyAddress = proxyConfig.proxyAddress();
final boolean needsDnsResolution = proxyAddress != null && !isCreatedWithIpAddressOnly(proxyAddress);
if (needsDnsResolution) {
assert proxyAddress != null;
final Future<InetSocketAddress> resolveFuture = addressResolverGroup
.getResolver(ctx.eventLoop().withoutContext())
.resolve(createUnresolvedAddressForRefreshing(proxyAddress));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.linecorp.armeria.client.proxy;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.hash;
import static java.util.Objects.requireNonNull;

import java.net.InetSocketAddress;
Expand Down Expand Up @@ -87,8 +86,8 @@ public InetSocketAddress sourceAddress() {
@Override
public ProxyConfig withProxyAddress(InetSocketAddress newProxyAddress) {
requireNonNull(newProxyAddress, "newProxyAddress");
return this.sourceAddress == null ? new HAProxyConfig(proxyAddress)
: new HAProxyConfig(proxyAddress, this.sourceAddress);
return this.sourceAddress == null ? new HAProxyConfig(newProxyAddress)
: new HAProxyConfig(newProxyAddress, this.sourceAddress);
}

@Override
Expand All @@ -106,7 +105,7 @@ public boolean equals(@Nullable Object o) {

@Override
public int hashCode() {
return hash(proxyAddress, sourceAddress);
return Objects.hash(proxyAddress, sourceAddress);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public static boolean isCreatedWithIpAddressOnly(InetSocketAddress socketAddress
}

final InetAddress inetAddress = socketAddress.getAddress();
if (inetAddress.isAnyLocalAddress()) {
return false; // Wildcard address
}

// If hostname and host address are the same, it was created with an IP address
return socketAddress.getHostString().equals(inetAddress.getHostAddress());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public void connectFailed(SessionProtocol protocol, Endpoint endpoint,
assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(UnprocessedRequestException.class)
.hasRootCauseInstanceOf(NullPointerException.class)
.hasRootCauseMessage("proxyConfig");
.hasRootCauseMessage("unresolvedProxyConfig");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ void testIsCreatedWithIpAddressOnly() throws UnknownHostException {
inetSocketAddress = new InetSocketAddress(inetAddress, 8080);
assertThat(IpAddrUtil.isCreatedWithIpAddressOnly(inetSocketAddress)).isTrue();

inetAddress = InetAddress.getByName("0.0.0.0");
inetSocketAddress = new InetSocketAddress(inetAddress, 8080);
assertThat(IpAddrUtil.isCreatedWithIpAddressOnly(inetSocketAddress)).isTrue();

inetAddress = InetAddress.getByName("::");
inetSocketAddress = new InetSocketAddress(inetAddress, 8080);
assertThat(IpAddrUtil.isCreatedWithIpAddressOnly(inetSocketAddress)).isTrue();

inetAddress = InetAddress.getByAddress("foo.com", new byte[] { 1, 2, 3, 4 });
inetSocketAddress = new InetSocketAddress(inetAddress, 8080);
assertThat(IpAddrUtil.isCreatedWithIpAddressOnly(inetSocketAddress)).isFalse();
Expand Down

0 comments on commit 25ff1af

Please sign in to comment.