Skip to content

Commit 64c7838

Browse files
committed
Sync pekko tests with akka tests
1 parent 9b8a87b commit 64c7838

File tree

5 files changed

+88
-23
lines changed

5 files changed

+88
-23
lines changed

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/client/HttpExtClientInstrumentation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client;
77

8-
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
98
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client.PekkoHttpClientSingletons.instrumenter;
109
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client.PekkoHttpClientSingletons.setter;
1110
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -45,7 +44,7 @@ public static class SingleRequestAdvice {
4544
@ToArgument(value = 0, index = 0, typing = Assigner.Typing.DYNAMIC))
4645
@Advice.OnMethodEnter(suppress = Throwable.class)
4746
public static Object[] methodEnter(@Advice.Argument(value = 0) HttpRequest request) {
48-
Context parentContext = currentContext();
47+
Context parentContext = Context.current();
4948
if (!instrumenter().shouldStart(parentContext, request)) {
5049
return new Object[] {request, null, null};
5150
}
@@ -90,7 +89,7 @@ public static Future<HttpResponse> methodExit(
9089
responseFuture.onComplete(
9190
new OnCompleteHandler(context, request), thiz.system().dispatcher());
9291

93-
return FutureWrapper.wrap(responseFuture, thiz.system().dispatcher(), currentContext());
92+
return FutureWrapper.wrap(responseFuture, thiz.system().dispatcher(), Context.current());
9493
}
9594
}
9695
}

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerTracer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server;
77

8-
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
98
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.PekkoHttpServerSingletons.instrumenter;
109

