Skip to content

Commit 1611c3d

Browse files
committed
chore: Re-run some tests on play 2.6 and play 2.7
1 parent 6fd4930 commit 1611c3d

File tree

5 files changed

+60
-92
lines changed

5 files changed

+60
-92
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
11
package datadog.trace.instrumentation.play26.server
22

3-
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_XML
4-
5-
import okhttp3.MediaType
6-
import okhttp3.RequestBody
7-
83
class PlayServerTest extends AbstractPlayServerTest {
9-
def 'test instrumentation gateway xml request body'() {
10-
setup:
11-
def request = request(
12-
BODY_XML, 'POST',
13-
RequestBody.create(MediaType.get('text/xml'), '<foo attr="attr_value">mytext<bar></bar></foo>'))
14-
.build()
15-
def response = client.newCall(request).execute()
16-
if (isDataStreamsEnabled()) {
17-
TEST_DATA_STREAMS_WRITER.waitForGroups(1)
18-
}
19-
String body = response.body().charStream().text
20-
21-
22-
expect:
23-
body == BODY_XML.body || body == '<?xml version="1.0" encoding="UTF-8"?><foo attr="attr_value">mytext<bar/></foo>'
24-
25-
when:
26-
TEST_WRITER.waitForTraces(1)
27-
28-
then:
29-
TEST_WRITER.get(0).any {
30-
it.getTag('request.body.converted') == '[[children:[mytext, [:]], attributes:[attr:attr_value]]]'
31-
}
32-
}
334
}
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
package datadog.trace.instrumentation.play26.server
22

3-
import spock.lang.IgnoreIf
4-
5-
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
6-
73
class PlayServerWithErrorHandlerTest extends AbstractPlayServerTest {
8-
@IgnoreIf({ !instance.testException() })
9-
def "test exception with custom status"() {
10-
setup:
11-
def request = request(CUSTOM_EXCEPTION, 'GET', null).build()
12-
def response = client.newCall(request).execute()
13-
14-
expect:
15-
response.code() == CUSTOM_EXCEPTION.status
16-
if (testExceptionBody()) {
17-
assert response.body().string() == CUSTOM_EXCEPTION.body
18-
}
19-
20-
and:
21-
assertTraces(1) {
22-
trace(spanCount(CUSTOM_EXCEPTION)) {
23-
sortSpansByStart()
24-
serverSpan(it, null, null, 'GET', CUSTOM_EXCEPTION)
25-
if (hasHandlerSpan()) {
26-
handlerSpan(it, CUSTOM_EXCEPTION)
27-
}
28-
controllerSpan(it, CUSTOM_EXCEPTION)
29-
if (hasResponseSpan(CUSTOM_EXCEPTION)) {
30-
responseSpan(it, CUSTOM_EXCEPTION)
31-
}
32-
}
33-
}
34-
}
354
}

dd-java-agent/instrumentation/play/play-2.6/src/testFixtures/groovy/datadog/trace/instrumentation/play26/server/AbstractPlayServerTest.groovy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package datadog.trace.instrumentation.play26.server
22

3+
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_XML
4+
35
import datadog.trace.agent.test.asserts.TraceAssert
46
import datadog.trace.agent.test.base.HttpServer
57
import datadog.trace.agent.test.base.HttpServerTest
@@ -8,6 +10,8 @@ import datadog.trace.api.DDTags
810
import datadog.trace.bootstrap.instrumentation.api.Tags
911
import datadog.trace.instrumentation.play26.PlayHttpServerDecorator
1012
import groovy.transform.CompileStatic
13+
import okhttp3.MediaType
14+
import okhttp3.RequestBody
1115
import play.server.Server
1216

