mirror of
https://github.com/square/okhttp.git
synced 2026-01-15 20:56:41 +03:00
Merge pull request #3029 from square/jwilson.1220.more_tostrings
Improve toString() of Route, Address, and StreamAllocation.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package okhttp3;
|
||||
|
||||
import java.net.Proxy;
|
||||
import java.util.List;
|
||||
import javax.net.SocketFactory;
|
||||
import okhttp3.internal.Util;
|
||||
@@ -48,4 +49,17 @@ public final class AddressTest {
|
||||
authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
|
||||
assertFalse(a.equals(b));
|
||||
}
|
||||
|
||||
@Test public void addressToString() throws Exception {
|
||||
Address address = new Address("square.com", 80, dns, socketFactory, null, null, null,
|
||||
authenticator, null, protocols, connectionSpecs, proxySelector);
|
||||
assertEquals("Address{square.com:80, proxySelector=RecordingProxySelector}",
|
||||
address.toString());
|
||||
}
|
||||
|
||||
@Test public void addressWithProxyToString() throws Exception {
|
||||
Address address = new Address("square.com", 80, dns, socketFactory, null, null, null,
|
||||
authenticator, Proxy.NO_PROXY, protocols, connectionSpecs, proxySelector);
|
||||
assertEquals("Address{square.com:80, proxy=" + Proxy.NO_PROXY + "}", address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,7 +1013,10 @@ public final class CallTest {
|
||||
executeSynchronously("/").assertBody("seed connection pool");
|
||||
|
||||
// If this succeeds, too many requests were made.
|
||||
executeSynchronously("/").assertFailure(IOException.class);
|
||||
executeSynchronously("/")
|
||||
.assertFailure(IOException.class)
|
||||
.assertFailureMatches("unexpected end of stream on Connection.*"
|
||||
+ server.getHostName() + ":" + server.getPort() + ".*");
|
||||
}
|
||||
|
||||
@Test public void recoverFromTlsHandshakeFailure() throws Exception {
|
||||
|
||||
@@ -154,6 +154,12 @@ public final class RecordedResponse {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecordedResponse assertFailureMatches(String pattern) {
|
||||
assertNotNull(failure);
|
||||
assertTrue(failure.getMessage(), failure.getMessage().matches(pattern));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecordedResponse assertSentRequestAtMillis(long minimum, long maximum) {
|
||||
assertDateInRange(minimum, response.sentRequestAtMillis(), maximum);
|
||||
return this;
|
||||
|
||||
@@ -327,6 +327,12 @@ public final class RouteSelectorTest {
|
||||
assertEquals("127.0.0.1", RouteSelector.getHostString(socketAddress));
|
||||
}
|
||||
|
||||
@Test public void routeToString() throws Exception {
|
||||
Route route = new Route(httpAddress(), Proxy.NO_PROXY,
|
||||
InetSocketAddress.createUnresolved("host", 1234));
|
||||
assertEquals("Route{host:1234}", route.toString());
|
||||
}
|
||||
|
||||
private void assertRoute(Route route, Address address, Proxy proxy, InetAddress socketAddress,
|
||||
int socketPort) {
|
||||
assertEquals(address, route.address());
|
||||
|
||||
@@ -49,4 +49,8 @@ public final class RecordingProxySelector extends ProxySelector {
|
||||
Util.format("%s %s:%d %s", uri, socketAddress.getHostName(), socketAddress.getPort(),
|
||||
ioe.getMessage()));
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "RecordingProxySelector";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,4 +180,19 @@ public final class Address {
|
||||
result = 31 * result + (certificatePinner != null ? certificatePinner.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
StringBuilder result = new StringBuilder()
|
||||
.append("Address{")
|
||||
.append(url.host()).append(":").append(url.port());
|
||||
|
||||
if (proxy != null) {
|
||||
result.append(", proxy=").append(proxy);
|
||||
} else {
|
||||
result.append(", proxySelector=").append(proxySelector);
|
||||
}
|
||||
|
||||
result.append("}");
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,4 +96,8 @@ public final class Route {
|
||||
result = 31 * result + inetSocketAddress.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "Route{" + inetSocketAddress + "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ import okhttp3.internal.Internal;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.http.HttpCodec;
|
||||
import okhttp3.internal.http1.Http1Codec;
|
||||
import okhttp3.internal.http2.ConnectionShutdownException;
|
||||
import okhttp3.internal.http2.ErrorCode;
|
||||
import okhttp3.internal.http2.Http2Codec;
|
||||
import okhttp3.internal.http2.ConnectionShutdownException;
|
||||
import okhttp3.internal.http2.StreamResetException;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
@@ -342,7 +342,8 @@ public final class StreamAllocation {
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return address.toString();
|
||||
RealConnection connection = connection();
|
||||
return connection != null ? connection.toString() : address.toString();
|
||||
}
|
||||
|
||||
public static final class StreamAllocationReference extends WeakReference<StreamAllocation> {
|
||||
|
||||
Reference in New Issue
Block a user