Skip to content

Commit 9e3c130

Browse files
committed
up
1 parent b2968ca commit 9e3c130

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

instrumentation/ratpack/ratpack-1.4/testing/src/main/java/io/opentelemetry/instrumentation/ratpack/client/AbstractRatpackHttpClientTest.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest;
1616
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult;
1717
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions;
18-
import java.net.ConnectException;
1918
import java.net.URI;
2019
import java.nio.channels.ClosedChannelException;
2120
import java.time.Duration;
@@ -180,7 +179,10 @@ private static Throwable nettyClientSpanErrorMapper(URI uri, Throwable exception
180179
if (rootCause instanceof ClosedChannelException) {
181180
return new PrematureChannelClosureException();
182181
}
183-
return buildConnectTimeoutException(uri, rootCause);
182+
if (isWindows()) {
183+
return exception;
184+
}
185+
return rootCause != null ? rootCause : exception;
184186
}
185187
return exception;
186188
}
@@ -193,7 +195,7 @@ private static String nettyExpectedClientSpanNameMapper(URI uri, String method)
193195
// On Windows, non-routable addresses don't fail at CONNECT level.
194196
// The connection proceeds far enough to start HTTP processing before
195197
// the channel closes, resulting in an HTTP span instead of CONNECT.
196-
if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")) {
198+
if (isWindows()) {
197199
return HttpClientTestOptions.DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER.apply(uri, method);
198200
}
199201
return "CONNECT";
@@ -206,6 +208,10 @@ private static boolean isNonRoutableAddress(URI uri) {
206208
return "192.0.2.1".equals(uri.getHost());
207209
}
208210

211+
private static boolean isWindows() {
212+
return System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
213+
}
214+
209215
private static Throwable unwrapConnectionException(Throwable exception) {
210216
if (exception == null) {
211217
return null;
@@ -216,20 +222,4 @@ private static Throwable unwrapConnectionException(Throwable exception) {
216222
}
217223
return current;
218224
}
219-
220-
private static Throwable buildConnectTimeoutException(URI uri, Throwable original) {
221-
String message = "connection timed out: /" + uri.getHost() + ":" + resolvePort(uri);
222-
ConnectException connectException = new ConnectException(message);
223-
if (original != null && original != connectException) {
224-
connectException.initCause(original);
225-
}
226-
return connectException;
227-
}
228-
229-
private static int resolvePort(URI uri) {
230-
if (uri.getPort() != -1) {
231-
return uri.getPort();
232-
}
233-
return uri.getScheme().equalsIgnoreCase("https") ? 443 : 80;
234-
}
235225
}

0 commit comments

Comments
 (0)