1317
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
@@ -147,4 +151,29 @@ class AbstractPlayServerTest extends HttpServerTest<Server> {
147151
}
148152
}
149153
}
154+
155+
def 'test instrumentation gateway xml request body'() {
156+
setup:
157+
def request = request(
158+
BODY_XML, 'POST',
159+
RequestBody.create(MediaType.get('text/xml'), '<foo attr="attr_value">mytext<bar></bar></foo>'))
160+
.build()
161+
def response = client.newCall(request).execute()
162+
if (isDataStreamsEnabled()) {
163+
TEST_DATA_STREAMS_WRITER.waitForGroups(1)
164+
}
165+
String body = response.body().charStream().text
166+
167+
168+
expect:
169+
body == BODY_XML.body || body == '<?xml version="1.0" encoding="UTF-8"?><foo attr="attr_value">mytext<bar/></foo>'
170+
171+
when:
172+
TEST_WRITER.waitForTraces(1)
173+
174+
then:
175+
TEST_WRITER.get(0).any {
176+
it.getTag('request.body.converted') == '[[children:[mytext, [:]], attributes:[attr:attr_value]]]'
177+
}
178+
}
150179
}

dd-java-agent/instrumentation/play/play-2.6/src/testFixtures/groovy/datadog/trace/instrumentation/play26/server/AbstractPlayServerWithErrorHandlerTest.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package datadog.trace.instrumentation.play26.server
22

3+
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
4+
35
import datadog.trace.agent.test.base.HttpServer
6+
import spock.lang.IgnoreIf
47

58
abstract class AbstractPlayServerWithErrorHandlerTest extends AbstractPlayServerTest {
69
@Override
@@ -12,4 +15,32 @@ abstract class AbstractPlayServerWithErrorHandlerTest extends AbstractPlayServer
1215
boolean testExceptionBody() {
1316
true
1417
}
18+
19+
@IgnoreIf({ !instance.testException() })
20+
def "test exception with custom status"() {
21+
setup:
22+
def request = request(CUSTOM_EXCEPTION, 'GET', null).build()
23+
def response = client.newCall(request).execute()
24+
25+
expect:
26+
response.code() == CUSTOM_EXCEPTION.status
27+
if (testExceptionBody()) {
28+
assert response.body().string() == CUSTOM_EXCEPTION.body
29+
}
30+
31+
and:
32+
assertTraces(1) {
33+
trace(spanCount(CUSTOM_EXCEPTION)) {
34+
sortSpansByStart()
35+
serverSpan(it, null, null, 'GET', CUSTOM_EXCEPTION)
36+
if (hasHandlerSpan()) {
37+
handlerSpan(it, CUSTOM_EXCEPTION)
38+
}
39+
controllerSpan(it, CUSTOM_EXCEPTION)
40+
if (hasResponseSpan(CUSTOM_EXCEPTION)) {
41+
responseSpan(it, CUSTOM_EXCEPTION)
42+
}
43+
}
44+
}
45+
}
1546
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,4 @@
11
package datadog.trace.instrumentation.play26.server
22

3-
import spock.lang.IgnoreIf
4-
5-
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
6-
73
class PlayServerWithErrorHandlerTest extends AbstractPlayServerWithErrorHandlerTest {
8-
9-
@IgnoreIf({ !instance.testException() })
10-
def "test exception with custom status"() {
11-
setup:
12-
def request = request(CUSTOM_EXCEPTION, 'GET', null).build()
13-
def response = client.newCall(request).execute()
14-
15-
expect:
16-
response.code() == CUSTOM_EXCEPTION.status
17-
if (testExceptionBody()) {
18-
assert response.body().string() == CUSTOM_EXCEPTION.body
19-
}
20-
21-
and:
22-
assertTraces(1) {
23-
trace(spanCount(CUSTOM_EXCEPTION)) {
24-
sortSpansByStart()
25-
serverSpan(it, null, null, 'GET', CUSTOM_EXCEPTION)
26-
if (hasHandlerSpan()) {
27-
handlerSpan(it, CUSTOM_EXCEPTION)
28-
}
29-
controllerSpan(it, CUSTOM_EXCEPTION)
30-
if (hasResponseSpan(CUSTOM_EXCEPTION)) {
31-
responseSpan(it, CUSTOM_EXCEPTION)
32-
}
33-
}
34-
}
35-
}
364
}

0 commit comments

Comments
 (0)