Skip to content

Commit

Permalink
Migrate remaining test client calls to Armeria and remove testing-com… (
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuraag Agrawal authored Jun 11, 2021
1 parent 4c6cfb5 commit 84cc044
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 539 deletions.
11 changes: 0 additions & 11 deletions instrumentation/gwt-2.0/javaagent/src/test/groovy/GwtTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import io.opentelemetry.instrumentation.test.asserts.TraceAssert
import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import java.util.concurrent.TimeUnit
import okhttp3.HttpUrl
import okhttp3.Request
import okhttp3.RequestBody
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.util.resource.Resource
import org.eclipse.jetty.webapp.WebAppContext
Expand Down Expand Up @@ -168,12 +165,4 @@ class GwtTest extends AgentInstrumentationSpecification implements HttpServerTes
kind SpanKind.SERVER
}
}

Request.Builder request(HttpUrl url, String method, RequestBody body) {
return new Request.Builder()
.url(url)
.method(method, body)
.header("User-Agent", TEST_USER_AGENT)
.header("X-Forwarded-For", TEST_CLIENT_IP)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import static Resource.Test3

import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait
import io.opentelemetry.testing.armeria.common.AggregatedHttpResponse
import okhttp3.HttpUrl
import okhttp3.Request
import okhttp3.RequestBody
import org.apache.cxf.endpoint.Server
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean

Expand Down Expand Up @@ -45,12 +42,6 @@ class CxfFilterTest extends JaxRsFilterTest implements HttpServerTestTrait<Serve
httpServer.stop()
}

Request.Builder request(HttpUrl url, String method, RequestBody body) {
return new Request.Builder()
.url(url)
.method(method, body)
}

@Override
def makeRequest(String path) {
AggregatedHttpResponse response = client.post(address.resolve(path).toString(), "").aggregate().join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import static io.opentelemetry.api.trace.SpanKind.SERVER
import static io.opentelemetry.api.trace.StatusCode.ERROR

import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.OkHttpUtils
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import io.opentelemetry.testing.armeria.client.WebClient
import io.opentelemetry.testing.armeria.common.AggregatedHttpResponse
import io.opentelemetry.testing.armeria.common.HttpMethod
import io.opentelemetry.testing.armeria.common.MediaType
import io.opentelemetry.testing.armeria.common.RequestHeaders
import java.nio.file.Files
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import org.apache.catalina.Context
import org.apache.catalina.startup.Tomcat
import org.apache.jasper.JasperException
Expand All @@ -39,7 +38,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
@Shared
String baseUrl

OkHttpClient client = OkHttpUtils.client()
@Shared
WebClient client

def setupSpec() {
baseDir = Files.createTempDirectory("jsp").toFile()
Expand All @@ -58,6 +58,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
// https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed
tomcatServer.getConnector()
baseUrl = "http://localhost:$port/$jspWebappContext"
client = WebClient.of(baseUrl)

appContext = tomcatServer.addWebapp("/$jspWebappContext",
JspInstrumentationBasicTests.getResource("/webapps/jsptest").getPath())
Expand All @@ -74,12 +75,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {

@Unroll
def "non-erroneous GET #test test"() {
setup:
String reqUrl = baseUrl + "/$jspFileName"
def req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/${jspFileName}").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -111,15 +108,12 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(0)
name "Render /$jspFileName"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/${jspFileName}"
}
}
}
}
res.code() == 200

cleanup:
res.close()
res.status().code() == 200

where:
test | jspFileName | jspClassName | jspClassNamePrefix
Expand All @@ -131,11 +125,9 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
def "non-erroneous GET with query string"() {
setup:
String queryString = "HELLO"
String reqUrl = baseUrl + "/getQuery.jsp"
Request req = new Request.Builder().url(new URL(reqUrl + "?" + queryString)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/getQuery.jsp?${queryString}").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -167,28 +159,22 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(0)
name "Render /getQuery.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/getQuery.jsp"
}
}
}
}
res.code() == 200

cleanup:
res.close()
res.status().code() == 200
}

def "non-erroneous POST"() {
setup:
String reqUrl = baseUrl + "/post.jsp"
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("name", "world")
RequestHeaders headers = RequestHeaders.builder(HttpMethod.POST, "/post.jsp")
.contentType(MediaType.FORM_DATA)
.build()
Request req = new Request.Builder().url(new URL(reqUrl)).post(requestBody).build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.execute(headers, "name=world").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -220,25 +206,18 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(0)
name "Render /post.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/post.jsp"
}
}
}
}
res.code() == 200

cleanup:
res.close()
res.status().code() == 200
}

@Unroll
def "erroneous runtime errors GET jsp with #test test"() {
setup:
String reqUrl = baseUrl + "/$jspFileName"
def req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/${jspFileName}").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -296,15 +275,12 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
}
}
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/${jspFileName}"
}
}
}
}
res.code() == 500

cleanup:
res.close()
res.status().code() == 500

where:
test | jspFileName | jspClassName | exceptionClass | errorMessageOptional
Expand All @@ -314,12 +290,8 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
}

def "non-erroneous include plain HTML GET"() {
setup:
String reqUrl = baseUrl + "/includes/includeHtml.jsp"
Request req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/includes/includeHtml.jsp").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -351,24 +323,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(0)
name "Render /includes/includeHtml.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/includes/includeHtml.jsp"
}
}
}
}
res.code() == 200

cleanup:
res.close()
res.status().code() == 200
}

def "non-erroneous multi GET"() {
setup:
String reqUrl = baseUrl + "/includes/includeMulti.jsp"
Request req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/includes/includeMulti.jsp").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -400,7 +365,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(0)
name "Render /includes/includeMulti.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/includes/includeMulti.jsp"
}
}
span(3) {
Expand All @@ -415,7 +380,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(2)
name "Render /common/javaLoopH2.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/includes/includeMulti.jsp"
}
}
span(5) {
Expand All @@ -430,24 +395,17 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
childOf span(2)
name "Render /common/javaLoopH2.jsp"
attributes {
"jsp.requestURL" reqUrl
"jsp.requestURL" "${baseUrl}/includes/includeMulti.jsp"
}
}
}
}
res.code() == 200

cleanup:
res.close()
res.status().code() == 200
}

def "#test compile error should not produce render traces and spans"() {
setup:
String reqUrl = baseUrl + "/$jspFileName"
Request req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/${jspFileName}").aggregate().join()

then:
assertTraces(1) {
Expand Down Expand Up @@ -481,10 +439,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
}
}
}
res.code() == 500

cleanup:
res.close()
res.status().code() == 500

where:
test | jspFileName | jspClassName | jspClassNamePrefix
Expand All @@ -493,15 +448,11 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
}

def "direct static file reference"() {
setup:
String reqUrl = baseUrl + "/$staticFile"
def req = new Request.Builder().url(new URL(reqUrl)).get().build()

when:
Response res = client.newCall(req).execute()
AggregatedHttpResponse res = client.get("/${staticFile}").aggregate().join()

then:
res.code() == 200
res.status().code() == 200
assertTraces(1) {
trace(0, 1) {
span(0) {
Expand All @@ -522,9 +473,6 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
}
}

cleanup:
res.close()

where:
staticFile = "common/hello.html"
}
Expand Down
Loading

0 comments on commit 84cc044

Please sign in to comment.