1110
import io.opentelemetry.context.Context;
@@ -99,7 +98,7 @@ public void onDownstreamFinish(Throwable cause) {
9998
public void onPush() {
10099
HttpRequest request = grab(requestIn);
101100
PekkoTracingRequest tracingRequest = PekkoTracingRequest.EMPTY;
102-
Context parentContext = currentContext();
101+
Context parentContext = Context.current();
103102
if (instrumenter().shouldStart(parentContext, request)) {
104103
Context context = instrumenter().start(parentContext, request);
105104
context = PekkoRouteHolder.init(context);

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/route/PekkoRouteWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route;
77

88
import io.opentelemetry.context.Context;
9-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
109
import org.apache.pekko.http.scaladsl.server.RequestContext;
1110
import org.apache.pekko.http.scaladsl.server.RouteResult;
1211
import scala.Function1;
@@ -21,7 +20,7 @@ public PekkoRouteWrapper(Function1<RequestContext, Future<RouteResult>> route) {
2120

2221
@Override
2322
public Future<RouteResult> apply(RequestContext ctx) {
24-
Context context = Java8BytecodeBridge.currentContext();
23+
Context context = Context.current();
2524
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
2625
if (routeHolder == null) {
2726
return route.apply(ctx);

instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/tapir/RouteWrapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.tapir;
77

88
import io.opentelemetry.context.Context;
9-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
109
import io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route.PekkoRouteHolder;
1110
import java.nio.charset.Charset;
1211
import org.apache.pekko.http.scaladsl.model.Uri;
@@ -47,7 +46,7 @@ public boolean isDefinedAt(Try<RouteResult> tryResult) {
4746

4847
@Override
4948
public Unit apply(Try<RouteResult> tryResult) {
50-
Context context = Java8BytecodeBridge.currentContext();
49+
Context context = Context.current();
5150
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
5251
if (routeHolder != null && tryResult.isSuccess()) {
5352
RouteResult result = tryResult.get();

instrumentation/pekko/pekko-http-1.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/PekkoHttpServerRouteTest.scala

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import org.apache.pekko.http.scaladsl.server.Route
2020
import org.assertj.core.api.Assertions.assertThat
2121
import org.junit.jupiter.api.extension.RegisterExtension
2222
import org.junit.jupiter.api.{AfterAll, Test, TestInstance}
23+
import org.junit.jupiter.params.ParameterizedTest
24+
import org.junit.jupiter.params.provider.CsvSource
2325

2426
import java.net.{URI, URISyntaxException}
2527
import java.util.function.Consumer
@@ -50,7 +52,6 @@ class PekkoHttpServerRouteTest {
5052
}
5153

5254
@Test def testPathPrefix(): Unit = {
53-
import org.apache.pekko.http.scaladsl.server.Directives._
5455
val route =
5556
pathPrefix("a") {
5657
pathPrefix("b") {
@@ -88,26 +89,44 @@ class PekkoHttpServerRouteTest {
8889
test(route, "/foo/number-123", "GET /foo/*")
8990
}
9091

91-
@Test def testPipe(): Unit = {
92+
@ParameterizedTest
93+
@CsvSource(
94+
Array(
95+
"/i42, GET /i*",
96+
"/hCAFE, GET /h*"
97+
)
98+
)
99+
def testPipe(requestPath: String, expectedName: String): Unit = {
92100
val route = path("i" ~ IntNumber | "h" ~ HexIntNumber) { _ =>
93101
complete("ok")
94102
}
95-
test(route, "/i42", "GET /i*")
96-
test(route, "/hCAFE", "GET /h*")
103+
test(route, requestPath, expectedName)
97104
}
98105

99-
@Test def testMapExtractor(): Unit = {
106+
@ParameterizedTest
107+
@CsvSource(
108+
Array(
109+
"/colours/red, GET /colours/red",
110+
"/colours/green, GET /colours/green"
111+
)
112+
)
113+
def testMapExtractor(requestPath: String, expectedName: String): Unit = {
100114
val route = path("colours" / Map("red" -> 1, "green" -> 2, "blue" -> 3)) {
101115
_ => complete("ok")
102116
}
103-
test(route, "/colours/red", "GET /colours/red")
104-
test(route, "/colours/green", "GET /colours/green")
117+
test(route, requestPath, expectedName)
105118
}
106119

107-
@Test def testNotMatch(): Unit = {
120+
@ParameterizedTest
121+
@CsvSource(
122+
Array(
123+
"/fooish, GET /foo*",
124+
"/fooish/123, GET /foo*"
125+
)
126+
)
127+
def testNotMatch(requestPath: String, expectedName: String): Unit = {
108128
val route = pathPrefix("foo" ~ not("bar")) { complete("ok") }
109-
test(route, "/fooish", "GET /foo*")
110-
test(route, "/fooish/123", "GET /foo*")
129+
test(route, requestPath, expectedName)
111130
}
112131

113132
@Test def testProvide(): Unit = {
@@ -121,12 +140,18 @@ class PekkoHttpServerRouteTest {
121140
test(route, "/foo/bar", "GET /foo/bar")
122141
}
123142

124-
@Test def testOptional(): Unit = {
143+
@ParameterizedTest
144+
@CsvSource(
145+
Array(
146+
"/foo/bar/X42/edit, GET /foo/bar/X*/edit",
147+
"/foo/bar/X/edit, GET /foo/bar/X/edit"
148+
)
149+
)
150+
def testOptional(requestPath: String, expectedName: String): Unit = {
125151
val route = path("foo" / "bar" / "X" ~ IntNumber.? / ("edit" | "create")) {
126152
_ => complete("ok")
127153
}
128-
test(route, "/foo/bar/X42/edit", "GET /foo/bar/X*/edit")
129-
test(route, "/foo/bar/X/edit", "GET /foo/bar/X/edit")
154+
test(route, requestPath, expectedName)
130155
}
131156

132157
@Test def testNoMatches(): Unit = {
@@ -186,14 +211,58 @@ class PekkoHttpServerRouteTest {
186211
test(route, "/test/foo/1", "GET /test/foo/*")
187212
}
188213

214+
@Test def testRouteWithUUID(): Unit = {
215+
val route =
216+
pathPrefix("foo") {
217+
pathPrefix("api") {
218+
pathPrefix("v2") {
219+
pathPrefix("bar") {
220+
path(JavaUUID) { _ =>
221+
complete("ok")
222+
}
223+
}
224+
}
225+
}
226+
}
227+
228+
test(
229+
route,
230+
"/foo/api/v2/bar/5bb7c7d8-0128-4349-86af-fe718f4f8059",
231+
"GET /foo/api/v2/bar/*"
232+
)
233+
}
234+
235+
@Test def testRouteWithSegment(): Unit = {
236+
val route =
237+
pathPrefix("api") {
238+
pathPrefix("v2") {
239+
pathPrefix("orders") {
240+
path(Segment) { _ =>
241+
complete("ok")
242+
}
243+
}
244+
}
245+
}
246+
247+
test(route, "/api/v2/orders/order123", "GET /api/v2/orders/*")
248+
}
249+
250+
@Test def testRouteWithSubSegment(): Unit = {
251+
val route =
252+
pathPrefix("api" / "v2" / "orders" / Segment / "status") { _ =>
253+
complete("ok")
254+
}
255+
256+
test(route, "/api/v2/orders/order123/status", "GET /api/v2/orders/*/status")
257+
}
258+
189259
def test(
190260
route: Route,
191261
path: String,
192262
spanName: String,
193263
expectedStatus: Int = 200,
194264
expectedMsg: String = "ok"
195265
): Unit = {
196-
testing.clearData()
197266
val port = PortUtils.findOpenPort
198267
val address: URI = buildAddress(port)
199268
val binding =

0 commit comments

Comments
 (0)