Skip to content

Commit 2e6ff44

Browse files
committed
misc cleanup
1 parent d933a40 commit 2e6ff44

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

dd-java-agent-ittests/src/test/groovy/com/datadoghq/agent/integration/TestHttpServer.groovy

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package com.datadoghq.agent.integration
22

3-
import io.opentracing.ActiveSpan;
4-
import io.opentracing.SpanContext;
5-
import io.opentracing.propagation.Format;
6-
import io.opentracing.propagation.TextMap;
7-
import io.opentracing.util.GlobalTracer;
8-
9-
import ratpack.http.MutableHeaders
10-
import ratpack.http.Response
3+
import io.opentracing.ActiveSpan
4+
import io.opentracing.SpanContext
5+
import io.opentracing.propagation.Format
6+
import io.opentracing.propagation.TextMap
7+
import io.opentracing.util.GlobalTracer
118
import ratpack.groovy.test.embed.GroovyEmbeddedApp
129
import ratpack.handling.Context
1310

1411
import static ratpack.groovy.test.embed.GroovyEmbeddedApp.ratpack
1512

1613
/**
1714
* A simple http server used for testing.<br>
18-
* Binds locally to {@link #PORT}.
15+
* Binds locally to {@link #port}.
1916
*
2017
* <p>To start: {@link #startServer()}<br>
2118
* to stop: {@link #stopServer()}
@@ -27,24 +24,24 @@ class TestHttpServer {
2724
*/
2825
public static final String IS_DD_SERVER = "is-dd-server"
2926

30-
private static GroovyEmbeddedApp INSTANCE = null
31-
private static int PORT = 0
27+
private static GroovyEmbeddedApp server = null
28+
private static int port = 0
3229

3330
static int getPort() {
34-
if (PORT == 0) {
31+
if (port == 0) {
3532
throw new RuntimeException("Server not started")
3633
}
37-
return PORT;
34+
return port
3835
}
3936

4037
/**
4138
* Start the server. Has no effect if already started.
4239
*
4340
* @throws IOException
4441
*/
45-
static synchronized def startServer() {
46-
if (null == INSTANCE) {
47-
INSTANCE = ratpack {
42+
static synchronized startServer() {
43+
if (null == server) {
44+
server = ratpack {
4845
handlers {
4946
get {
5047
String msg = "<html><body><h1>Hello test.</h1>\n"
@@ -55,46 +52,46 @@ class TestHttpServer {
5552
if (isDDServer) {
5653
final SpanContext extractedContext =
5754
GlobalTracer.get()
58-
.extract(Format.Builtin.HTTP_HEADERS, new RatpackResponseAdapter(context))
55+
.extract(Format.Builtin.HTTP_HEADERS, new RatpackResponseAdapter(context))
5956
ActiveSpan span =
6057
GlobalTracer.get()
61-
.buildSpan("test-http-server")
62-
.asChildOf(extractedContext)
63-
.startActive()
58+
.buildSpan("test-http-server")
59+
.asChildOf(extractedContext)
60+
.startActive()
6461
span.deactivate()
6562
}
6663

6764
response.status(200).send(msg)
6865
}
6966
}
7067
}
71-
PORT = INSTANCE.address.port
68+
port = server.address.port
7269
}
7370
}
7471

7572
/** Stop the server. Has no effect if already stopped. */
7673
static synchronized void stopServer() {
77-
if (null != INSTANCE) {
78-
INSTANCE.close()
79-
INSTANCE = null
80-
PORT = 0
74+
if (null != server) {
75+
server.close()
76+
server = null
77+
port = 0
8178
}
8279
}
8380

8481
private static class RatpackResponseAdapter implements TextMap {
85-
final Context context;
82+
final Context context
8683

87-
public RatpackResponseAdapter(Context context) {
84+
RatpackResponseAdapter(Context context) {
8885
this.context = context
8986
}
9087

9188
@Override
92-
public void put(String key, String value) {
89+
void put(String key, String value) {
9390
context.response.set(key, value)
9491
}
9592

9693
@Override
97-
public Iterator<Map.Entry<String, String>> iterator() {
94+
Iterator<Map.Entry<String, String>> iterator() {
9895
return context.request.getHeaders().asMultiValueMap().entrySet().iterator()
9996
}
10097
}

dd-java-agent-ittests/src/test/groovy/com/datadoghq/agent/integration/httpclient/ApacheHttpClientTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import spock.lang.Specification
1717
class ApacheHttpClientTest extends Specification {
1818

1919
@Shared
20-
def ListWriter writer = new ListWriter()
20+
def writer = new ListWriter()
2121
@Shared
22-
def DDTracer tracer = new DDTracer(writer)
22+
def tracer = new DDTracer(writer)
2323

2424
def setupSpec() {
2525
TestUtils.registerOrReplaceGlobalTracer(tracer)

dd-java-agent/integrations/jms-2/src/test/groovy/JMS2Test.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class JMS2Test extends Specification {
156156
def producer = session.createProducer(destination)
157157
def consumer = session.createConsumer(destination)
158158
consumer.setMessageListener { message ->
159-
Thread.sleep(5) // Slow things down a bit.
159+
Thread.sleep(10) // Slow things down a bit.
160160
messageRef.set(message)
161161
}
162162

dd-java-agent/integrations/okhttp-3/src/main/java/dd/inst/okhttp3/OkHttp3Instrumentation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Collections;
1515
import net.bytebuddy.agent.builder.AgentBuilder;
1616
import net.bytebuddy.asm.Advice;
17+
import okhttp3.Interceptor;
1718
import okhttp3.OkHttpClient;
1819

1920
@AutoService(Instrumenter.class)
@@ -38,6 +39,11 @@ public static class OkHttp3Advice {
3839
@Advice.OnMethodEnter(suppress = Throwable.class)
3940
public static void addTracingInterceptor(
4041
@Advice.Argument(0) final OkHttpClient.Builder builder) {
42+
for (final Interceptor interceptor : builder.interceptors()) {
43+
if (interceptor instanceof TracingInterceptor) {
44+
return;
45+
}
46+
}
4147
final TracingInterceptor interceptor =
4248
new TracingInterceptor(GlobalTracer.get(), Collections.singletonList(STANDARD_TAGS));
4349
builder.addInterceptor(interceptor);

dd-java-agent/integrations/okhttp-3/src/test/groovy/OkHttp3Test.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ class OkHttp3Test extends Specification {
4040
}
4141
}
4242
}
43-
def client = new OkHttpClient();
43+
def client = new OkHttpClient()
4444
def request = new Request.Builder()
4545
.url("http://localhost:$server.address.port/ping")
46-
.build();
46+
.build()
4747

4848
def response = client.newCall(request).execute()
4949

dd-java-agent/tooling/src/test/groovy/dd/test/TestUtils.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class TestUtils {
5050
}
5151

5252
static runUnderTrace(final String rootOperationName, Callable r) {
53-
ActiveSpan rootSpan = GlobalTracer.get().buildSpan(rootOperationName).startActive();
53+
ActiveSpan rootSpan = GlobalTracer.get().buildSpan(rootOperationName).startActive()
5454
try {
55-
return r.call();
55+
return r.call()
5656
} finally {
57-
rootSpan.deactivate();
57+
rootSpan.deactivate()
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)