Enable read timeout test for reactor netty
MODIFY
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.groovy
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.groovy
@@ -27,6 +27,11 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
false
}
+ @Override
+ boolean testReadTimeout() {
+ true
+ }
+
@Override
String userAgent() {
return "ReactorNetty"
@@ -34,7 +39,8 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
@Override
HttpClient.ResponseReceiver buildRequest(String method, URI uri, Map<String, String> headers) {
- return createHttpClient()
+ def readTimeout = uri.toString().contains("/read-timeout")
+ return createHttpClient(readTimeout)
.followRedirect(true)
.headers({ h -> headers.each { k, v -> h.add(k, v) } })
.baseUrl(resolveAddress("").toString())
@@ -97,7 +103,7 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
return super.httpAttributes(uri)
}
- abstract HttpClient createHttpClient()
+ abstract HttpClient createHttpClient(boolean readTimeout)
def "should expose context to http client callbacks"() {
given:
@@ -107,7 +113,7 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
def afterResponseSpan = new AtomicReference<Span>()
def latch = new CountDownLatch(1)
- def httpClient = createHttpClient()
+ def httpClient = createHttpClient(false)
.doOnRequest({ rq, con -> onRequestSpan.set(Span.current()) })
.doAfterRequest({ rq, con -> afterRequestSpan.set(Span.current()) })
.doOnResponse({ rs, con -> onResponseSpan.set(Span.current()) })
@@ -155,7 +161,7 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
given:
def onRequestErrorSpan = new AtomicReference<Span>()
- def httpClient = createHttpClient()
+ def httpClient = createHttpClient(false)
.doOnRequestError({ rq, err -> onRequestErrorSpan.set(Span.current()) })
when:

MODIFY
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyHttpClientTest.groovy
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyHttpClientTest.groovy
package io.opentelemetry.javaagent.instrumentation.reactornetty.v0_9
import io.netty.channel.ChannelOption
+import io.netty.handler.timeout.ReadTimeoutHandler
import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection
+import java.util.concurrent.TimeUnit
import reactor.netty.http.client.HttpClient
import java.util.concurrent.ExecutionException
@@ -14,8 +16,13 @@ import java.util.concurrent.TimeoutException
class ReactorNettyHttpClientTest extends AbstractReactorNettyHttpClientTest {
- HttpClient createHttpClient() {
+ HttpClient createHttpClient(boolean readTimeout) {
return HttpClient.create().tcpConfiguration({ tcpClient ->
+ if (readTimeout) {
+ tcpClient = tcpClient.doOnConnected({ connection ->
+ connection.addHandlerLast(new ReadTimeoutHandler(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS))
+ })
+ }
tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS)
})
}

MODIFY
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyHttpClientUsingFromTest.groovy
instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyHttpClientUsingFromTest.groovy
package io.opentelemetry.javaagent.instrumentation.reactornetty.v0_9
import io.netty.channel.ChannelOption
+import io.netty.handler.timeout.ReadTimeoutHandler
+import java.util.concurrent.TimeUnit
import reactor.netty.http.client.HttpClient
import reactor.netty.tcp.TcpClient
class ReactorNettyHttpClientUsingFromTest extends AbstractReactorNettyHttpClientTest {
- HttpClient createHttpClient() {
+ HttpClient createHttpClient(boolean readTimeout) {
return HttpClient.from(TcpClient.create()).tcpConfiguration({ tcpClient ->
+ if (readTimeout) {
+ tcpClient = tcpClient.doOnConnected({ connection ->
+ connection.addHandlerLast(new ReadTimeoutHandler(READ_TIMEOUT_MS, TimeUnit.MILLISECONDS))
+ })
+ }
tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS)
})
}

MODIFY
instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.groovy
instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.groovy
@@ -18,6 +18,8 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpClientTest
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest
import io.opentelemetry.sdk.trace.data.SpanData
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
+import java.time.Duration
import reactor.netty.http.client.HttpClient
import java.util.concurrent.CountDownLatch
@@ -32,6 +34,11 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
false
}
+ @Override
+ boolean testReadTimeout() {
+ true
+ }
+
@Override
String userAgent() {
return "ReactorNetty"
@@ -39,11 +46,14 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
@Override
HttpClient.ResponseReceiver buildRequest(String method, URI uri, Map<String, String> headers) {
- return createHttpClient()
+ def client = createHttpClient()
.followRedirect(true)
.headers({ h -> headers.each { k, v -> h.add(k, v) } })
.baseUrl(resolveAddress("").toString())
- ."${method.toLowerCase()}"()
+ if (uri.toString().contains("/read-timeout")) {
+ client = client.responseTimeout(Duration.ofMillis(READ_TIMEOUT_MS))
+ }
+ return client."${method.toLowerCase()}"()
.uri(uri.toString())
}
@@ -88,7 +98,13 @@ abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest<HttpCli
case "https://192.0.2.1/": // non routable address
return []
}
- return super.httpAttributes(uri)
+ def attributes = super.httpAttributes(uri)
+ if (uri.toString().contains("/read-timeout")) {
+ attributes.remove(SemanticAttributes.NET_PEER_NAME)
+ attributes.remove(SemanticAttributes.NET_PEER_PORT)
+ attributes.remove(SemanticAttributes.HTTP_FLAVOR)
+ }
+ attributes
}
abstract HttpClient createHttpClient()

Enable read timeout test for reactor netty (#6156)