Skip to content

Commit 9c69dd4

Browse files
committed
fix method names, remove redundant config code
1 parent 24b2a26 commit 9c69dd4

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

instrumentation/dropwizard/dropwizard-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/dropwizard/DropwizardAsyncTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Class<?> testResource() {
4747
@Override
4848
protected void configure(HttpServerTestOptions options) {
4949
super.configure(options);
50-
customizeTestOptions(options);
5150
// server spans are ended inside the JAX-RS controller spans
5251
options.setVerifyServerSpanEndTime(false);
5352
}
@@ -80,7 +79,7 @@ public void success(@Suspended AsyncResponse asyncResponse) {
8079

8180
@GET
8281
@Path("query")
83-
public void query_param(
82+
public void queryParam(
8483
@QueryParam("some") String param, @Suspended AsyncResponse asyncResponse) {
8584
executor.execute(
8685
() ->
@@ -145,7 +144,7 @@ public void exception(@Suspended AsyncResponse asyncResponse) {
145144

146145
@GET
147146
@Path("path/{id}/param")
148-
public void path_param(@PathParam("id") int param, @Suspended AsyncResponse asyncResponse) {
147+
public void pathParam(@PathParam("id") int param, @Suspended AsyncResponse asyncResponse) {
149148
executor.execute(
150149
() ->
151150
controller(
@@ -157,7 +156,7 @@ public void path_param(@PathParam("id") int param, @Suspended AsyncResponse asyn
157156

158157
@GET
159158
@Path("child")
160-
public void indexed_child(
159+
public void indexedChild(
161160
@QueryParam("id") String param, @Suspended AsyncResponse asyncResponse) {
162161
controller(
163162
INDEXED_CHILD,
@@ -170,7 +169,7 @@ public void indexed_child(
170169

171170
@GET
172171
@Path("captureHeaders")
173-
public void capture_headers(
172+
public void captureHeaders(
174173
@HeaderParam("X-Test-Request") String header, @Suspended AsyncResponse asyncResponse) {
175174
controller(
176175
CAPTURE_HEADERS,

instrumentation/dropwizard/dropwizard-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/dropwizard/DropwizardTest.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
1616
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
1717
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
18+
import static org.assertj.core.api.Assertions.assertThat;
1819

1920
import io.dropwizard.Application;
2021
import io.dropwizard.Configuration;
@@ -66,7 +67,9 @@ protected void stopServer(DropwizardTestSupport<Configuration> server) {
6667
server.after();
6768
}
6869

69-
protected void customizeTestOptions(HttpServerTestOptions options) {
70+
@Override
71+
protected void configure(HttpServerTestOptions options) {
72+
super.configure(options);
7073
// this override is needed because dropwizard reports peer ip as the client ip
7174
options.setSockPeerAddr(serverEndpoint -> TEST_CLIENT_IP);
7275
options.setHasHandlerSpan(endpoint -> endpoint != NOT_FOUND);
@@ -90,12 +93,6 @@ protected void customizeTestOptions(HttpServerTestOptions options) {
9093
});
9194
}
9295

93-
@Override
94-
protected void configure(HttpServerTestOptions options) {
95-
super.configure(options);
96-
customizeTestOptions(options);
97-
}
98-
9996
Class<? extends Application<Configuration>> testApp() {
10097
return TestApp.class;
10198
}
@@ -107,18 +104,32 @@ Class<?> testResource() {
107104
@Override
108105
protected SpanDataAssert assertHandlerSpan(
109106
SpanDataAssert span, String method, ServerEndpoint endpoint) {
110-
span.hasName(testResource().getSimpleName() + "." + endpoint.name().toLowerCase(Locale.ROOT))
107+
span.hasName(testResource().getSimpleName() + "." + getEndpointName(endpoint))
111108
.hasKind(INTERNAL);
112109
if (EXCEPTION.equals(endpoint)) {
113110
span.hasStatus(StatusData.error()).hasException(new Exception(EXCEPTION.getBody()));
114111
}
115112
return span;
116113
}
117114

115+
private static String getEndpointName(ServerEndpoint endpoint) {
116+
if (QUERY_PARAM.equals(endpoint)) {
117+
return "queryParam";
118+
} else if (PATH_PARAM.equals(endpoint)) {
119+
return "pathParam";
120+
} else if (CAPTURE_HEADERS.equals(endpoint)) {
121+
return "captureHeaders";
122+
} else if (INDEXED_CHILD.equals(endpoint)) {
123+
return "indexedChild";
124+
}
125+
return endpoint.name().toLowerCase(Locale.ROOT);
126+
}
127+
118128
@Override
119129
protected SpanDataAssert assertResponseSpan(
120130
SpanDataAssert span, SpanData parentSpan, String method, ServerEndpoint endpoint) {
121-
span.hasName("CompressedResponseWrapper.sendError").hasKind(INTERNAL);
131+
span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError"))
132+
.hasKind(INTERNAL);
122133
return span;
123134
}
124135

@@ -149,7 +160,7 @@ public Response success() {
149160

150161
@GET
151162
@Path("query")
152-
public Response query_param(@QueryParam("some") String param) {
163+
public Response queryParam(@QueryParam("some") String param) {
153164
return controller(
154165
QUERY_PARAM,
155166
() -> Response.status(QUERY_PARAM.getStatus()).entity("some=" + param).build());
@@ -187,15 +198,15 @@ public Response exception() throws Exception {
187198

188199
@GET
189200
@Path("path/{id}/param")
190-
public Response path_param(@PathParam("id") int param) {
201+
public Response pathParam(@PathParam("id") int param) {
191202
return controller(
192203
PATH_PARAM,
193204
() -> Response.status(PATH_PARAM.getStatus()).entity(String.valueOf(param)).build());
194205
}
195206

196207
@GET
197208
@Path("child")
198-
public Response indexed_child(@QueryParam("id") String param) {
209+
public Response indexedChild(@QueryParam("id") String param) {
199210
return controller(
200211
INDEXED_CHILD,
201212
() -> {
@@ -208,7 +219,7 @@ public Response indexed_child(@QueryParam("id") String param) {
208219

209220
@GET
210221
@Path("captureHeaders")
211-
public Response capture_headers(@HeaderParam("X-Test-Request") String header) {
222+
public Response captureHeaders(@HeaderParam("X-Test-Request") String header) {
212223
return controller(
213224
CAPTURE_HEADERS,
214225
() ->

0 commit comments

Comments
 (0)