Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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}

object AkkaHttpTestAsyncWebServer {
Expand All @@ -31,7 +31,7 @@ object AkkaHttpTestAsyncWebServer {
val endpoint = ServerEndpoint.forPath(uri.path.toString())
AbstractHttpServerTest.controller(
endpoint,
new Supplier[HttpResponse] {
new ThrowingSupplier[HttpResponse, Exception] {
def get(): HttpResponse = {
val resp = HttpResponse(status =
endpoint.getStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Sink
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier

import java.util.function.Supplier
import scala.concurrent.Await

object AkkaHttpTestServerSourceWebServer {
Expand All @@ -33,7 +33,7 @@ object AkkaHttpTestServerSourceWebServer {
},
path(INDEXED_CHILD.rawPath()) {
parameterMap { map =>
val supplier = new Supplier[String] {
val supplier = new ThrowingSupplier[String, Exception] {
def get(): String = {
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
override def getParameter(name: String): String =
Expand Down Expand Up @@ -114,8 +114,8 @@ object AkkaHttpTestServerSourceWebServer {
}
}

def supplier(string: String): Supplier[String] = {
new Supplier[String] {
def supplier(string: String): ThrowingSupplier[String, Exception] = {
new ThrowingSupplier[String, Exception] {
def get(): String = {
string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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

object AkkaHttpTestSyncWebServer {
Expand All @@ -30,7 +30,7 @@ object AkkaHttpTestSyncWebServer {
val endpoint = ServerEndpoint.forPath(uri.path.toString())
AbstractHttpServerTest.controller(
endpoint,
new Supplier[HttpResponse] {
new ThrowingSupplier[HttpResponse, Exception] {
def get(): HttpResponse = {
val resp = HttpResponse(status = endpoint.getStatus)
endpoint match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier

import java.util.function.Supplier
import scala.concurrent.Await

object AkkaHttpTestWebServer {
Expand All @@ -32,7 +32,7 @@ object AkkaHttpTestWebServer {
},
path(INDEXED_CHILD.rawPath()) {
parameterMap { map =>
val supplier = new Supplier[String] {
val supplier = new ThrowingSupplier[String, Exception] {
def get(): String = {
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
override def getParameter(name: String): String =
Expand Down Expand Up @@ -107,8 +107,8 @@ object AkkaHttpTestWebServer {
}
}

def supplier(string: String): Supplier[String] = {
new Supplier[String] {
def supplier(string: String): ThrowingSupplier[String, Exception] = {
new ThrowingSupplier[String, Exception] {
def get(): String = {
string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,74 @@

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.util.Future
import groovy.lang.Closure
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._

import java.util.function.Supplier
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier

class FinatraController extends Controller {
any(SUCCESS.getPath) { request: Request =>
controller(
SUCCESS,
new Supplier[Response] {
override def get(): Response = {
response.ok(SUCCESS.getBody)
}
}
)
controller(SUCCESS, supplier(() => response.ok(SUCCESS.getBody)))
}

any(ERROR.getPath) { request: Request =>
controller(
ERROR,
new Supplier[Response] {
override def get(): Response = {
response.internalServerError(ERROR.getBody)
}
}
supplier(() => response.internalServerError(ERROR.getBody))
)
}

any(QUERY_PARAM.getPath) { request: Request =>
controller(
QUERY_PARAM,
new Supplier[Response] {
override def get(): Response = {
response.ok(QUERY_PARAM.getBody)
}
}
supplier(() => response.ok(QUERY_PARAM.getBody))
)
}

any(EXCEPTION.getPath) { request: Request =>
controller(
EXCEPTION,
new Supplier[Future[Response]] {
override def get(): Future[Response] = {
throw new Exception(EXCEPTION.getBody)
}
}
supplier(() => throw new Exception(EXCEPTION.getBody))
)
}

any(REDIRECT.getPath) { request: Request =>
controller(
REDIRECT,
new Supplier[Response] {
override def get(): Response = {
response.found.location(REDIRECT.getBody)
}
}
supplier(() => response.found.location(REDIRECT.getBody))
)
}

any(CAPTURE_HEADERS.getPath) { request: Request =>
controller(
CAPTURE_HEADERS,
new Supplier[Response] {
override def get(): Response = {
response
.ok(CAPTURE_HEADERS.getBody)
.header(
"X-Test-Response",
request.headerMap.get("X-Test-Request").get
)
}
}
supplier(() =>
response
.ok(CAPTURE_HEADERS.getBody)
.header(
"X-Test-Response",
request.headerMap.get("X-Test-Request").get
)
)
)
}

any(INDEXED_CHILD.getPath) { request: Request =>
controller(
INDEXED_CHILD,
new Supplier[Response] {
override def get(): Response = {
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
override def getParameter(name: String): String =
request.getParam(name)
})
response.ok(INDEXED_CHILD.getBody)
}
}
supplier(() => {
INDEXED_CHILD.collectSpanAttributes((name: String) =>
request.getParam(name)
)
response.ok(INDEXED_CHILD.getBody)
})
)
}

def supplier[A](action: () => A): ThrowingSupplier[A, Exception] = { () =>
{
action.apply()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,108 +5,87 @@

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.util.Future
import groovy.lang.Closure
import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.controller
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier

class FinatraController extends Controller {
any(SUCCESS.getPath) { request: Request =>
controller(
SUCCESS,
new Closure[Response](null) {
override def call(): Response = {
response.ok(SUCCESS.getBody)
}
}
supplier(() => response.ok(SUCCESS.getBody))
)
}

any(ERROR.getPath) { request: Request =>
controller(
ERROR,
new Closure[Response](null) {
override def call(): Response = {
response.internalServerError(ERROR.getBody)
}
}
supplier(() => response.internalServerError(ERROR.getBody))
)
}

any(QUERY_PARAM.getPath) { request: Request =>
controller(
QUERY_PARAM,
new Closure[Response](null) {
override def call(): Response = {
response.ok(QUERY_PARAM.getBody)
}
}
supplier(() => response.ok(QUERY_PARAM.getBody))
)
}

any(EXCEPTION.getPath) { request: Request =>
controller(
EXCEPTION,
new Closure[Future[Response]](null) {
override def call(): Future[Response] = {
throw new Exception(EXCEPTION.getBody)
}
}
supplier(() => throw new Exception(EXCEPTION.getBody))
)
}

any(REDIRECT.getPath) { request: Request =>
controller(
REDIRECT,
new Closure[Response](null) {
override def call(): Response = {
response.found.location(REDIRECT.getBody)
}
}
supplier(() => response.found.location(REDIRECT.getBody))
)
}

any(CAPTURE_HEADERS.getPath) { request: Request =>
controller(
CAPTURE_HEADERS,
new Closure[Response](null) {
override def call(): Response = {
response
.ok(CAPTURE_HEADERS.getBody)
.header(
"X-Test-Response",
request.headerMap.get("X-Test-Request").get
)
}
}
supplier(() =>
response
.ok(CAPTURE_HEADERS.getBody)
.header(
"X-Test-Response",
request.headerMap.get("X-Test-Request").get
)
)
)
}

any(INDEXED_CHILD.getPath) { request: Request =>
controller(
INDEXED_CHILD,
new Closure[Response](null) {
override def call(): Response = {
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
override def getParameter(name: String): String =
request.getParam(name)
})
response.ok(INDEXED_CHILD.getBody)
}
}
supplier(() => {
INDEXED_CHILD.collectSpanAttributes(new UrlParameterProvider {
override def getParameter(name: String): String =
request.getParam(name)
})
response.ok(INDEXED_CHILD.getBody)
})
)
}

any("/path/:id/param") { request: Request =>
controller(
PATH_PARAM,
new Closure[Response](null) {
override def call(): Response = {
response.ok(request.params("id"))
}
}
supplier(() => response.ok(request.params("id")))
)
}

def supplier[A](action: () => A): ThrowingSupplier[A, Exception] = {
new ThrowingSupplier[A, Exception] {
def get(): A = {
action.apply()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package test

import grails.artefact.Controller
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.ERROR
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION
Expand Down Expand Up @@ -82,4 +84,8 @@ class TestController implements Controller {
render INDEXED_CHILD.body
}
}

private static void controller(ServerEndpoint endpoint, ThrowingRunnable action) {
AbstractHttpServerTest.controller(endpoint, action)
}
}
Loading
Loading