소스 검색

Test latest version of akka-http (#5945)

* Test latest version of akka-http

* checkstyle

* spotless
Lauri Tulmin 2 년 전
부모
커밋
a45ee01259
10개의 변경된 파일62개의 추가작업 그리고 41개의 파일을 삭제
  1. 15 0
      instrumentation/akka/akka-http-10.0/javaagent/build.gradle.kts
  2. 1 1
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AbstractHttpServerInstrumentationTest.scala
  3. 1 1
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpClientInstrumentationTest.scala
  4. 1 1
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpServerInstrumentationTestAsync.scala
  5. 13 5
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpServerInstrumentationTestSync.scala
  6. 9 7
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestAsyncWebServer.scala
  7. 9 7
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestSyncWebServer.scala
  8. 1 1
      instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestWebServer.scala
  9. 2 18
      instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy
  10. 10 0
      testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java

+ 15 - 0
instrumentation/akka/akka-http-10.0/javaagent/build.gradle.kts

@@ -50,10 +50,25 @@ dependencies {
   // they are here to test for context leaks
   testInstrumentation(project(":instrumentation:akka:akka-actor-2.5:javaagent"))
   testInstrumentation(project(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent"))
+
+  latestDepTestLibrary("com.typesafe.akka:akka-http_2.13:+")
+  latestDepTestLibrary("com.typesafe.akka:akka-stream_2.13:+")
 }
 
 tasks.withType<Test>().configureEach {
   // required on jdk17
   jvmArgs("--add-exports=java.base/sun.security.util=ALL-UNNAMED")
   jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
+
+  systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
+}
+
+if (findProperty("testLatestDeps") as Boolean) {
+  configurations {
+    // akka artifact name is different for regular and latest tests
+    testImplementation {
+      exclude("com.typesafe.akka", "akka-http_2.11")
+      exclude("com.typesafe.akka", "akka-stream_2.11")
+    }
+  }
 }

+ 1 - 1
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AbstractHttpServerInstrumentationTest.scala

@@ -21,7 +21,7 @@ import java.util.function.Function
 abstract class AbstractHttpServerInstrumentationTest
     extends AbstractHttpServerTest[Object] {
 
-  override final protected def configure(
+  override protected def configure(
       options: HttpServerTestOptions
   ): Unit = {
     options.setTestCaptureHttpHeaders(false)

+ 1 - 1
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpClientInstrumentationTest.scala

@@ -36,7 +36,7 @@ import scala.util.{Failure, Success}
 class AkkaHttpClientInstrumentationTest
     extends AbstractHttpClientTest[HttpRequest] {
 
-  @RegisterExtension val _: InstrumentationExtension =
+  @RegisterExtension val extension: InstrumentationExtension =
     HttpClientInstrumentationExtension.forAgent()
 
   val system: ActorSystem = ActorSystem.create()

+ 1 - 1
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpServerInstrumentationTestAsync.scala

@@ -12,7 +12,7 @@ import org.junit.jupiter.api.extension.RegisterExtension
 class AkkaHttpServerInstrumentationTestAsync
     extends AbstractHttpServerInstrumentationTest {
 
-  @RegisterExtension val _: InstrumentationExtension =
+  @RegisterExtension val extension: InstrumentationExtension =
     HttpServerInstrumentationExtension.forAgent()
 
   override protected def setupServer(): AnyRef = {

+ 13 - 5
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpServerInstrumentationTestSync.scala

@@ -5,17 +5,17 @@
 
 package io.opentelemetry.javaagent.instrumentation.akkahttp
 
-import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension
-import io.opentelemetry.instrumentation.testing.junit.{
-  AgentInstrumentationExtension,
-  InstrumentationExtension
+import io.opentelemetry.instrumentation.testing.junit.http.{
+  HttpServerInstrumentationExtension,
+  HttpServerTestOptions
 }
+import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension
 import org.junit.jupiter.api.extension.RegisterExtension
 
 class AkkaHttpServerInstrumentationTestSync
     extends AbstractHttpServerInstrumentationTest {
 
-  @RegisterExtension val _: InstrumentationExtension =
+  @RegisterExtension val extension: InstrumentationExtension =
     HttpServerInstrumentationExtension.forAgent()
 
   override protected def setupServer(): AnyRef = {
@@ -25,4 +25,12 @@ class AkkaHttpServerInstrumentationTestSync
 
   override protected def stopServer(server: Object): Unit =
     AkkaHttpTestSyncWebServer.stop()
+
+  override protected def configure(
+      options: HttpServerTestOptions
+  ): Unit = {
+    super.configure(options)
+    // FIXME: latest deps does not fill http.status_code
+    options.setTestException(!java.lang.Boolean.getBoolean("testLatestDeps"))
+  }
 }

+ 9 - 7
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestAsyncWebServer.scala

@@ -11,11 +11,13 @@ import akka.http.scaladsl.Http.ServerBinding
 import akka.http.scaladsl.model.HttpMethods.GET
 import akka.http.scaladsl.model._
 import akka.stream.ActorMaterializer
-import groovy.lang.Closure
-import io.opentelemetry.instrumentation.test.base.HttpServerTest
-import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
+import io.opentelemetry.instrumentation.testing.junit.http.{
+  AbstractHttpServerTest,
+  ServerEndpoint
+}
 import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
 
+import java.util.function.Supplier
 import scala.concurrent.{Await, ExecutionContextExecutor, Future}
 
 object AkkaHttpTestAsyncWebServer {
@@ -27,10 +29,10 @@ object AkkaHttpTestAsyncWebServer {
     case HttpRequest(GET, uri: Uri, _, _, _) =>
       Future {
         val endpoint = ServerEndpoint.forPath(uri.path.toString())
-        HttpServerTest.controller(
+        AbstractHttpServerTest.controller(
           endpoint,
-          new Closure[HttpResponse](()) {
-            def doCall(): HttpResponse = {
+          new Supplier[HttpResponse] {
+            def get(): HttpResponse = {
               val resp = HttpResponse(status =
                 endpoint.getStatus
               ) // .withHeaders(headers.Type)resp.contentType = "text/plain"
@@ -64,7 +66,7 @@ object AkkaHttpTestAsyncWebServer {
       import scala.concurrent.duration._
       binding = Await.result(
         Http().bindAndHandleAsync(asyncHandler, "localhost", port),
-        10 seconds
+        10.seconds
       )
     }
   }

+ 9 - 7
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestSyncWebServer.scala

@@ -11,11 +11,13 @@ import akka.http.scaladsl.Http.ServerBinding
 import akka.http.scaladsl.model.HttpMethods.GET
 import akka.http.scaladsl.model._
 import akka.stream.ActorMaterializer
-import groovy.lang.Closure
-import io.opentelemetry.instrumentation.test.base.HttpServerTest
-import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
+import io.opentelemetry.instrumentation.testing.junit.http.{
+  AbstractHttpServerTest,
+  ServerEndpoint
+}
 import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
 
+import java.util.function.Supplier
 import scala.concurrent.Await
 
 object AkkaHttpTestSyncWebServer {
@@ -26,10 +28,10 @@ object AkkaHttpTestSyncWebServer {
   val syncHandler: HttpRequest => HttpResponse = {
     case HttpRequest(GET, uri: Uri, _, _, _) => {
       val endpoint = ServerEndpoint.forPath(uri.path.toString())
-      HttpServerTest.controller(
+      AbstractHttpServerTest.controller(
         endpoint,
-        new Closure[HttpResponse](()) {
-          def doCall(): HttpResponse = {
+        new Supplier[HttpResponse] {
+          def get(): HttpResponse = {
             val resp = HttpResponse(status = endpoint.getStatus)
             endpoint match {
               case SUCCESS => resp.withEntity(endpoint.getBody)
@@ -61,7 +63,7 @@ object AkkaHttpTestSyncWebServer {
       import scala.concurrent.duration._
       binding = Await.result(
         Http().bindAndHandleSync(syncHandler, "localhost", port),
-        10 seconds
+        10.seconds
       )
     }
   }

+ 1 - 1
instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestWebServer.scala

@@ -53,7 +53,7 @@ object AkkaHttpTestWebServer {
     if (null == binding) {
       import scala.concurrent.duration._
       binding =
-        Await.result(Http().bindAndHandle(route, "localhost", port), 10 seconds)
+        Await.result(Http().bindAndHandle(route, "localhost", port), 10.seconds)
     }
   }
 

+ 2 - 18
instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy

@@ -7,16 +7,12 @@ package test
 
 import grails.artefact.Controller
 import grails.web.Action
-import io.opentelemetry.api.trace.Span
-import io.opentelemetry.instrumentation.testing.GlobalTraceUtil
-import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
-import java.util.concurrent.Callable
 
+import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD
-import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM
 import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT
@@ -86,16 +82,4 @@ class TestController implements Controller {
       render INDEXED_CHILD.body
     }
   }
-
-  // copied from HttpServerTest
-  // groovy classes in testing-common are compiled with a different groovy version, we don't want
-  // to use them here
-  static <T> T controller(ServerEndpoint endpoint, Callable<T> closure) {
-    assert Span.current().getSpanContext().isValid(): "Controller should have a parent span."
-    if (endpoint == NOT_FOUND) {
-      return closure.call()
-    }
-    return GlobalTraceUtil.runWithSpan("controller") {
-      closure.call()
-    }
-  }}
+}

+ 10 - 0
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java

@@ -25,6 +25,7 @@ import io.opentelemetry.api.trace.SpanKind;
 import io.opentelemetry.context.Context;
 import io.opentelemetry.context.propagation.TextMapPropagator;
 import io.opentelemetry.context.propagation.TextMapSetter;
+import io.opentelemetry.instrumentation.testing.GlobalTraceUtil;
 import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner;
 import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
 import io.opentelemetry.sdk.testing.assertj.TraceAssert;
@@ -48,6 +49,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.function.Consumer;
+import java.util.function.Supplier;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
@@ -135,6 +137,14 @@ public abstract class AbstractHttpServerTest<SERVER> {
     }
   }
 
+  public static <T> T controller(ServerEndpoint endpoint, Supplier<T> closure) {
+    assert Span.current().getSpanContext().isValid() : "Controller should have a parent span.";
+    if (endpoint == NOT_FOUND) {
+      return closure.get();
+    }
+    return GlobalTraceUtil.runWithSpan("controller", () -> closure.get());
+  }
+
   String resolveAddress(ServerEndpoint uri) {
     String url = uri.resolvePath(address).toString();
     // Force HTTP/1 via h1c so upgrade requests don't show up as traces