Skip to content

Commit 31768d7

Browse files
committed
add tests
1 parent 10f235b commit 31768d7

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0
77

88
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension
9-
import io.opentelemetry.instrumentation.testing.junit.http.{
10-
HttpServerInstrumentationExtension,
11-
HttpServerTestOptions
12-
}
9+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS
10+
import io.opentelemetry.instrumentation.testing.junit.http.{HttpServerInstrumentationExtension, HttpServerTestOptions}
11+
import io.opentelemetry.testing.internal.armeria.common.{AggregatedHttpRequest, AggregatedHttpResponse}
12+
import org.assertj.core.api.Assertions.assertThat
13+
import org.junit.jupiter.api.Test
1314
import org.junit.jupiter.api.extension.RegisterExtension
1415

1516
class PekkoHttpServerInstrumentationTestAsync
16-
extends AbstractHttpServerInstrumentationTest {
17+
extends AbstractHttpServerInstrumentationTest {
1718

1819
@RegisterExtension val extension: InstrumentationExtension =
1920
HttpServerInstrumentationExtension.forAgent()
@@ -27,9 +28,24 @@ class PekkoHttpServerInstrumentationTestAsync
2728
PekkoHttpTestAsyncWebServer.stop()
2829

2930
override protected def configure(
30-
options: HttpServerTestOptions
31-
): Unit = {
31+
options: HttpServerTestOptions
32+
): Unit = {
3233
super.configure(options)
3334
options.setTestHttpPipelining(false)
3435
}
36+
37+
@Test
38+
def successfulPostRequestWithParent(): Unit = {
39+
val method = "POST"
40+
val traceId = "00000000000000000000000000000123"
41+
val parentId = "0000000000000456"
42+
val aggregatedHttpRequest = AggregatedHttpRequest.of( // intentionally sending mixed-case "tracePARENT" to make sure that TextMapGetters are
43+
// not case-sensitive
44+
request(SUCCESS, method).headers.toBuilder.set("tracePARENT", "00-" + traceId + "-" + parentId + "-01").build)
45+
val response = client.execute(aggregatedHttpRequest).aggregate.join
46+
assertThat(response.status.code).isEqualTo(SUCCESS.getStatus)
47+
assertThat(response.contentUtf8).isEqualTo(SUCCESS.getBody)
48+
val spanId = assertResponseHasCustomizedHeaders(response, SUCCESS, traceId)
49+
assertTheTraces(1, traceId, parentId, spanId, "POST", SUCCESS)
50+
}
3551
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55

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

8+
import io.opentelemetry.context.Context
9+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
10+
import io.opentelemetry.instrumentation.testing.junit.http.{AbstractHttpServerTest, ServerEndpoint}
811
import org.apache.pekko.actor.ActorSystem
912
import org.apache.pekko.http.scaladsl.Http
1013
import org.apache.pekko.http.scaladsl.Http.ServerBinding
11-
import org.apache.pekko.http.scaladsl.model.HttpMethods.GET
14+
import org.apache.pekko.http.scaladsl.model.HttpMethods.{GET, POST}
15+
import org.apache.pekko.http.scaladsl.model.StatusCodes.OK
1216
import org.apache.pekko.http.scaladsl.model._
17+
import org.apache.pekko.pattern.after
1318
import org.apache.pekko.stream.ActorMaterializer
14-
import io.opentelemetry.instrumentation.testing.junit.http.{
15-
AbstractHttpServerTest,
16-
ServerEndpoint
17-
}
18-
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
1919

2020
import java.util.function.Supplier
21+
import scala.concurrent.duration.DurationInt
2122
import scala.concurrent.{Await, ExecutionContextExecutor, Future}
2223

2324
object PekkoHttpTestAsyncWebServer {
@@ -57,6 +58,17 @@ object PekkoHttpTestAsyncWebServer {
5758
}
5859
)
5960
}
61+
case HttpRequest(POST, uri: Uri, _, _, _) =>
62+
val endpoint = ServerEndpoint.forPath(uri.path.toString())
63+
AbstractHttpServerTest.controller(endpoint, () =>
64+
for {
65+
_ <- Future.successful(2)
66+
firstContext = Context.current()
67+
_ <- after(1.second, system.scheduler)(Future.successful(1))
68+
secondContext = Context.current()
69+
_ = assert(firstContext eq secondContext)
70+
} yield HttpResponse(status = OK, entity = endpoint.getBody)
71+
)
6072
}
6173

6274
private var binding: ServerBinding = _

0 commit comments

Comments
 (0)