Add test case with netty

This commit is contained in:
Laplie Anderson 2019-10-08 13:43:26 +02:00
parent 5719a783ad
commit d5021e0cbc
2 changed files with 48 additions and 0 deletions

View File

@ -38,6 +38,7 @@ dependencies {
compileOnly group: 'io.netty', name: 'netty-codec-http', version: '4.1.0.Final'
testCompile project(':dd-java-agent:instrumentation:java-concurrent')
testCompile project(':dd-java-agent:instrumentation:trace-annotation')
testCompile group: 'io.netty', name: 'netty-codec-http', version: '4.1.0.Final'
testCompile group: 'org.asynchttpclient', name: 'async-http-client', version: '2.1.0'

View File

@ -1,4 +1,6 @@
import datadog.opentracing.DDSpan
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.api.Trace
import datadog.trace.instrumentation.netty41.client.HttpClientTracingHandler
import datadog.trace.instrumentation.netty41.client.NettyHttpClientDecorator
import io.netty.channel.AbstractChannel
@ -174,11 +176,54 @@ class Netty41ClientTest extends HttpClientTest<NettyHttpClientDecorator> {
null != channel.pipeline().remove(HttpClientTracingHandler.getName())
}
def "request with trace annotated method"() {
given:
def annotatedClass = new AnnotatedClass()
when:
def status = runUnderTrace("parent") {
annotatedClass.makeRequestUnderTrace(method)
}
then:
status == 200
assertTraces(2) {
server.distributedRequestTrace(it, 0, trace(1).last())
trace(1, size(3)) {
basicSpan(it, 0, "parent")
span(1) {
childOf((DDSpan) span(0))
serviceName "unnamed-java-app"
operationName "trace.annotation"
resourceName "AnnotatedClass.makeRequestUnderTrace"
errored false
tags {
defaultTags()
"$Tags.COMPONENT.key" "trace"
}
}
clientSpan(it, 2, span(1), method)
}
}
where:
method << BODY_METHODS
}
class AnnotatedClass {
@Trace
int makeRequestUnderTrace(String method) {
return doRequest(method, server.address.resolve("/success"))
}
}
class SimpleHandler implements ChannelHandler {
@Override
void handlerAdded(ChannelHandlerContext ctx) throws Exception {}
@Override
void handlerRemoved(ChannelHandlerContext ctx) throws Exception {}
@Override
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {}
}
@ -186,8 +231,10 @@ class Netty41ClientTest extends HttpClientTest<NettyHttpClientDecorator> {
class OtherSimpleHandler implements ChannelHandler {
@Override
void handlerAdded(ChannelHandlerContext ctx) throws Exception {}
@Override
void handlerRemoved(ChannelHandlerContext ctx) throws Exception {}
@Override
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {}
}