Don't use HttpServerTest.controller in java tests (#12347)
This commit is contained in:
		
							parent
							
								
									f0115c6bdc
								
							
						
					
					
						commit
						7f881d07a3
					
				|  | @ -16,8 +16,8 @@ import io.opentelemetry.instrumentation.testing.junit.http.{ | ||||||
|   ServerEndpoint |   ServerEndpoint | ||||||
| } | } | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.{Await, ExecutionContextExecutor, Future} | import scala.concurrent.{Await, ExecutionContextExecutor, Future} | ||||||
| 
 | 
 | ||||||
| object AkkaHttpTestAsyncWebServer { | object AkkaHttpTestAsyncWebServer { | ||||||
|  | @ -31,7 +31,7 @@ object AkkaHttpTestAsyncWebServer { | ||||||
|         val endpoint = ServerEndpoint.forPath(uri.path.toString()) |         val endpoint = ServerEndpoint.forPath(uri.path.toString()) | ||||||
|         AbstractHttpServerTest.controller( |         AbstractHttpServerTest.controller( | ||||||
|           endpoint, |           endpoint, | ||||||
|           new Supplier[HttpResponse] { |           new ThrowingSupplier[HttpResponse, Exception] { | ||||||
|             def get(): HttpResponse = { |             def get(): HttpResponse = { | ||||||
|               val resp = HttpResponse(status = |               val resp = HttpResponse(status = | ||||||
|                 endpoint.getStatus |                 endpoint.getStatus | ||||||
|  |  | ||||||
|  | @ -14,8 +14,8 @@ import akka.stream.ActorMaterializer | ||||||
| import akka.stream.scaladsl.Sink | import akka.stream.scaladsl.Sink | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.Await | import scala.concurrent.Await | ||||||
| 
 | 
 | ||||||
| object AkkaHttpTestServerSourceWebServer { | object AkkaHttpTestServerSourceWebServer { | ||||||
|  | @ -33,7 +33,7 @@ object AkkaHttpTestServerSourceWebServer { | ||||||
|       }, |       }, | ||||||
|       path(INDEXED_CHILD.rawPath()) { |       path(INDEXED_CHILD.rawPath()) { | ||||||
|         parameterMap { map => |         parameterMap { map => | ||||||
|           val supplier = new Supplier[String] { |           val supplier = new ThrowingSupplier[String, Exception] { | ||||||
|             def get(): String = { |             def get(): String = { | ||||||
|               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { | ||||||
|                 override def getParameter(name: String): String = |                 override def getParameter(name: String): String = | ||||||
|  | @ -114,8 +114,8 @@ object AkkaHttpTestServerSourceWebServer { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   def supplier(string: String): Supplier[String] = { |   def supplier(string: String): ThrowingSupplier[String, Exception] = { | ||||||
|     new Supplier[String] { |     new ThrowingSupplier[String, Exception] { | ||||||
|       def get(): String = { |       def get(): String = { | ||||||
|         string |         string | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -16,8 +16,8 @@ import io.opentelemetry.instrumentation.testing.junit.http.{ | ||||||
|   ServerEndpoint |   ServerEndpoint | ||||||
| } | } | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.Await | import scala.concurrent.Await | ||||||
| 
 | 
 | ||||||
| object AkkaHttpTestSyncWebServer { | object AkkaHttpTestSyncWebServer { | ||||||
|  | @ -30,7 +30,7 @@ object AkkaHttpTestSyncWebServer { | ||||||
|       val endpoint = ServerEndpoint.forPath(uri.path.toString()) |       val endpoint = ServerEndpoint.forPath(uri.path.toString()) | ||||||
|       AbstractHttpServerTest.controller( |       AbstractHttpServerTest.controller( | ||||||
|         endpoint, |         endpoint, | ||||||
|         new Supplier[HttpResponse] { |         new ThrowingSupplier[HttpResponse, Exception] { | ||||||
|           def get(): HttpResponse = { |           def get(): HttpResponse = { | ||||||
|             val resp = HttpResponse(status = endpoint.getStatus) |             val resp = HttpResponse(status = endpoint.getStatus) | ||||||
|             endpoint match { |             endpoint match { | ||||||
|  |  | ||||||
|  | @ -13,8 +13,8 @@ import akka.http.scaladsl.server.Directives._ | ||||||
| import akka.stream.ActorMaterializer | import akka.stream.ActorMaterializer | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.Await | import scala.concurrent.Await | ||||||
| 
 | 
 | ||||||
| object AkkaHttpTestWebServer { | object AkkaHttpTestWebServer { | ||||||
|  | @ -32,7 +32,7 @@ object AkkaHttpTestWebServer { | ||||||
|       }, |       }, | ||||||
|       path(INDEXED_CHILD.rawPath()) { |       path(INDEXED_CHILD.rawPath()) { | ||||||
|         parameterMap { map => |         parameterMap { map => | ||||||
|           val supplier = new Supplier[String] { |           val supplier = new ThrowingSupplier[String, Exception] { | ||||||
|             def get(): String = { |             def get(): String = { | ||||||
|               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { | ||||||
|                 override def getParameter(name: String): String = |                 override def getParameter(name: String): String = | ||||||
|  | @ -107,8 +107,8 @@ object AkkaHttpTestWebServer { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   def supplier(string: String): Supplier[String] = { |   def supplier(string: String): ThrowingSupplier[String, Exception] = { | ||||||
|     new Supplier[String] { |     new ThrowingSupplier[String, Exception] { | ||||||
|       def get(): String = { |       def get(): String = { | ||||||
|         string |         string | ||||||
|       } |       } | ||||||
|  |  | ||||||
|  | @ -5,99 +5,74 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.finatra | package io.opentelemetry.javaagent.instrumentation.finatra | ||||||
| 
 | 
 | ||||||
| import com.twitter.finagle.http.{Request, Response} | import com.twitter.finagle.http.Request | ||||||
| import com.twitter.finatra.http.Controller | import com.twitter.finatra.http.Controller | ||||||
| import com.twitter.util.Future |  | ||||||
| import groovy.lang.Closure |  | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
| 
 | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| import java.util.function.Supplier |  | ||||||
| 
 | 
 | ||||||
| class FinatraController extends Controller { | class FinatraController extends Controller { | ||||||
|   any(SUCCESS.getPath) { request: Request => |   any(SUCCESS.getPath) { request: Request => | ||||||
|     controller( |     controller(SUCCESS, supplier(() => response.ok(SUCCESS.getBody))) | ||||||
|       SUCCESS, |  | ||||||
|       new Supplier[Response] { |  | ||||||
|         override def get(): Response = { |  | ||||||
|           response.ok(SUCCESS.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(ERROR.getPath) { request: Request => |   any(ERROR.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       ERROR, |       ERROR, | ||||||
|       new Supplier[Response] { |       supplier(() => response.internalServerError(ERROR.getBody)) | ||||||
|         override def get(): Response = { |  | ||||||
|           response.internalServerError(ERROR.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(QUERY_PARAM.getPath) { request: Request => |   any(QUERY_PARAM.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       QUERY_PARAM, |       QUERY_PARAM, | ||||||
|       new Supplier[Response] { |       supplier(() => response.ok(QUERY_PARAM.getBody)) | ||||||
|         override def get(): Response = { |  | ||||||
|           response.ok(QUERY_PARAM.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(EXCEPTION.getPath) { request: Request => |   any(EXCEPTION.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       EXCEPTION, |       EXCEPTION, | ||||||
|       new Supplier[Future[Response]] { |       supplier(() => throw new Exception(EXCEPTION.getBody)) | ||||||
|         override def get(): Future[Response] = { |  | ||||||
|           throw new Exception(EXCEPTION.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(REDIRECT.getPath) { request: Request => |   any(REDIRECT.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       REDIRECT, |       REDIRECT, | ||||||
|       new Supplier[Response] { |       supplier(() => response.found.location(REDIRECT.getBody)) | ||||||
|         override def get(): Response = { |  | ||||||
|           response.found.location(REDIRECT.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(CAPTURE_HEADERS.getPath) { request: Request => |   any(CAPTURE_HEADERS.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       CAPTURE_HEADERS, |       CAPTURE_HEADERS, | ||||||
|       new Supplier[Response] { |       supplier(() => | ||||||
|         override def get(): Response = { |  | ||||||
|         response |         response | ||||||
|           .ok(CAPTURE_HEADERS.getBody) |           .ok(CAPTURE_HEADERS.getBody) | ||||||
|           .header( |           .header( | ||||||
|             "X-Test-Response", |             "X-Test-Response", | ||||||
|             request.headerMap.get("X-Test-Request").get |             request.headerMap.get("X-Test-Request").get | ||||||
|           ) |           ) | ||||||
|         } |       ) | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(INDEXED_CHILD.getPath) { request: Request => |   any(INDEXED_CHILD.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       INDEXED_CHILD, |       INDEXED_CHILD, | ||||||
|       new Supplier[Response] { |       supplier(() => { | ||||||
|         override def get(): Response = { |         INDEXED_CHILD.collectSpanAttributes((name: String) => | ||||||
|           INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |  | ||||||
|             override def getParameter(name: String): String = |  | ||||||
|           request.getParam(name) |           request.getParam(name) | ||||||
|           }) |         ) | ||||||
|         response.ok(INDEXED_CHILD.getBody) |         response.ok(INDEXED_CHILD.getBody) | ||||||
|         } |       }) | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   def supplier[A](action: () => A): ThrowingSupplier[A, Exception] = { () => | ||||||
|  |     { | ||||||
|  |       action.apply() | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,108 +5,87 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.finatra | package io.opentelemetry.javaagent.instrumentation.finatra | ||||||
| 
 | 
 | ||||||
| import com.twitter.finagle.http.{Request, Response} | import com.twitter.finagle.http.Request | ||||||
| import com.twitter.finatra.http.Controller | import com.twitter.finatra.http.Controller | ||||||
| import com.twitter.util.Future | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller | ||||||
| import groovy.lang.Closure |  | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller |  | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| 
 | 
 | ||||||
| class FinatraController extends Controller { | class FinatraController extends Controller { | ||||||
|   any(SUCCESS.getPath) { request: Request => |   any(SUCCESS.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       SUCCESS, |       SUCCESS, | ||||||
|       new Closure[Response](null) { |       supplier(() => response.ok(SUCCESS.getBody)) | ||||||
|         override def call(): Response = { |  | ||||||
|           response.ok(SUCCESS.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(ERROR.getPath) { request: Request => |   any(ERROR.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       ERROR, |       ERROR, | ||||||
|       new Closure[Response](null) { |       supplier(() => response.internalServerError(ERROR.getBody)) | ||||||
|         override def call(): Response = { |  | ||||||
|           response.internalServerError(ERROR.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(QUERY_PARAM.getPath) { request: Request => |   any(QUERY_PARAM.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       QUERY_PARAM, |       QUERY_PARAM, | ||||||
|       new Closure[Response](null) { |       supplier(() => response.ok(QUERY_PARAM.getBody)) | ||||||
|         override def call(): Response = { |  | ||||||
|           response.ok(QUERY_PARAM.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(EXCEPTION.getPath) { request: Request => |   any(EXCEPTION.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       EXCEPTION, |       EXCEPTION, | ||||||
|       new Closure[Future[Response]](null) { |       supplier(() => throw new Exception(EXCEPTION.getBody)) | ||||||
|         override def call(): Future[Response] = { |  | ||||||
|           throw new Exception(EXCEPTION.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(REDIRECT.getPath) { request: Request => |   any(REDIRECT.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       REDIRECT, |       REDIRECT, | ||||||
|       new Closure[Response](null) { |       supplier(() => response.found.location(REDIRECT.getBody)) | ||||||
|         override def call(): Response = { |  | ||||||
|           response.found.location(REDIRECT.getBody) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(CAPTURE_HEADERS.getPath) { request: Request => |   any(CAPTURE_HEADERS.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       CAPTURE_HEADERS, |       CAPTURE_HEADERS, | ||||||
|       new Closure[Response](null) { |       supplier(() => | ||||||
|         override def call(): Response = { |  | ||||||
|         response |         response | ||||||
|           .ok(CAPTURE_HEADERS.getBody) |           .ok(CAPTURE_HEADERS.getBody) | ||||||
|           .header( |           .header( | ||||||
|             "X-Test-Response", |             "X-Test-Response", | ||||||
|             request.headerMap.get("X-Test-Request").get |             request.headerMap.get("X-Test-Request").get | ||||||
|           ) |           ) | ||||||
|         } |       ) | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any(INDEXED_CHILD.getPath) { request: Request => |   any(INDEXED_CHILD.getPath) { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       INDEXED_CHILD, |       INDEXED_CHILD, | ||||||
|       new Closure[Response](null) { |       supplier(() => { | ||||||
|         override def call(): Response = { |  | ||||||
|         INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |         INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { | ||||||
|           override def getParameter(name: String): String = |           override def getParameter(name: String): String = | ||||||
|             request.getParam(name) |             request.getParam(name) | ||||||
|         }) |         }) | ||||||
|         response.ok(INDEXED_CHILD.getBody) |         response.ok(INDEXED_CHILD.getBody) | ||||||
|         } |       }) | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   any("/path/:id/param") { request: Request => |   any("/path/:id/param") { request: Request => | ||||||
|     controller( |     controller( | ||||||
|       PATH_PARAM, |       PATH_PARAM, | ||||||
|       new Closure[Response](null) { |       supplier(() => response.ok(request.params("id"))) | ||||||
|         override def call(): Response = { |  | ||||||
|           response.ok(request.params("id")) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   def supplier[A](action: () => A): ThrowingSupplier[A, Exception] = { | ||||||
|  |     new ThrowingSupplier[A, Exception] { | ||||||
|  |       def get(): A = { | ||||||
|  |         action.apply() | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,8 +7,10 @@ package test | ||||||
| 
 | 
 | ||||||
| import grails.artefact.Controller | import grails.artefact.Controller | ||||||
| import grails.web.Action | import grails.web.Action | ||||||
|  | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | ||||||
|  | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable | ||||||
| 
 | 
 | ||||||
| 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.CAPTURE_HEADERS | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR | 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.EXCEPTION | ||||||
|  | @ -82,4 +84,8 @@ class TestController implements Controller { | ||||||
|       render INDEXED_CHILD.body |       render INDEXED_CHILD.body | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   private static void controller(ServerEndpoint endpoint, ThrowingRunnable action) { | ||||||
|  |     AbstractHttpServerTest.controller(endpoint, action) | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -31,8 +31,7 @@ object PekkoHttpTestAsyncWebServer { | ||||||
|         val endpoint = ServerEndpoint.forPath(uri.path.toString()) |         val endpoint = ServerEndpoint.forPath(uri.path.toString()) | ||||||
|         AbstractHttpServerTest.controller( |         AbstractHttpServerTest.controller( | ||||||
|           endpoint, |           endpoint, | ||||||
|           new Supplier[HttpResponse] { |           () => { | ||||||
|             def get(): HttpResponse = { |  | ||||||
|             val resp = HttpResponse(status = |             val resp = HttpResponse(status = | ||||||
|               endpoint.getStatus |               endpoint.getStatus | ||||||
|             ) // .withHeaders(headers.Type)resp.contentType = "text/plain" |             ) // .withHeaders(headers.Type)resp.contentType = "text/plain" | ||||||
|  | @ -54,7 +53,6 @@ object PekkoHttpTestAsyncWebServer { | ||||||
|                   .withEntity(NOT_FOUND.getBody) |                   .withEntity(NOT_FOUND.getBody) | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|           } |  | ||||||
|         ) |         ) | ||||||
|       } |       } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0 | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| import org.apache.pekko.actor.ActorSystem | import org.apache.pekko.actor.ActorSystem | ||||||
| import org.apache.pekko.http.scaladsl.Http | import org.apache.pekko.http.scaladsl.Http | ||||||
| import org.apache.pekko.http.scaladsl.Http.ServerBinding | import org.apache.pekko.http.scaladsl.Http.ServerBinding | ||||||
|  | @ -15,7 +16,6 @@ import org.apache.pekko.http.scaladsl.server.Directives._ | ||||||
| import org.apache.pekko.stream.ActorMaterializer | import org.apache.pekko.stream.ActorMaterializer | ||||||
| import org.apache.pekko.stream.scaladsl.Sink | import org.apache.pekko.stream.scaladsl.Sink | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.Await | import scala.concurrent.Await | ||||||
| 
 | 
 | ||||||
| object PekkoHttpTestServerSourceWebServer { | object PekkoHttpTestServerSourceWebServer { | ||||||
|  | @ -33,7 +33,7 @@ object PekkoHttpTestServerSourceWebServer { | ||||||
|       }, |       }, | ||||||
|       path(INDEXED_CHILD.rawPath()) { |       path(INDEXED_CHILD.rawPath()) { | ||||||
|         parameterMap { map => |         parameterMap { map => | ||||||
|           val supplier = new Supplier[String] { |           val supplier = new ThrowingSupplier[String, Exception] { | ||||||
|             def get(): String = { |             def get(): String = { | ||||||
|               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { | ||||||
|                 override def getParameter(name: String): String = |                 override def getParameter(name: String): String = | ||||||
|  | @ -114,11 +114,9 @@ object PekkoHttpTestServerSourceWebServer { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   def supplier(string: String): Supplier[String] = { |   def supplier(string: String): ThrowingSupplier[String, Exception] = { () => | ||||||
|     new Supplier[String] { |     { | ||||||
|       def get(): String = { |  | ||||||
|       string |       string | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -30,8 +30,7 @@ object PekkoHttpTestSyncWebServer { | ||||||
|       val endpoint = ServerEndpoint.forPath(uri.path.toString()) |       val endpoint = ServerEndpoint.forPath(uri.path.toString()) | ||||||
|       AbstractHttpServerTest.controller( |       AbstractHttpServerTest.controller( | ||||||
|         endpoint, |         endpoint, | ||||||
|         new Supplier[HttpResponse] { |         () => { | ||||||
|           def get(): HttpResponse = { |  | ||||||
|           val resp = HttpResponse(status = endpoint.getStatus) |           val resp = HttpResponse(status = endpoint.getStatus) | ||||||
|           endpoint match { |           endpoint match { | ||||||
|             case SUCCESS => resp.withEntity(endpoint.getBody) |             case SUCCESS => resp.withEntity(endpoint.getBody) | ||||||
|  | @ -51,7 +50,6 @@ object PekkoHttpTestSyncWebServer { | ||||||
|                 .withEntity(NOT_FOUND.getBody) |                 .withEntity(NOT_FOUND.getBody) | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|       ) |       ) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0 | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier | ||||||
| import org.apache.pekko.actor.ActorSystem | import org.apache.pekko.actor.ActorSystem | ||||||
| import org.apache.pekko.http.scaladsl.Http | import org.apache.pekko.http.scaladsl.Http | ||||||
| import org.apache.pekko.http.scaladsl.Http.ServerBinding | import org.apache.pekko.http.scaladsl.Http.ServerBinding | ||||||
|  | @ -14,7 +15,6 @@ import org.apache.pekko.http.scaladsl.model.StatusCodes.Found | ||||||
| import org.apache.pekko.http.scaladsl.server.Directives._ | import org.apache.pekko.http.scaladsl.server.Directives._ | ||||||
| import org.apache.pekko.stream.ActorMaterializer | import org.apache.pekko.stream.ActorMaterializer | ||||||
| 
 | 
 | ||||||
| import java.util.function.Supplier |  | ||||||
| import scala.concurrent.Await | import scala.concurrent.Await | ||||||
| 
 | 
 | ||||||
| object PekkoHttpTestWebServer { | object PekkoHttpTestWebServer { | ||||||
|  | @ -32,7 +32,7 @@ object PekkoHttpTestWebServer { | ||||||
|       }, |       }, | ||||||
|       path(INDEXED_CHILD.rawPath()) { |       path(INDEXED_CHILD.rawPath()) { | ||||||
|         parameterMap { map => |         parameterMap { map => | ||||||
|           val supplier = new Supplier[String] { |           val supplier = new ThrowingSupplier[String, Exception] { | ||||||
|             def get(): String = { |             def get(): String = { | ||||||
|               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { |               INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider { | ||||||
|                 override def getParameter(name: String): String = |                 override def getParameter(name: String): String = | ||||||
|  | @ -107,11 +107,9 @@ object PekkoHttpTestWebServer { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   def supplier(string: String): Supplier[String] = { |   def supplier(string: String): ThrowingSupplier[String, Exception] = { () => | ||||||
|     new Supplier[String] { |     { | ||||||
|       def get(): String = { |  | ||||||
|       string |       string | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -93,6 +93,7 @@ class JettyServlet2Test extends AbstractHttpServerTest<Server> { | ||||||
|     options.setTestCaptureHttpHeaders(false); |     options.setTestCaptureHttpHeaders(false); | ||||||
|     options.setHasResponseSpan(e -> e.equals(REDIRECT) || e.equals(ERROR)); |     options.setHasResponseSpan(e -> e.equals(REDIRECT) || e.equals(ERROR)); | ||||||
|     options.setHasResponseCustomizer(e -> true); |     options.setHasResponseCustomizer(e -> true); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|  |  | ||||||
|  | @ -12,8 +12,9 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
|  | import java.io.IOException; | ||||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
|  | @ -24,10 +25,10 @@ public class TestServlet2 { | ||||||
| 
 | 
 | ||||||
|   public static class Sync extends HttpServlet { |   public static class Sync extends HttpServlet { | ||||||
|     @Override |     @Override | ||||||
|     protected void service(HttpServletRequest req, HttpServletResponse resp) { |     protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||||
|       req.getRequestDispatcher(null); |       req.getRequestDispatcher(null); | ||||||
|       ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); |       ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); | ||||||
|       HttpServerTest.controller( |       AbstractHttpServerTest.controller( | ||||||
|           endpoint, |           endpoint, | ||||||
|           () -> { |           () -> { | ||||||
|             resp.setContentType("text/plain"); |             resp.setContentType("text/plain"); | ||||||
|  | @ -42,7 +43,7 @@ public class TestServlet2 { | ||||||
|             } else if (ERROR.equals(endpoint)) { |             } else if (ERROR.equals(endpoint)) { | ||||||
|               resp.sendError(endpoint.getStatus(), endpoint.getBody()); |               resp.sendError(endpoint.getStatus(), endpoint.getBody()); | ||||||
|             } else if (EXCEPTION.equals(endpoint)) { |             } else if (EXCEPTION.equals(endpoint)) { | ||||||
|               throw new Exception(endpoint.getBody()); |               throw new IllegalStateException(endpoint.getBody()); | ||||||
|             } else if (INDEXED_CHILD.equals(endpoint)) { |             } else if (INDEXED_CHILD.equals(endpoint)) { | ||||||
|               INDEXED_CHILD.collectSpanAttributes(req::getParameter); |               INDEXED_CHILD.collectSpanAttributes(req::getParameter); | ||||||
|               resp.setStatus(endpoint.getStatus()); |               resp.setStatus(endpoint.getStatus()); | ||||||
|  |  | ||||||
|  | @ -69,6 +69,7 @@ public abstract class AbstractServlet3Test<SERVER, CONTEXT> extends AbstractHttp | ||||||
|     options.setTestCaptureRequestParameters(true); |     options.setTestCaptureRequestParameters(true); | ||||||
|     options.setHasResponseCustomizer(e -> true); |     options.setHasResponseCustomizer(e -> true); | ||||||
|     options.setHasResponseSpan(this::hasResponseSpan); |     options.setHasResponseSpan(this::hasResponseSpan); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   protected boolean hasResponseSpan(ServerEndpoint endpoint) { |   protected boolean hasResponseSpan(ServerEndpoint endpoint) { | ||||||
|  |  | ||||||
|  | @ -20,7 +20,6 @@ import java.io.IOException; | ||||||
| import java.io.Writer; | import java.io.Writer; | ||||||
| import java.net.InetSocketAddress; | import java.net.InetSocketAddress; | ||||||
| import javax.servlet.Servlet; | import javax.servlet.Servlet; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import org.eclipse.jetty.server.Server; | import org.eclipse.jetty.server.Server; | ||||||
| import org.eclipse.jetty.server.handler.ErrorHandler; | import org.eclipse.jetty.server.handler.ErrorHandler; | ||||||
|  | @ -47,7 +46,7 @@ public abstract class JettyServlet3Test | ||||||
|   protected void configure(HttpServerTestOptions options) { |   protected void configure(HttpServerTestOptions options) { | ||||||
|     super.configure(options); |     super.configure(options); | ||||||
|     options.setTestNotFound(false); |     options.setTestNotFound(false); | ||||||
|     options.setExpectedException(new ServletException(EXCEPTION.getBody())); |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|     options.setContextPath("/jetty-context"); |     options.setContextPath("/jetty-context"); | ||||||
|     options.setVerifyServerSpanEndTime(!isAsyncTest()); |     options.setVerifyServerSpanEndTime(!isAsyncTest()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -24,7 +24,6 @@ import java.io.Writer; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| import javax.servlet.Servlet; | import javax.servlet.Servlet; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import org.eclipse.jetty.server.Server; | import org.eclipse.jetty.server.Server; | ||||||
| import org.eclipse.jetty.server.handler.ErrorHandler; | import org.eclipse.jetty.server.handler.ErrorHandler; | ||||||
|  | @ -42,7 +41,7 @@ public class JettyServletHandlerTest extends AbstractServlet3Test<Server, Servle | ||||||
|     super.configure(options); |     super.configure(options); | ||||||
|     options.setContextPath(""); |     options.setContextPath(""); | ||||||
|     options.setTestNotFound(false); |     options.setTestNotFound(false); | ||||||
|     options.setExpectedException(new ServletException(EXCEPTION.getBody())); |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|     options.setHttpAttributes( |     options.setHttpAttributes( | ||||||
|         serverEndpoint -> { |         serverEndpoint -> { | ||||||
|           Set<AttributeKey<?>> attributes = |           Set<AttributeKey<?>> attributes = | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.servlet.v3_0.tomcat; | package io.opentelemetry.javaagent.instrumentation.servlet.v3_0.tomcat; | ||||||
| 
 | 
 | ||||||
|  | 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.CAPTURE_HEADERS; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; | ||||||
|  | @ -16,7 +17,6 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
| import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.AbstractServlet3Test.HTML_PRINT_WRITER; | import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.AbstractServlet3Test.HTML_PRINT_WRITER; | ||||||
| import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.AbstractServlet3Test.HTML_SERVLET_OUTPUT_STREAM; | import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.AbstractServlet3Test.HTML_SERVLET_OUTPUT_STREAM; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; |  | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||||
|  | @ -24,7 +24,6 @@ import java.nio.charset.StandardCharsets; | ||||||
| import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||||
| import javax.servlet.AsyncContext; | import javax.servlet.AsyncContext; | ||||||
| import javax.servlet.RequestDispatcher; | import javax.servlet.RequestDispatcher; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.annotation.WebServlet; | import javax.servlet.annotation.WebServlet; | ||||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
|  | @ -37,14 +36,14 @@ public class TestServlet3 { | ||||||
|   @WebServlet |   @WebServlet | ||||||
|   public static class Sync extends HttpServlet { |   public static class Sync extends HttpServlet { | ||||||
|     @Override |     @Override | ||||||
|     protected void service(HttpServletRequest req, HttpServletResponse resp) { |     protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||||
|       String servletPath = (String) req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); |       String servletPath = (String) req.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH); | ||||||
|       if (servletPath == null) { |       if (servletPath == null) { | ||||||
|         servletPath = req.getServletPath(); |         servletPath = req.getServletPath(); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath); |       ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath); | ||||||
|       HttpServerTest.controller( |       controller( | ||||||
|           endpoint, |           endpoint, | ||||||
|           () -> { |           () -> { | ||||||
|             resp.setContentType("text/plain"); |             resp.setContentType("text/plain"); | ||||||
|  | @ -67,7 +66,7 @@ public class TestServlet3 { | ||||||
|               req.setCharacterEncoding("UTF8"); |               req.setCharacterEncoding("UTF8"); | ||||||
|               String value = req.getParameter("test-parameter"); |               String value = req.getParameter("test-parameter"); | ||||||
|               if (!value.equals("test value õäöü")) { |               if (!value.equals("test value õäöü")) { | ||||||
|                 throw new ServletException( |                 throw new IllegalStateException( | ||||||
|                     "request parameter does not have expected value " + value); |                     "request parameter does not have expected value " + value); | ||||||
|               } |               } | ||||||
| 
 | 
 | ||||||
|  | @ -76,7 +75,7 @@ public class TestServlet3 { | ||||||
|             } else if (ERROR.equals(endpoint)) { |             } else if (ERROR.equals(endpoint)) { | ||||||
|               resp.sendError(endpoint.getStatus(), endpoint.getBody()); |               resp.sendError(endpoint.getStatus(), endpoint.getBody()); | ||||||
|             } else if (EXCEPTION.equals(endpoint)) { |             } else if (EXCEPTION.equals(endpoint)) { | ||||||
|               throw new ServletException(endpoint.getBody()); |               throw new IllegalStateException(endpoint.getBody()); | ||||||
|             } else if (HTML_PRINT_WRITER.equals(endpoint)) { |             } else if (HTML_PRINT_WRITER.equals(endpoint)) { | ||||||
|               resp.setContentType("text/html"); |               resp.setContentType("text/html"); | ||||||
|               resp.setStatus(endpoint.getStatus()); |               resp.setStatus(endpoint.getStatus()); | ||||||
|  | @ -108,7 +107,7 @@ public class TestServlet3 { | ||||||
|       context.start( |       context.start( | ||||||
|           () -> { |           () -> { | ||||||
|             try { |             try { | ||||||
|               HttpServerTest.controller( |               controller( | ||||||
|                   endpoint, |                   endpoint, | ||||||
|                   () -> { |                   () -> { | ||||||
|                     resp.setContentType("text/plain"); |                     resp.setContentType("text/plain"); | ||||||
|  | @ -136,7 +135,7 @@ public class TestServlet3 { | ||||||
|                       req.setCharacterEncoding("UTF8"); |                       req.setCharacterEncoding("UTF8"); | ||||||
|                       String value = req.getParameter("test-parameter"); |                       String value = req.getParameter("test-parameter"); | ||||||
|                       if (!value.equals("test value õäöü")) { |                       if (!value.equals("test value õäöü")) { | ||||||
|                         throw new ServletException( |                         throw new IllegalStateException( | ||||||
|                             "request parameter does not have expected value " + value); |                             "request parameter does not have expected value " + value); | ||||||
|                       } |                       } | ||||||
| 
 | 
 | ||||||
|  | @ -157,7 +156,7 @@ public class TestServlet3 { | ||||||
|                         // response is sent |                         // response is sent | ||||||
|                         writer.close(); |                         writer.close(); | ||||||
|                       } |                       } | ||||||
|                       throw new ServletException(endpoint.getBody()); |                       throw new IllegalStateException(endpoint.getBody()); | ||||||
|                     } else if (HTML_PRINT_WRITER.equals(endpoint)) { |                     } else if (HTML_PRINT_WRITER.equals(endpoint)) { | ||||||
|                       resp.setContentType("text/html"); |                       resp.setContentType("text/html"); | ||||||
|                       resp.setStatus(endpoint.getStatus()); |                       resp.setStatus(endpoint.getStatus()); | ||||||
|  | @ -172,6 +171,11 @@ public class TestServlet3 { | ||||||
|                     } |                     } | ||||||
|                     return null; |                     return null; | ||||||
|                   }); |                   }); | ||||||
|  |             } catch (Exception exception) { | ||||||
|  |               if (exception instanceof RuntimeException) { | ||||||
|  |                 throw (RuntimeException) exception; | ||||||
|  |               } | ||||||
|  |               throw new IllegalStateException(exception); | ||||||
|             } finally { |             } finally { | ||||||
|               latch.countDown(); |               latch.countDown(); | ||||||
|             } |             } | ||||||
|  | @ -187,12 +191,12 @@ public class TestServlet3 { | ||||||
|   @WebServlet(asyncSupported = true) |   @WebServlet(asyncSupported = true) | ||||||
|   public static class FakeAsync extends HttpServlet { |   public static class FakeAsync extends HttpServlet { | ||||||
|     @Override |     @Override | ||||||
|     protected void service(HttpServletRequest req, HttpServletResponse resp) { |     protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||||
|       AsyncContext context = req.startAsync(); |       AsyncContext context = req.startAsync(); | ||||||
|       try { |       try { | ||||||
|         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); |         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); | ||||||
| 
 | 
 | ||||||
|         HttpServerTest.controller( |         controller( | ||||||
|             endpoint, |             endpoint, | ||||||
|             () -> { |             () -> { | ||||||
|               resp.setContentType("text/plain"); |               resp.setContentType("text/plain"); | ||||||
|  | @ -215,7 +219,7 @@ public class TestServlet3 { | ||||||
|                 req.setCharacterEncoding("UTF8"); |                 req.setCharacterEncoding("UTF8"); | ||||||
|                 String value = req.getParameter("test-parameter"); |                 String value = req.getParameter("test-parameter"); | ||||||
|                 if (!value.equals("test value õäöü")) { |                 if (!value.equals("test value õäöü")) { | ||||||
|                   throw new ServletException( |                   throw new IllegalStateException( | ||||||
|                       "request parameter does not have expected value " + value); |                       "request parameter does not have expected value " + value); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  | @ -226,7 +230,7 @@ public class TestServlet3 { | ||||||
|               } else if (EXCEPTION.equals(endpoint)) { |               } else if (EXCEPTION.equals(endpoint)) { | ||||||
|                 resp.setStatus(endpoint.getStatus()); |                 resp.setStatus(endpoint.getStatus()); | ||||||
|                 resp.getWriter().print(endpoint.getBody()); |                 resp.getWriter().print(endpoint.getBody()); | ||||||
|                 throw new ServletException(endpoint.getBody()); |                 throw new IllegalStateException(endpoint.getBody()); | ||||||
|               } else if (HTML_PRINT_WRITER.equals(endpoint)) { |               } else if (HTML_PRINT_WRITER.equals(endpoint)) { | ||||||
|                 // intentionally testing setting status before contentType here to cover that case |                 // intentionally testing setting status before contentType here to cover that case | ||||||
|                 // somewhere |                 // somewhere | ||||||
|  |  | ||||||
|  | @ -31,7 +31,6 @@ import java.util.function.Consumer; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
| import java.util.stream.IntStream; | import java.util.stream.IntStream; | ||||||
| import javax.servlet.Servlet; | import javax.servlet.Servlet; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import org.apache.catalina.Context; | import org.apache.catalina.Context; | ||||||
| import org.apache.catalina.LifecycleException; | import org.apache.catalina.LifecycleException; | ||||||
| import org.apache.catalina.core.StandardHost; | import org.apache.catalina.core.StandardHost; | ||||||
|  | @ -63,7 +62,7 @@ public abstract class TomcatServlet3Test extends AbstractServlet3Test<Tomcat, Co | ||||||
|   @Override |   @Override | ||||||
|   protected void configure(HttpServerTestOptions options) { |   protected void configure(HttpServerTestOptions options) { | ||||||
|     super.configure(options); |     super.configure(options); | ||||||
|     options.setExpectedException(new ServletException(EXCEPTION.getBody())); |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|     options.setContextPath("/tomcat-context"); |     options.setContextPath("/tomcat-context"); | ||||||
|     options.setTestError(testError()); |     options.setTestError(testError()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -46,7 +46,7 @@ public class DelayedControllerSpringWebFluxServerTest extends ControllerSpringWe | ||||||
|     protected <T> Mono<T> wrapControllerMethod(ServerEndpoint endpoint, Supplier<T> handler) { |     protected <T> Mono<T> wrapControllerMethod(ServerEndpoint endpoint, Supplier<T> handler) { | ||||||
|       return Mono.just("") |       return Mono.just("") | ||||||
|           .delayElement(Duration.ofMillis(10)) |           .delayElement(Duration.ofMillis(10)) | ||||||
|           .map(unused -> controller(endpoint, handler)); |           .map(unused -> controller(endpoint, handler::get)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -45,7 +45,7 @@ public class ImmediateControllerSpringWebFluxServerTest extends ControllerSpring | ||||||
|     @Override |     @Override | ||||||
|     protected <T> Mono<T> wrapControllerMethod( |     protected <T> Mono<T> wrapControllerMethod( | ||||||
|         ServerEndpoint endpoint, Supplier<T> controllerMethod) { |         ServerEndpoint endpoint, Supplier<T> controllerMethod) { | ||||||
|       return Mono.just(controller(endpoint, controllerMethod)); |       return Mono.just(controller(endpoint, controllerMethod::get)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.spring.webmvc.v3_1.filter; | ||||||
| 
 | 
 | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import javax.servlet.Filter; | import javax.servlet.Filter; | ||||||
|  | @ -29,7 +29,7 @@ class ServletFilterConfig { | ||||||
|     return new Filter() { |     return new Filter() { | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|       public void init(FilterConfig filterConfig) throws ServletException {} |       public void init(FilterConfig filterConfig) {} | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||||||
|  | @ -37,45 +37,35 @@ class ServletFilterConfig { | ||||||
|         HttpServletRequest req = (HttpServletRequest) request; |         HttpServletRequest req = (HttpServletRequest) request; | ||||||
|         HttpServletResponse resp = (HttpServletResponse) response; |         HttpServletResponse resp = (HttpServletResponse) response; | ||||||
|         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); |         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); | ||||||
|         HttpServerTest.controller( |         if (endpoint != null && endpoint != ServerEndpoint.NOT_FOUND) { | ||||||
|  |           AbstractHttpServerTest.controller( | ||||||
|               endpoint, |               endpoint, | ||||||
|               () -> { |               () -> { | ||||||
|                 resp.setContentType("text/plain"); |                 resp.setContentType("text/plain"); | ||||||
|               switch (endpoint.name()) { |                 if (endpoint == ServerEndpoint.QUERY_PARAM) { | ||||||
|                 case "SUCCESS": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |  | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |  | ||||||
|                   break; |  | ||||||
|                 case "QUERY_PARAM": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |                   resp.setStatus(endpoint.getStatus()); | ||||||
|                   resp.getWriter().print(req.getQueryString()); |                   resp.getWriter().print(req.getQueryString()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.REDIRECT) { | ||||||
|                 case "PATH_PARAM": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |  | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |  | ||||||
|                   break; |  | ||||||
|                 case "REDIRECT": |  | ||||||
|                   resp.sendRedirect(endpoint.getBody()); |                   resp.sendRedirect(endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.CAPTURE_HEADERS) { | ||||||
|                 case "CAPTURE_HEADERS": |  | ||||||
|                   resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); |                   resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); | ||||||
|                   resp.setStatus(endpoint.getStatus()); |                   resp.setStatus(endpoint.getStatus()); | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.ERROR) { | ||||||
|                 case "ERROR": |  | ||||||
|                   resp.sendError(endpoint.getStatus(), endpoint.getBody()); |                   resp.sendError(endpoint.getStatus(), endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.EXCEPTION) { | ||||||
|                 case "EXCEPTION": |                   throw new IllegalStateException(endpoint.getBody()); | ||||||
|                   throw new Exception(endpoint.getBody()); |                 } else if (endpoint == ServerEndpoint.INDEXED_CHILD) { | ||||||
|                 case "INDEXED_CHILD": |  | ||||||
|                   INDEXED_CHILD.collectSpanAttributes(req::getParameter); |                   INDEXED_CHILD.collectSpanAttributes(req::getParameter); | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|                   break; |                 } else { | ||||||
|                 default: |                   resp.setStatus(endpoint.getStatus()); | ||||||
|  |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|  |                 } | ||||||
|  |               }); | ||||||
|  |         } else { | ||||||
|           chain.doFilter(request, response); |           chain.doFilter(request, response); | ||||||
|         } |         } | ||||||
|               return null; |  | ||||||
|             }); |  | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.spring.webmvc.v6_0.filter; | ||||||
| 
 | 
 | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import jakarta.servlet.Filter; | import jakarta.servlet.Filter; | ||||||
| import jakarta.servlet.FilterChain; | import jakarta.servlet.FilterChain; | ||||||
|  | @ -29,7 +29,7 @@ class ServletFilterConfig { | ||||||
|     return new Filter() { |     return new Filter() { | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|       public void init(FilterConfig filterConfig) throws ServletException {} |       public void init(FilterConfig filterConfig) {} | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||||||
|  | @ -37,45 +37,35 @@ class ServletFilterConfig { | ||||||
|         HttpServletRequest req = (HttpServletRequest) request; |         HttpServletRequest req = (HttpServletRequest) request; | ||||||
|         HttpServletResponse resp = (HttpServletResponse) response; |         HttpServletResponse resp = (HttpServletResponse) response; | ||||||
|         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); |         ServerEndpoint endpoint = ServerEndpoint.forPath(req.getServletPath()); | ||||||
|         HttpServerTest.controller( |         if (endpoint != null && endpoint != ServerEndpoint.NOT_FOUND) { | ||||||
|  |           AbstractHttpServerTest.controller( | ||||||
|               endpoint, |               endpoint, | ||||||
|               () -> { |               () -> { | ||||||
|                 resp.setContentType("text/plain"); |                 resp.setContentType("text/plain"); | ||||||
|               switch (endpoint.name()) { |                 if (endpoint == ServerEndpoint.QUERY_PARAM) { | ||||||
|                 case "SUCCESS": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |  | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |  | ||||||
|                   break; |  | ||||||
|                 case "QUERY_PARAM": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |                   resp.setStatus(endpoint.getStatus()); | ||||||
|                   resp.getWriter().print(req.getQueryString()); |                   resp.getWriter().print(req.getQueryString()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.REDIRECT) { | ||||||
|                 case "PATH_PARAM": |  | ||||||
|                   resp.setStatus(endpoint.getStatus()); |  | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |  | ||||||
|                   break; |  | ||||||
|                 case "REDIRECT": |  | ||||||
|                   resp.sendRedirect(endpoint.getBody()); |                   resp.sendRedirect(endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.CAPTURE_HEADERS) { | ||||||
|                 case "CAPTURE_HEADERS": |  | ||||||
|                   resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); |                   resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); | ||||||
|                   resp.setStatus(endpoint.getStatus()); |                   resp.setStatus(endpoint.getStatus()); | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.ERROR) { | ||||||
|                 case "ERROR": |  | ||||||
|                   resp.sendError(endpoint.getStatus(), endpoint.getBody()); |                   resp.sendError(endpoint.getStatus(), endpoint.getBody()); | ||||||
|                   break; |                 } else if (endpoint == ServerEndpoint.EXCEPTION) { | ||||||
|                 case "EXCEPTION": |                   throw new IllegalStateException(endpoint.getBody()); | ||||||
|                   throw new Exception(endpoint.getBody()); |                 } else if (endpoint == ServerEndpoint.INDEXED_CHILD) { | ||||||
|                 case "INDEXED_CHILD": |  | ||||||
|                   INDEXED_CHILD.collectSpanAttributes(req::getParameter); |                   INDEXED_CHILD.collectSpanAttributes(req::getParameter); | ||||||
|                   resp.getWriter().print(endpoint.getBody()); |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|                   break; |                 } else { | ||||||
|                 default: |                   resp.setStatus(endpoint.getStatus()); | ||||||
|  |                   resp.getWriter().print(endpoint.getBody()); | ||||||
|  |                 } | ||||||
|  |               }); | ||||||
|  |         } else { | ||||||
|           chain.doFilter(request, response); |           chain.doFilter(request, response); | ||||||
|         } |         } | ||||||
|               return null; |  | ||||||
|             }); |  | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       @Override |       @Override | ||||||
|  |  | ||||||
|  | @ -49,6 +49,7 @@ public abstract class AbstractServletFilterTest | ||||||
|     options.setHasResponseSpan( |     options.setHasResponseSpan( | ||||||
|         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); |         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); | ||||||
|     options.setTestPathParam(true); |     options.setTestPathParam(true); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|  |  | ||||||
|  | @ -5,8 +5,9 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.struts2; | package io.opentelemetry.javaagent.instrumentation.struts2; | ||||||
| 
 | 
 | ||||||
|  | import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller; | ||||||
|  | 
 | ||||||
| import com.opensymphony.xwork2.ActionSupport; | import com.opensymphony.xwork2.ActionSupport; | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; |  | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
|  | @ -17,40 +18,37 @@ public class GreetingAction extends ActionSupport { | ||||||
|   String responseBody = "default"; |   String responseBody = "default"; | ||||||
| 
 | 
 | ||||||
|   public String success() { |   public String success() { | ||||||
|     responseBody = |     responseBody = controller(ServerEndpoint.SUCCESS, ServerEndpoint.SUCCESS::getBody); | ||||||
|         HttpServerTest.controller(ServerEndpoint.SUCCESS, ServerEndpoint.SUCCESS::getBody); |  | ||||||
| 
 | 
 | ||||||
|     return "greeting"; |     return "greeting"; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public String redirect() { |   public String redirect() { | ||||||
|     responseBody = |     responseBody = controller(ServerEndpoint.REDIRECT, ServerEndpoint.REDIRECT::getBody); | ||||||
|         HttpServerTest.controller(ServerEndpoint.REDIRECT, ServerEndpoint.REDIRECT::getBody); |  | ||||||
|     return "redirect"; |     return "redirect"; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public String query_param() { |   public String query_param() { | ||||||
|     responseBody = |     responseBody = controller(ServerEndpoint.QUERY_PARAM, ServerEndpoint.QUERY_PARAM::getBody); | ||||||
|         HttpServerTest.controller(ServerEndpoint.QUERY_PARAM, ServerEndpoint.QUERY_PARAM::getBody); |  | ||||||
|     return "greeting"; |     return "greeting"; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public String error() { |   public String error() { | ||||||
|     HttpServerTest.controller(ServerEndpoint.ERROR, ServerEndpoint.ERROR::getBody); |     controller(ServerEndpoint.ERROR, ServerEndpoint.ERROR::getBody); | ||||||
|     return "error"; |     return "error"; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public String exception() { |   public String exception() { | ||||||
|     HttpServerTest.controller( |     controller( | ||||||
|         ServerEndpoint.EXCEPTION, |         ServerEndpoint.EXCEPTION, | ||||||
|         () -> { |         () -> { | ||||||
|           throw new Exception(ServerEndpoint.EXCEPTION.getBody()); |           throw new IllegalStateException(ServerEndpoint.EXCEPTION.getBody()); | ||||||
|         }); |         }); | ||||||
|     throw new AssertionError(); // should not reach here |     throw new AssertionError(); // should not reach here | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public String path_param() { |   public String path_param() { | ||||||
|     HttpServerTest.controller( |     controller( | ||||||
|         ServerEndpoint.PATH_PARAM, |         ServerEndpoint.PATH_PARAM, | ||||||
|         () -> |         () -> | ||||||
|             "this does nothing, as responseBody is set in setId, but we need this controller span nevertheless"); |             "this does nothing, as responseBody is set in setId, but we need this controller span nevertheless"); | ||||||
|  | @ -59,7 +57,7 @@ public class GreetingAction extends ActionSupport { | ||||||
| 
 | 
 | ||||||
|   public String indexed_child() { |   public String indexed_child() { | ||||||
|     responseBody = |     responseBody = | ||||||
|         HttpServerTest.controller( |         controller( | ||||||
|             ServerEndpoint.INDEXED_CHILD, |             ServerEndpoint.INDEXED_CHILD, | ||||||
|             () -> { |             () -> { | ||||||
|               ServerEndpoint.INDEXED_CHILD.collectSpanAttributes( |               ServerEndpoint.INDEXED_CHILD.collectSpanAttributes( | ||||||
|  | @ -74,8 +72,7 @@ public class GreetingAction extends ActionSupport { | ||||||
|     HttpServletResponse response = ServletActionContext.getResponse(); |     HttpServletResponse response = ServletActionContext.getResponse(); | ||||||
|     response.setHeader("X-Test-Response", request.getHeader("X-Test-Request")); |     response.setHeader("X-Test-Response", request.getHeader("X-Test-Request")); | ||||||
|     responseBody = |     responseBody = | ||||||
|         HttpServerTest.controller( |         controller(ServerEndpoint.CAPTURE_HEADERS, ServerEndpoint.CAPTURE_HEADERS::getBody); | ||||||
|             ServerEndpoint.CAPTURE_HEADERS, ServerEndpoint.CAPTURE_HEADERS::getBody); |  | ||||||
|     return "greeting"; |     return "greeting"; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ | ||||||
| package io.opentelemetry.javaagent.instrumentation.struts2; | package io.opentelemetry.javaagent.instrumentation.struts2; | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
|  | @ -14,8 +13,7 @@ import javax.servlet.http.HttpServletResponse; | ||||||
| public class GreetingServlet extends HttpServlet { | public class GreetingServlet extends HttpServlet { | ||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|   protected void doGet(HttpServletRequest req, HttpServletResponse resp) |   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||||||
|       throws ServletException, IOException { |  | ||||||
|     resp.getWriter().write("greeting"); |     resp.getWriter().write("greeting"); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -96,6 +96,7 @@ class Struts2ActionSpanTest extends AbstractHttpServerTest<Server> { | ||||||
|     options.setTestPathParam(true); |     options.setTestPathParam(true); | ||||||
|     options.setTestErrorBody(false); |     options.setTestErrorBody(false); | ||||||
|     options.setHasHandlerSpan(endpoint -> !endpoint.equals(NOT_FOUND)); |     options.setHasHandlerSpan(endpoint -> !endpoint.equals(NOT_FOUND)); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|     options.setHasResponseSpan( |     options.setHasResponseSpan( | ||||||
|         endpoint -> |         endpoint -> | ||||||
|             endpoint == REDIRECT |             endpoint == REDIRECT | ||||||
|  | @ -139,7 +140,8 @@ class Struts2ActionSpanTest extends AbstractHttpServerTest<Server> { | ||||||
|         .hasKind(SpanKind.INTERNAL); |         .hasKind(SpanKind.INTERNAL); | ||||||
| 
 | 
 | ||||||
|     if (endpoint.equals(EXCEPTION)) { |     if (endpoint.equals(EXCEPTION)) { | ||||||
|       span.hasStatus(StatusData.error()).hasException(new Exception(EXCEPTION.getBody())); |       span.hasStatus(StatusData.error()) | ||||||
|  |           .hasException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     span.hasAttributesSatisfyingExactly( |     span.hasAttributesSatisfyingExactly( | ||||||
|  |  | ||||||
|  | @ -13,14 +13,14 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import jakarta.servlet.AsyncContext; | import jakarta.servlet.AsyncContext; | ||||||
| import jakarta.servlet.ServletException; |  | ||||||
| import jakarta.servlet.annotation.WebServlet; | import jakarta.servlet.annotation.WebServlet; | ||||||
| import jakarta.servlet.http.HttpServlet; | import jakarta.servlet.http.HttpServlet; | ||||||
| import jakarta.servlet.http.HttpServletRequest; | import jakarta.servlet.http.HttpServletRequest; | ||||||
| import jakarta.servlet.http.HttpServletResponse; | import jakarta.servlet.http.HttpServletResponse; | ||||||
|  | import java.io.IOException; | ||||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||||
| import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||||
| 
 | 
 | ||||||
|  | @ -37,7 +37,7 @@ class AsyncServlet extends HttpServlet { | ||||||
|     context.start( |     context.start( | ||||||
|         () -> { |         () -> { | ||||||
|           try { |           try { | ||||||
|             HttpServerTest.controller( |             AbstractHttpServerTest.controller( | ||||||
|                 endpoint, |                 endpoint, | ||||||
|                 () -> { |                 () -> { | ||||||
|                   resp.setContentType("text/plain"); |                   resp.setContentType("text/plain"); | ||||||
|  | @ -61,10 +61,11 @@ class AsyncServlet extends HttpServlet { | ||||||
|                     PrintWriter writer = resp.getWriter(); |                     PrintWriter writer = resp.getWriter(); | ||||||
|                     writer.print(endpoint.getBody()); |                     writer.print(endpoint.getBody()); | ||||||
|                     writer.close(); |                     writer.close(); | ||||||
|                     throw new ServletException(endpoint.getBody()); |                     throw new IllegalStateException(endpoint.getBody()); | ||||||
|                   } |                   } | ||||||
|                   return null; |  | ||||||
|                 }); |                 }); | ||||||
|  |           } catch (IOException exception) { | ||||||
|  |             throw new IllegalStateException(exception); | ||||||
|           } finally { |           } finally { | ||||||
|             // complete at the end so the server span will end after the controller span |             // complete at the end so the server span will end after the controller span | ||||||
|             if (endpoint != EXCEPTION) { |             if (endpoint != EXCEPTION) { | ||||||
|  |  | ||||||
|  | @ -5,9 +5,8 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0; | package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import jakarta.servlet.ServletException; |  | ||||||
| import jakarta.servlet.http.HttpServlet; | import jakarta.servlet.http.HttpServlet; | ||||||
| import jakarta.servlet.http.HttpServletRequest; | import jakarta.servlet.http.HttpServletRequest; | ||||||
| import jakarta.servlet.http.HttpServletResponse; | import jakarta.servlet.http.HttpServletResponse; | ||||||
|  | @ -21,11 +20,11 @@ class TestServlet extends HttpServlet { | ||||||
| 
 | 
 | ||||||
|     ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); |     ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); | ||||||
|     if (serverEndpoint != null) { |     if (serverEndpoint != null) { | ||||||
|       HttpServerTest.controller( |       AbstractHttpServerTest.controller( | ||||||
|           serverEndpoint, |           serverEndpoint, | ||||||
|           () -> { |           () -> { | ||||||
|             if (serverEndpoint == ServerEndpoint.EXCEPTION) { |             if (serverEndpoint == ServerEndpoint.EXCEPTION) { | ||||||
|               throw new Exception(serverEndpoint.getBody()); |               throw new IllegalStateException(serverEndpoint.getBody()); | ||||||
|             } |             } | ||||||
|             if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { |             if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { | ||||||
|               resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); |               resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); | ||||||
|  | @ -34,7 +33,7 @@ class TestServlet extends HttpServlet { | ||||||
|               req.setCharacterEncoding("UTF8"); |               req.setCharacterEncoding("UTF8"); | ||||||
|               String value = req.getParameter("test-parameter"); |               String value = req.getParameter("test-parameter"); | ||||||
|               if (!"test value õäöü".equals(value)) { |               if (!"test value õäöü".equals(value)) { | ||||||
|                 throw new ServletException( |                 throw new IllegalStateException( | ||||||
|                     "request parameter does not have expected value " + value); |                     "request parameter does not have expected value " + value); | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -26,7 +26,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | ||||||
| import jakarta.servlet.Servlet; | import jakarta.servlet.Servlet; | ||||||
| import jakarta.servlet.ServletException; |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.nio.file.Files; | import java.nio.file.Files; | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
|  | @ -110,8 +109,7 @@ class TomcatAsyncTest extends AbstractHttpServerTest<Tomcat> { | ||||||
|           return super.expectedHttpRoute(endpoint, method); |           return super.expectedHttpRoute(endpoint, method); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|     options.setExpectedException(new ServletException(EXCEPTION.getBody())); |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
| 
 |  | ||||||
|     options.setHasResponseSpan(endpoint -> endpoint == NOT_FOUND || endpoint == REDIRECT); |     options.setHasResponseSpan(endpoint -> endpoint == NOT_FOUND || endpoint == REDIRECT); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -99,6 +99,7 @@ class TomcatHandlerTest extends AbstractHttpServerTest<Tomcat> { | ||||||
|     options.setHasResponseCustomizer(serverEndpoint -> true); |     options.setHasResponseCustomizer(serverEndpoint -> true); | ||||||
|     options.setTestCaptureRequestParameters(true); |     options.setTestCaptureRequestParameters(true); | ||||||
|     options.setTestErrorBody(false); |     options.setTestErrorBody(false); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
| 
 | 
 | ||||||
|     options.setHasResponseSpan( |     options.setHasResponseSpan( | ||||||
|         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); |         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); | ||||||
|  |  | ||||||
|  | @ -13,12 +13,11 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||||
| import java.util.concurrent.CountDownLatch; | import java.util.concurrent.CountDownLatch; | ||||||
| import javax.servlet.AsyncContext; | import javax.servlet.AsyncContext; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.annotation.WebServlet; | import javax.servlet.annotation.WebServlet; | ||||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
|  | @ -37,7 +36,7 @@ class AsyncServlet extends HttpServlet { | ||||||
|     context.start( |     context.start( | ||||||
|         () -> { |         () -> { | ||||||
|           try { |           try { | ||||||
|             HttpServerTest.controller( |             AbstractHttpServerTest.controller( | ||||||
|                 endpoint, |                 endpoint, | ||||||
|                 () -> { |                 () -> { | ||||||
|                   resp.setContentType("text/plain"); |                   resp.setContentType("text/plain"); | ||||||
|  | @ -61,10 +60,15 @@ class AsyncServlet extends HttpServlet { | ||||||
|                     PrintWriter writer = resp.getWriter(); |                     PrintWriter writer = resp.getWriter(); | ||||||
|                     writer.print(endpoint.getBody()); |                     writer.print(endpoint.getBody()); | ||||||
|                     writer.close(); |                     writer.close(); | ||||||
|                     throw new ServletException(endpoint.getBody()); |                     throw new IllegalStateException(endpoint.getBody()); | ||||||
|                   } |                   } | ||||||
|                   return null; |                   return null; | ||||||
|                 }); |                 }); | ||||||
|  |           } catch (Exception exception) { | ||||||
|  |             if (exception instanceof RuntimeException) { | ||||||
|  |               throw (RuntimeException) exception; | ||||||
|  |             } | ||||||
|  |             throw new IllegalStateException(exception); | ||||||
|           } finally { |           } finally { | ||||||
|             // complete at the end so the server span will end after the controller span |             // complete at the end so the server span will end after the controller span | ||||||
|             if (endpoint != EXCEPTION) { |             if (endpoint != EXCEPTION) { | ||||||
|  |  | ||||||
|  | @ -5,10 +5,9 @@ | ||||||
| 
 | 
 | ||||||
| package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0; | package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; | import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; | ||||||
| import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
|  | @ -21,11 +20,11 @@ class TestServlet extends HttpServlet { | ||||||
| 
 | 
 | ||||||
|     ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); |     ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); | ||||||
|     if (serverEndpoint != null) { |     if (serverEndpoint != null) { | ||||||
|       HttpServerTest.controller( |       AbstractHttpServerTest.controller( | ||||||
|           serverEndpoint, |           serverEndpoint, | ||||||
|           () -> { |           () -> { | ||||||
|             if (serverEndpoint == ServerEndpoint.EXCEPTION) { |             if (serverEndpoint == ServerEndpoint.EXCEPTION) { | ||||||
|               throw new Exception(serverEndpoint.getBody()); |               throw new IllegalStateException(serverEndpoint.getBody()); | ||||||
|             } |             } | ||||||
|             if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { |             if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { | ||||||
|               resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); |               resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); | ||||||
|  | @ -34,7 +33,7 @@ class TestServlet extends HttpServlet { | ||||||
|               req.setCharacterEncoding("UTF8"); |               req.setCharacterEncoding("UTF8"); | ||||||
|               String value = req.getParameter("test-parameter"); |               String value = req.getParameter("test-parameter"); | ||||||
|               if (!"test value õäöü".equals(value)) { |               if (!"test value õäöü".equals(value)) { | ||||||
|                 throw new ServletException( |                 throw new IllegalStateException( | ||||||
|                     "request parameter does not have expected value " + value); |                     "request parameter does not have expected value " + value); | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -28,7 +28,6 @@ import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.nio.file.Files; | import java.nio.file.Files; | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
| import javax.servlet.ServletException; |  | ||||||
| import org.apache.catalina.Context; | import org.apache.catalina.Context; | ||||||
| import org.apache.catalina.LifecycleException; | import org.apache.catalina.LifecycleException; | ||||||
| import org.apache.catalina.startup.Tomcat; | import org.apache.catalina.startup.Tomcat; | ||||||
|  | @ -105,8 +104,7 @@ class TomcatAsyncTest extends AbstractHttpServerTest<Tomcat> { | ||||||
|           return super.expectedHttpRoute(endpoint, method); |           return super.expectedHttpRoute(endpoint, method); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|     options.setExpectedException(new ServletException(EXCEPTION.getBody())); |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
| 
 |  | ||||||
|     options.setHasResponseSpan(endpoint -> endpoint == NOT_FOUND || endpoint == REDIRECT); |     options.setHasResponseSpan(endpoint -> endpoint == NOT_FOUND || endpoint == REDIRECT); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -99,6 +99,7 @@ class TomcatHandlerTest extends AbstractHttpServerTest<Tomcat> { | ||||||
|     options.setHasResponseCustomizer(serverEndpoint -> true); |     options.setHasResponseCustomizer(serverEndpoint -> true); | ||||||
|     options.setTestCaptureRequestParameters(true); |     options.setTestCaptureRequestParameters(true); | ||||||
|     options.setTestErrorBody(false); |     options.setTestErrorBody(false); | ||||||
|  |     options.setExpectedException(new IllegalStateException(EXCEPTION.getBody())); | ||||||
| 
 | 
 | ||||||
|     options.setHasResponseSpan( |     options.setHasResponseSpan( | ||||||
|         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); |         endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); | ||||||
|  |  | ||||||
|  | @ -18,6 +18,8 @@ import io.vertx.core.json.JsonObject | ||||||
| import java.util.concurrent.CompletableFuture | import java.util.concurrent.CompletableFuture | ||||||
| import java.util.concurrent.TimeUnit | import java.util.concurrent.TimeUnit | ||||||
| 
 | 
 | ||||||
|  | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION | ||||||
|  | 
 | ||||||
| abstract class AbstractVertxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTrait { | abstract class AbstractVertxHttpServerTest extends HttpServerTest<Vertx> implements AgentTestTrait { | ||||||
|   @Override |   @Override | ||||||
|   Vertx startServer(int port) { |   Vertx startServer(int port) { | ||||||
|  | @ -63,6 +65,11 @@ abstract class AbstractVertxHttpServerTest extends HttpServerTest<Vertx> impleme | ||||||
|     "/vertx-app" |     "/vertx-app" | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   @Override | ||||||
|  |   Throwable expectedException() { | ||||||
|  |     new IllegalStateException(EXCEPTION.body) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   @Override |   @Override | ||||||
|   String expectedHttpRoute(ServerEndpoint endpoint, String method) { |   String expectedHttpRoute(ServerEndpoint endpoint, String method) { | ||||||
|     if (method == HttpConstants._OTHER) { |     if (method == HttpConstants._OTHER) { | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| 
 | 
 | ||||||
| package server; | package server; | ||||||
| 
 | 
 | ||||||
|  | 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.CAPTURE_HEADERS; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; | 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.EXCEPTION; | ||||||
|  | @ -14,7 +15,6 @@ import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||||||
| import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||||||
| 
 | 
 | ||||||
| import io.opentelemetry.instrumentation.test.base.HttpServerTest; |  | ||||||
| import io.vertx.core.AbstractVerticle; | import io.vertx.core.AbstractVerticle; | ||||||
| import io.vertx.core.Handler; | import io.vertx.core.Handler; | ||||||
| import io.vertx.core.http.HttpServerResponse; | import io.vertx.core.http.HttpServerResponse; | ||||||
|  | @ -42,7 +42,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|             new Handler<RoutingContext>() { |             new Handler<RoutingContext>() { | ||||||
|               @Override |               @Override | ||||||
|               public void handle(RoutingContext ctx) { |               public void handle(RoutingContext ctx) { | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     SUCCESS, |                     SUCCESS, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end(ctx.response().setStatusCode(SUCCESS.getStatus()), SUCCESS.getBody()); |                       end(ctx.response().setStatusCode(SUCCESS.getStatus()), SUCCESS.getBody()); | ||||||
|  | @ -54,7 +54,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(INDEXED_CHILD.getPath()) |         .route(INDEXED_CHILD.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     INDEXED_CHILD, |                     INDEXED_CHILD, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       INDEXED_CHILD.collectSpanAttributes(it -> ctx.request().getParam(it)); |                       INDEXED_CHILD.collectSpanAttributes(it -> ctx.request().getParam(it)); | ||||||
|  | @ -65,7 +65,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(QUERY_PARAM.getPath()) |         .route(QUERY_PARAM.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     QUERY_PARAM, |                     QUERY_PARAM, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end( |                       end( | ||||||
|  | @ -77,7 +77,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(REDIRECT.getPath()) |         .route(REDIRECT.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     REDIRECT, |                     REDIRECT, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end( |                       end( | ||||||
|  | @ -90,7 +90,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(ERROR.getPath()) |         .route(ERROR.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     ERROR, |                     ERROR, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end(ctx.response().setStatusCode(ERROR.getStatus()), ERROR.getBody()); |                       end(ctx.response().setStatusCode(ERROR.getStatus()), ERROR.getBody()); | ||||||
|  | @ -100,16 +100,16 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(EXCEPTION.getPath()) |         .route(EXCEPTION.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     EXCEPTION, |                     EXCEPTION, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       throw new Exception(EXCEPTION.getBody()); |                       throw new IllegalStateException(EXCEPTION.getBody()); | ||||||
|                     })); |                     })); | ||||||
|     router |     router | ||||||
|         .route("/path/:id/param") |         .route("/path/:id/param") | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     PATH_PARAM, |                     PATH_PARAM, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end( |                       end( | ||||||
|  | @ -121,7 +121,7 @@ public abstract class AbstractVertxWebServer extends AbstractVerticle { | ||||||
|         .route(CAPTURE_HEADERS.getPath()) |         .route(CAPTURE_HEADERS.getPath()) | ||||||
|         .handler( |         .handler( | ||||||
|             ctx -> |             ctx -> | ||||||
|                 HttpServerTest.controller( |                 controller( | ||||||
|                     CAPTURE_HEADERS, |                     CAPTURE_HEADERS, | ||||||
|                     () -> { |                     () -> { | ||||||
|                       end( |                       end( | ||||||
|  |  | ||||||
|  | @ -29,6 +29,8 @@ import io.opentelemetry.context.propagation.TextMapPropagator; | ||||||
| import io.opentelemetry.context.propagation.TextMapSetter; | import io.opentelemetry.context.propagation.TextMapSetter; | ||||||
| import io.opentelemetry.instrumentation.api.internal.HttpConstants; | import io.opentelemetry.instrumentation.api.internal.HttpConstants; | ||||||
| import io.opentelemetry.instrumentation.testing.GlobalTraceUtil; | import io.opentelemetry.instrumentation.testing.GlobalTraceUtil; | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable; | ||||||
|  | import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier; | ||||||
| import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; | ||||||
| import io.opentelemetry.sdk.testing.assertj.TraceAssert; | import io.opentelemetry.sdk.testing.assertj.TraceAssert; | ||||||
| import io.opentelemetry.sdk.trace.data.SpanData; | import io.opentelemetry.sdk.trace.data.SpanData; | ||||||
|  | @ -75,7 +77,6 @@ import java.util.concurrent.CountDownLatch; | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
| import java.util.concurrent.atomic.AtomicReference; | import java.util.concurrent.atomic.AtomicReference; | ||||||
| import java.util.function.Consumer; | import java.util.function.Consumer; | ||||||
| import java.util.function.Supplier; |  | ||||||
| import java.util.stream.Stream; | import java.util.stream.Stream; | ||||||
| import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||||
| import org.assertj.core.api.AssertAccess; | import org.assertj.core.api.AssertAccess; | ||||||
|  | @ -115,15 +116,17 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU | ||||||
| 
 | 
 | ||||||
|   protected void configure(HttpServerTestOptions options) {} |   protected void configure(HttpServerTestOptions options) {} | ||||||
| 
 | 
 | ||||||
|   public static <T> T controller(ServerEndpoint endpoint, Supplier<T> closure) { |   public static <T, E extends Throwable> T controller( | ||||||
|  |       ServerEndpoint endpoint, ThrowingSupplier<T, E> closure) throws E { | ||||||
|     assert Span.current().getSpanContext().isValid() : "Controller should have a parent span."; |     assert Span.current().getSpanContext().isValid() : "Controller should have a parent span."; | ||||||
|     if (endpoint == NOT_FOUND) { |     if (endpoint == NOT_FOUND) { | ||||||
|       return closure.get(); |       return closure.get(); | ||||||
|     } |     } | ||||||
|     return GlobalTraceUtil.runWithSpan("controller", closure::get); |     return GlobalTraceUtil.runWithSpan("controller", closure); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public static void controller(ServerEndpoint endpoint, Runnable closure) { |   public static <E extends Throwable> void controller( | ||||||
|  |       ServerEndpoint endpoint, ThrowingRunnable<E> closure) throws E { | ||||||
|     controller( |     controller( | ||||||
|         endpoint, |         endpoint, | ||||||
|         () -> { |         () -> { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue