Move server field to HttpServerTest
MODIFY
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy
dd-java-agent/instrumentation/akka-http-10.0/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy
@@ -7,7 +7,7 @@ import io.opentracing.tag.Tags
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
-abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<AkkaHttpServerDecorator> {
+abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<Object, AkkaHttpServerDecorator> {
@Override
AkkaHttpServerDecorator decorator() {
@@ -26,12 +26,12 @@ abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<AkkaHttp
// FIXME: This doesn't work because we don't support bindAndHandle.
// @Override
-// void startServer(int port) {
+// def startServer(int port) {
// AkkaHttpTestWebServer.start(port)
// }
//
// @Override
-// void stopServer() {
+// void stopServer(Object ignore) {
// AkkaHttpTestWebServer.stop()
// }
@@ -68,24 +68,24 @@ abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest<AkkaHttp
class AkkaHttpServerInstrumentationTestSync extends AkkaHttpServerInstrumentationTest {
@Override
- void startServer(int port) {
+ def startServer(int port) {
AkkaHttpTestSyncWebServer.start(port)
}
@Override
- void stopServer() {
+ void stopServer(Object ignore) {
AkkaHttpTestSyncWebServer.stop()
}
}
class AkkaHttpServerInstrumentationTestAsync extends AkkaHttpServerInstrumentationTest {
@Override
- void startServer(int port) {
+ def startServer(int port) {
AkkaHttpTestAsyncWebServer.start(port)
}
@Override
- void stopServer() {
+ void stopServer(Object ignore) {
AkkaHttpTestAsyncWebServer.stop()
}
}

MODIFY
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
dd-java-agent/instrumentation/netty-4.0/src/test/groovy/Netty40ServerTest.groovy
@@ -12,6 +12,7 @@ import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.handler.codec.http.DefaultFullHttpResponse
import io.netty.handler.codec.http.FullHttpResponse
+import io.netty.handler.codec.http.HttpHeaders
import io.netty.handler.codec.http.HttpRequest
import io.netty.handler.codec.http.HttpRequestDecoder
import io.netty.handler.codec.http.HttpResponseEncoder
@@ -19,7 +20,6 @@ import io.netty.handler.codec.http.HttpResponseStatus
import io.netty.handler.logging.LogLevel
import io.netty.handler.logging.LoggingHandler
import io.netty.util.CharsetUtil
-import spock.lang.Shared
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
@@ -31,13 +31,11 @@ import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
-class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
- @Shared
- EventLoopGroup eventLoopGroup
+class Netty40ServerTest extends HttpServerTest<EventLoopGroup, NettyHttpServerDecorator> {
@Override
- void startServer(int port) {
- eventLoopGroup = new NioEventLoopGroup()
+ EventLoopGroup startServer(int port) {
+ def eventLoopGroup = new NioEventLoopGroup()
ServerBootstrap bootstrap = new ServerBootstrap()
.group(eventLoopGroup)
@@ -91,11 +89,13 @@ class Netty40ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
}
] as ChannelInitializer).channel(NioServerSocketChannel)
bootstrap.bind(port).sync()
+
+ return eventLoopGroup
}
@Override
- void stopServer() {
- eventLoopGroup?.shutdownGracefully()
+ void stopServer(EventLoopGroup server) {
+ server?.shutdownGracefully()
}
@Override

MODIFY
dd-java-agent/instrumentation/netty-4.1/src/test/groovy/Netty41ServerTest.groovy
dd-java-agent/instrumentation/netty-4.1/src/test/groovy/Netty41ServerTest.groovy
@@ -19,7 +19,6 @@ import io.netty.handler.codec.http.HttpServerCodec
import io.netty.handler.logging.LogLevel
import io.netty.handler.logging.LoggingHandler
import io.netty.util.CharsetUtil
-import spock.lang.Shared
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
@@ -31,13 +30,11 @@ import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE
import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
-class Netty41ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
- @Shared
- EventLoopGroup eventLoopGroup
+class Netty41ServerTest extends HttpServerTest<EventLoopGroup, NettyHttpServerDecorator> {
@Override
- void startServer(int port) {
- eventLoopGroup = new NioEventLoopGroup()
+ EventLoopGroup startServer(int port) {
+ def eventLoopGroup = new NioEventLoopGroup()
ServerBootstrap bootstrap = new ServerBootstrap()
.group(eventLoopGroup)
@@ -91,11 +88,13 @@ class Netty41ServerTest extends HttpServerTest<NettyHttpServerDecorator> {
}
] as ChannelInitializer).channel(NioServerSocketChannel)
bootstrap.bind(port).sync()
+
+ return eventLoopGroup
}
@Override
- void stopServer() {
- eventLoopGroup?.shutdownGracefully()
+ void stopServer(EventLoopGroup server) {
+ server?.shutdownGracefully()
}
@Override

MODIFY
dd-java-agent/instrumentation/servlet-2/src/test/groovy/JettyServlet2Test.groovy
dd-java-agent/instrumentation/servlet-2/src/test/groovy/JettyServlet2Test.groovy
@@ -14,14 +14,13 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
-class JettyServlet2Test extends HttpServerTest<Servlet2Decorator> {
+class JettyServlet2Test extends HttpServerTest<Server, Servlet2Decorator> {
private static final CONTEXT = "ctx"
- private Server jettyServer
@Override
- void startServer(int port) {
- jettyServer = new Server(port)
+ Server startServer(int port) {
+ def jettyServer = new Server(port)
jettyServer.connectors.each { it.resolveNames = true } // get localhost instead of 127.0.0.1
ServletContextHandler servletContext = new ServletContextHandler(null, "/$CONTEXT")
servletContext.errorHandler = new ErrorHandler() {
@@ -43,12 +42,14 @@ class JettyServlet2Test extends HttpServerTest<Servlet2Decorator> {
jettyServer.setHandler(servletContext)
jettyServer.start()
+
+ return jettyServer
}
@Override
- void stopServer() {
- jettyServer.stop()
- jettyServer.destroy()
+ void stopServer(Server server) {
+ server.stop()
+ server.destroy()
}
@Override

MODIFY
dd-java-agent/instrumentation/servlet-3/src/test/groovy/AbstractServlet3Test.groovy
dd-java-agent/instrumentation/servlet-3/src/test/groovy/AbstractServlet3Test.groovy
@@ -13,7 +13,7 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
-abstract class AbstractServlet3Test<CONTEXT> extends HttpServerTest<Servlet3Decorator> {
+abstract class AbstractServlet3Test<SERVER, CONTEXT> extends HttpServerTest<SERVER, Servlet3Decorator> {
@Override
URI buildAddress() {
return new URI("http://localhost:$port/$context/")

MODIFY
dd-java-agent/instrumentation/servlet-3/src/test/groovy/JettyServlet3Test.groovy
dd-java-agent/instrumentation/servlet-3/src/test/groovy/JettyServlet3Test.groovy
@@ -10,7 +10,6 @@ import org.apache.catalina.core.ApplicationFilterChain
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler.ErrorHandler
import org.eclipse.jetty.servlet.ServletContextHandler
-import spock.lang.Shared
import static datadog.trace.agent.test.asserts.TraceAssert.assertTrace
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
@@ -20,10 +19,7 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRE
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
-abstract class JettyServlet3Test extends AbstractServlet3Test<ServletContextHandler> {
-
- @Shared
- private Server jettyServer
+abstract class JettyServlet3Test extends AbstractServlet3Test<Server, ServletContextHandler> {
@Override
boolean testNotFound() {
@@ -31,8 +27,8 @@ abstract class JettyServlet3Test extends AbstractServlet3Test<ServletContextHand
}
@Override
- void startServer(int port) {
- jettyServer = new Server(port)
+ Server startServer(int port) {
+ def jettyServer = new Server(port)
jettyServer.connectors.each {
if (it.hasProperty("resolveNames")) {
it.resolveNames = true // get localhost instead of 127.0.0.1
@@ -52,14 +48,13 @@ abstract class JettyServlet3Test extends AbstractServlet3Test<ServletContextHand
jettyServer.start()
- System.out.println(
- "Jetty server: http://localhost:" + port + "/")
+ return jettyServer
}
@Override
- void stopServer() {
- jettyServer.stop()
- jettyServer.destroy()
+ void stopServer(Server server) {
+ server.stop()
+ server.destroy()
}
@Override

MODIFY
dd-java-agent/instrumentation/servlet-3/src/test/groovy/TomcatServlet3Test.groovy
dd-java-agent/instrumentation/servlet-3/src/test/groovy/TomcatServlet3Test.groovy
@@ -15,7 +15,6 @@ import org.apache.catalina.startup.Tomcat
import org.apache.catalina.valves.ErrorReportValve
import org.apache.tomcat.JarScanFilter
import org.apache.tomcat.JarScanType
-import spock.lang.Shared
import static datadog.trace.agent.test.asserts.TraceAssert.assertTrace
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED
@@ -26,14 +25,11 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRE
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
-abstract class TomcatServlet3Test extends AbstractServlet3Test<Context> {
-
- @Shared
- Tomcat tomcatServer
+abstract class TomcatServlet3Test extends AbstractServlet3Test<Tomcat, Context> {
@Override
- void startServer(int port) {
- tomcatServer = new Tomcat()
+ Tomcat startServer(int port) {
+ def tomcatServer = new Tomcat()
def baseDir = Files.createTempDir()
baseDir.deleteOnExit()
@@ -62,14 +58,14 @@ abstract class TomcatServlet3Test extends AbstractServlet3Test<Context> {
(tomcatServer.host as StandardHost).errorReportValveClass = ErrorHandlerValve.name
tomcatServer.start()
- System.out.println(
- "Tomcat server: http://" + tomcatServer.getHost().getName() + ":" + port + "/")
+
+ return tomcatServer
}
@Override
- void stopServer() {
- tomcatServer.stop()
- tomcatServer.destroy()
+ void stopServer(Tomcat server) {
+ server.stop()
+ server.destroy()
}
@Override

MODIFY
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxHttpServerTest.groovy
dd-java-agent/instrumentation/vertx/src/test/groovy/server/VertxHttpServerTest.groovy
@@ -12,7 +12,6 @@ import io.vertx.core.Vertx
import io.vertx.core.VertxOptions
import io.vertx.core.json.JsonObject
import io.vertx.ext.web.Router
-import spock.lang.Shared
import java.util.concurrent.CompletableFuture
@@ -21,15 +20,12 @@ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
-class VertxHttpServerTest extends HttpServerTest<NettyHttpServerDecorator> {
+class VertxHttpServerTest extends HttpServerTest<Vertx, NettyHttpServerDecorator> {
public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"
- @Shared
- Vertx server
-
@Override
- void startServer(int port) {
- server = Vertx.vertx(new VertxOptions()
+ Vertx startServer(int port) {
+ def server = Vertx.vertx(new VertxOptions()
// Useful for debugging:
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
.setClusterPort(port))
@@ -45,6 +41,7 @@ class VertxHttpServerTest extends HttpServerTest<NettyHttpServerDecorator> {
}
future.get()
+ return server
}
protected Class<io.vertx.reactivex.core.AbstractVerticle> verticle() {
@@ -52,7 +49,7 @@ class VertxHttpServerTest extends HttpServerTest<NettyHttpServerDecorator> {
}
@Override
- void stopServer() {
+ void stopServer(Vertx server) {
server.close()
}

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy
@@ -24,14 +24,17 @@ import static datadog.trace.agent.test.asserts.TraceAssert.assertTrace
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
+import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
import static org.junit.Assume.assumeTrue
@Unroll
-abstract class HttpServerTest<DECORATOR extends HttpServerDecorator> extends AgentTestRunner {
+abstract class HttpServerTest<SERVER, DECORATOR extends HttpServerDecorator> extends AgentTestRunner {
+ @Shared
+ SERVER server
@Shared
OkHttpClient client = OkHttpUtils.client()
@Shared
@@ -47,18 +50,19 @@ abstract class HttpServerTest<DECORATOR extends HttpServerDecorator> extends Age
DECORATOR serverDecorator = decorator()
def setupSpec() {
- startServer(port)
- println "Http server started at: http://localhost:$port/"
+ server = startServer(port)
+ println getClass().name + " http server started at: http://localhost:$port/"
}
- abstract void startServer(int port)
+ abstract SERVER startServer(int port)
def cleanupSpec() {
- stopServer()
- println "Http server stopped at: http://localhost:$port/"
+ stopServer(server)
+ server = null
+ println getClass().name + " http server stopped at: http://localhost:$port/"
}
- abstract void stopServer()
+ abstract void stopServer(SERVER server)
abstract DECORATOR decorator()

Move server field to HttpServerTest