Skip to content

Commit 978ae8e

Browse files
committed
Don't use HttpServerTest.controller in java tests
1 parent 68dbcd5 commit 978ae8e

File tree

35 files changed

+204
-211
lines changed

35 files changed

+204
-211
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import io.opentelemetry.instrumentation.testing.junit.http.{
1616
ServerEndpoint
1717
}
1818
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
19+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1920

20-
import java.util.function.Supplier
2121
import scala.concurrent.{Await, ExecutionContextExecutor, Future}
2222

2323
object AkkaHttpTestAsyncWebServer {
@@ -31,7 +31,7 @@ object AkkaHttpTestAsyncWebServer {
3131
val endpoint = ServerEndpoint.forPath(uri.path.toString())
3232
AbstractHttpServerTest.controller(
3333
endpoint,
34-
new Supplier[HttpResponse] {
34+
new ThrowingSupplier[HttpResponse, Exception] {
3535
def get(): HttpResponse = {
3636
val resp = HttpResponse(status =
3737
endpoint.getStatus

instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/akkahttp/AkkaHttpTestServerSourceWebServer.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import akka.stream.ActorMaterializer
1414
import akka.stream.scaladsl.Sink
1515
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
1616
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
17+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1718

18-
import java.util.function.Supplier
1919
import scala.concurrent.Await
2020

2121
object AkkaHttpTestServerSourceWebServer {
@@ -33,7 +33,7 @@ object AkkaHttpTestServerSourceWebServer {
3333
},
3434
path(INDEXED_CHILD.rawPath()) {
3535
parameterMap { map =>
36-
val supplier = new Supplier[String] {
36+
val supplier = new ThrowingSupplier[String, Exception] {
3737
def get(): String = {
3838
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
3939
override def getParameter(name: String): String =
@@ -114,8 +114,8 @@ object AkkaHttpTestServerSourceWebServer {
114114
}
115115
}
116116

117-
def supplier(string: String): Supplier[String] = {
118-
new Supplier[String] {
117+
def supplier(string: String): ThrowingSupplier[String, Exception] = {
118+
new ThrowingSupplier[String, Exception] {
119119
def get(): String = {
120120
string
121121
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import io.opentelemetry.instrumentation.testing.junit.http.{
1616
ServerEndpoint
1717
}
1818
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
19+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1920

20-
import java.util.function.Supplier
2121
import scala.concurrent.Await
2222

2323
object AkkaHttpTestSyncWebServer {
@@ -30,7 +30,7 @@ object AkkaHttpTestSyncWebServer {
3030
val endpoint = ServerEndpoint.forPath(uri.path.toString())
3131
AbstractHttpServerTest.controller(
3232
endpoint,
33-
new Supplier[HttpResponse] {
33+
new ThrowingSupplier[HttpResponse, Exception] {
3434
def get(): HttpResponse = {
3535
val resp = HttpResponse(status = endpoint.getStatus)
3636
endpoint match {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import akka.http.scaladsl.server.Directives._
1313
import akka.stream.ActorMaterializer
1414
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
1515
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
16+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1617

17-
import java.util.function.Supplier
1818
import scala.concurrent.Await
1919

2020
object AkkaHttpTestWebServer {
@@ -32,7 +32,7 @@ object AkkaHttpTestWebServer {
3232
},
3333
path(INDEXED_CHILD.rawPath()) {
3434
parameterMap { map =>
35-
val supplier = new Supplier[String] {
35+
val supplier = new ThrowingSupplier[String, Exception] {
3636
def get(): String = {
3737
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
3838
override def getParameter(name: String): String =
@@ -107,8 +107,8 @@ object AkkaHttpTestWebServer {
107107
}
108108
}
109109

110-
def supplier(string: String): Supplier[String] = {
111-
new Supplier[String] {
110+
def supplier(string: String): ThrowingSupplier[String, Exception] = {
111+
new ThrowingSupplier[String, Exception] {
112112
def get(): String = {
113113
string
114114
}

instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ package test
77

88
import grails.artefact.Controller
99
import grails.web.Action
10+
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
11+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
12+
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable
1013

11-
import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller
1214
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS
1315
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR
1416
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
@@ -82,4 +84,8 @@ class TestController implements Controller {
8284
render INDEXED_CHILD.body
8385
}
8486
}
87+
88+
private static void controller(ServerEndpoint endpoint, ThrowingRunnable action) {
89+
AbstractHttpServerTest.controller(endpoint, action)
90+
}
8591
}

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,26 @@ object PekkoHttpTestAsyncWebServer {
3131
val endpoint = ServerEndpoint.forPath(uri.path.toString())
3232
AbstractHttpServerTest.controller(
3333
endpoint,
34-
new Supplier[HttpResponse] {
35-
def get(): HttpResponse = {
36-
val resp = HttpResponse(status =
37-
endpoint.getStatus
38-
) // .withHeaders(headers.Type)resp.contentType = "text/plain"
39-
endpoint match {
40-
case SUCCESS => resp.withEntity(endpoint.getBody)
41-
case INDEXED_CHILD =>
42-
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
43-
override def getParameter(name: String): String =
44-
uri.query().get(name).orNull
45-
})
46-
resp.withEntity("")
47-
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
48-
case REDIRECT =>
49-
resp.withHeaders(headers.Location(endpoint.getBody))
50-
case ERROR => resp.withEntity(endpoint.getBody)
51-
case EXCEPTION => throw new Exception(endpoint.getBody)
52-
case _ =>
53-
HttpResponse(status = NOT_FOUND.getStatus)
54-
.withEntity(NOT_FOUND.getBody)
55-
}
34+
() => {
35+
val resp = HttpResponse(status =
36+
endpoint.getStatus
37+
) // .withHeaders(headers.Type)resp.contentType = "text/plain"
38+
endpoint match {
39+
case SUCCESS => resp.withEntity(endpoint.getBody)
40+
case INDEXED_CHILD =>
41+
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
42+
override def getParameter(name: String): String =
43+
uri.query().get(name).orNull
44+
})
45+
resp.withEntity("")
46+
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
47+
case REDIRECT =>
48+
resp.withHeaders(headers.Location(endpoint.getBody))
49+
case ERROR => resp.withEntity(endpoint.getBody)
50+
case EXCEPTION => throw new Exception(endpoint.getBody)
51+
case _ =>
52+
HttpResponse(status = NOT_FOUND.getStatus)
53+
.withEntity(NOT_FOUND.getBody)
5654
}
5755
}
5856
)

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

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

88
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
99
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
10+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1011
import org.apache.pekko.actor.ActorSystem
1112
import org.apache.pekko.http.scaladsl.Http
1213
import org.apache.pekko.http.scaladsl.Http.ServerBinding
@@ -15,7 +16,6 @@ import org.apache.pekko.http.scaladsl.server.Directives._
1516
import org.apache.pekko.stream.ActorMaterializer
1617
import org.apache.pekko.stream.scaladsl.Sink
1718

18-
import java.util.function.Supplier
1919
import scala.concurrent.Await
2020

2121
object PekkoHttpTestServerSourceWebServer {
@@ -33,7 +33,7 @@ object PekkoHttpTestServerSourceWebServer {
3333
},
3434
path(INDEXED_CHILD.rawPath()) {
3535
parameterMap { map =>
36-
val supplier = new Supplier[String] {
36+
val supplier = new ThrowingSupplier[String, Exception] {
3737
def get(): String = {
3838
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
3939
override def getParameter(name: String): String =
@@ -114,11 +114,9 @@ object PekkoHttpTestServerSourceWebServer {
114114
}
115115
}
116116

117-
def supplier(string: String): Supplier[String] = {
118-
new Supplier[String] {
119-
def get(): String = {
120-
string
121-
}
117+
def supplier(string: String): ThrowingSupplier[String, Exception] = { () =>
118+
{
119+
string
122120
}
123121
}
124122
}

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,24 @@ object PekkoHttpTestSyncWebServer {
3030
val endpoint = ServerEndpoint.forPath(uri.path.toString())
3131
AbstractHttpServerTest.controller(
3232
endpoint,
33-
new Supplier[HttpResponse] {
34-
def get(): HttpResponse = {
35-
val resp = HttpResponse(status = endpoint.getStatus)
36-
endpoint match {
37-
case SUCCESS => resp.withEntity(endpoint.getBody)
38-
case INDEXED_CHILD =>
39-
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
40-
override def getParameter(name: String): String =
41-
uri.query().get(name).orNull
42-
})
43-
resp.withEntity("")
44-
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
45-
case REDIRECT =>
46-
resp.withHeaders(headers.Location(endpoint.getBody))
47-
case ERROR => resp.withEntity(endpoint.getBody)
48-
case EXCEPTION => throw new Exception(endpoint.getBody)
49-
case _ =>
50-
HttpResponse(status = NOT_FOUND.getStatus)
51-
.withEntity(NOT_FOUND.getBody)
52-
}
33+
() => {
34+
val resp = HttpResponse(status = endpoint.getStatus)
35+
endpoint match {
36+
case SUCCESS => resp.withEntity(endpoint.getBody)
37+
case INDEXED_CHILD =>
38+
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
39+
override def getParameter(name: String): String =
40+
uri.query().get(name).orNull
41+
})
42+
resp.withEntity("")
43+
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
44+
case REDIRECT =>
45+
resp.withHeaders(headers.Location(endpoint.getBody))
46+
case ERROR => resp.withEntity(endpoint.getBody)
47+
case EXCEPTION => throw new Exception(endpoint.getBody)
48+
case _ =>
49+
HttpResponse(status = NOT_FOUND.getStatus)
50+
.withEntity(NOT_FOUND.getBody)
5351
}
5452
}
5553
)

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

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

88
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
99
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
10+
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier
1011
import org.apache.pekko.actor.ActorSystem
1112
import org.apache.pekko.http.scaladsl.Http
1213
import org.apache.pekko.http.scaladsl.Http.ServerBinding
1314
import org.apache.pekko.http.scaladsl.model.StatusCodes.Found
1415
import org.apache.pekko.http.scaladsl.server.Directives._
1516
import org.apache.pekko.stream.ActorMaterializer
1617

17-
import java.util.function.Supplier
1818
import scala.concurrent.Await
1919

2020
object PekkoHttpTestWebServer {
@@ -32,7 +32,7 @@ object PekkoHttpTestWebServer {
3232
},
3333
path(INDEXED_CHILD.rawPath()) {
3434
parameterMap { map =>
35-
val supplier = new Supplier[String] {
35+
val supplier = new ThrowingSupplier[String, Exception] {
3636
def get(): String = {
3737
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
3838
override def getParameter(name: String): String =
@@ -107,11 +107,9 @@ object PekkoHttpTestWebServer {
107107
}
108108
}
109109

110-
def supplier(string: String): Supplier[String] = {
111-
new Supplier[String] {
112-
def get(): String = {
113-
string
114-
}
110+
def supplier(string: String): ThrowingSupplier[String, Exception] = { () =>
111+
{
112+
string
115113
}
116114
}
117115
}

instrumentation/servlet/servlet-2.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/JettyServlet2Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected void configure(HttpServerTestOptions options) {
9393
options.setTestCaptureHttpHeaders(false);
9494
options.setHasResponseSpan(e -> e.equals(REDIRECT) || e.equals(ERROR));
9595
options.setHasResponseCustomizer(e -> true);
96+
options.setExpectedException(new IllegalStateException(EXCEPTION.getBody()));
9697
}
9798

9899
@Override

0 commit comments

Comments
 (0)