5
5
6
6
package org.hypertrace.agent.smoketest
7
7
8
+ import okhttp3.MediaType
9
+ import okhttp3.RequestBody
10
+
8
11
import static org.junit.Assume.assumeTrue
9
12
10
13
import io.opentelemetry.proto.trace.v1.Span
11
- import java.util.jar.Attributes
12
- import java.util.jar.JarFile
13
14
import okhttp3.Request
14
15
import org.junit.runner.RunWith
15
16
import spock.lang.Shared
@@ -56,17 +57,13 @@ abstract class AppServerTest extends SmokeTest {
56
57
57
58
String url = " http://localhost:${ target.getMappedPort(8080)} /app/greeting"
58
59
def request = new Request.Builder (). url(url). get(). build()
59
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
60
- // .IMPLEMENTATION_VERSION)
61
60
62
61
when :
63
62
def response = CLIENT . newCall(request). execute()
64
63
TraceInspector traces = new TraceInspector (waitForTraces())
65
64
Set<String > traceIds = traces. traceIds
66
65
String responseBody = response. body(). string()
67
66
68
- println traces. getSpanStream(). forEach({ span -> " ************** " + span. toString() + " *******************************" });
69
-
70
67
then : " There is one trace"
71
68
traceIds. size() == 1
72
69
@@ -93,12 +90,64 @@ abstract class AppServerTest extends SmokeTest {
93
90
[appServer, jdk] << getTestParams()
94
91
}
95
92
93
+ @Unroll
94
+ def " #appServer request response capture test smoke test on JDK #jdk" (String appServer, String jdk) {
95
+ assumeTrue(testSmoke())
96
+
97
+ String url = " http://localhost:${ target.getMappedPort(8080)} /app/echo"
98
+ MediaType JSON = MediaType . parse(" application/json; charset=utf-8" )
99
+ String requestData = " {\" greeting\" : \" Hello\" ,\" name\" : \" John\" }"
100
+ RequestBody requestBody = RequestBody . create(requestData, JSON );
101
+ def request = new Request.Builder (). url(url). post(requestBody). build();
102
+
103
+ when :
104
+ def response = CLIENT . newCall(request). execute()
105
+ TraceInspector traces = new TraceInspector (waitForTraces())
106
+ Set<String > traceIds = traces. traceIds
107
+ String headerValue = new String (Base64 . getDecoder(). decode(response. header(" Header-Dump" )));
108
+
109
+ then : " There is one trace"
110
+ traceIds. size() == 1
111
+
112
+ and : " trace id is present in the HTTP headers as reported by the called endpoint"
113
+ headerValue. contains(traceIds. find())
114
+
115
+ and : " Server spans in the distributed trace"
116
+ traces. countSpansByKind(Span.SpanKind . SPAN_KIND_SERVER ) == 2
117
+
118
+ and : " Expected span names"
119
+ traces. countSpansByName(getSpanName(' /app/echo' )) == 1
120
+ traces. countSpansByName(getSpanName(' /app/headers' )) == 1
121
+
122
+ and : " The span for the initial web request"
123
+ traces. countFilteredAttributes(" http.url" , url) == 1
124
+
125
+ and : " Client and server spans for the remote call"
126
+ traces. countFilteredAttributes(" http.url" , " http://localhost:8080/app/headers" ) == 2
127
+
128
+ and : " response body attribute should be present"
129
+ traces. countFilteredAttributes(" http.response.body" ) == 1
130
+
131
+ and : " request body attribute should be present"
132
+ traces. countFilteredAttributes(" http.request.body" ) == 1
133
+
134
+ and : " Request body should be same as sent content"
135
+ traces. getFilteredAttributeValue(" http.request.body" ) == requestData
136
+
137
+ and : " Response body should be same as sent content"
138
+ traces. getFilteredAttributeValue(" http.response.body" ) == requestData
139
+
140
+ cleanup :
141
+ response?. close()
142
+
143
+ where :
144
+ [appServer, jdk] << getTestParams()
145
+ }
146
+
96
147
@Unroll
97
148
def " #appServer test static file found on JDK #jdk" (String appServer, String jdk) {
98
149
String url = " http://localhost:${ target.getMappedPort(8080)} /app/hello.txt"
99
150
def request = new Request.Builder (). url(url). get(). build()
100
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
101
- // .IMPLEMENTATION_VERSION)
102
151
103
152
when :
104
153
def response = CLIENT . newCall(request). execute()
@@ -132,8 +181,6 @@ abstract class AppServerTest extends SmokeTest {
132
181
def " #appServer test static file not found on JDK #jdk" (String appServer, String jdk) {
133
182
String url = " http://localhost:${ target.getMappedPort(8080)} /app/file-that-does-not-exist"
134
183
def request = new Request.Builder (). url(url). get(). build()
135
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
136
- // .IMPLEMENTATION_VERSION)
137
184
138
185
when :
139
186
def response = CLIENT . newCall(request). execute()
@@ -168,8 +215,6 @@ abstract class AppServerTest extends SmokeTest {
168
215
169
216
String url = " http://localhost:${ target.getMappedPort(8080)} /app/WEB-INF/web.xml"
170
217
def request = new Request.Builder (). url(url). get(). build()
171
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
172
- // .IMPLEMENTATION_VERSION)
173
218
174
219
when :
175
220
def response = CLIENT . newCall(request). execute()
@@ -204,8 +249,6 @@ abstract class AppServerTest extends SmokeTest {
204
249
205
250
String url = " http://localhost:${ target.getMappedPort(8080)} /app/exception"
206
251
def request = new Request.Builder (). url(url). get(). build()
207
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
208
- // .IMPLEMENTATION_VERSION)
209
252
210
253
when :
211
254
def response = CLIENT . newCall(request). execute()
@@ -241,8 +284,6 @@ abstract class AppServerTest extends SmokeTest {
241
284
def " #appServer test request outside deployed application JDK #jdk" (String appServer, String jdk) {
242
285
String url = " http://localhost:${ target.getMappedPort(8080)} /this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless"
243
286
def request = new Request.Builder (). url(url). get(). build()
244
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
245
- // .IMPLEMENTATION_VERSION)
246
287
247
288
when :
248
289
def response = CLIENT . newCall(request). execute()
@@ -277,8 +318,6 @@ abstract class AppServerTest extends SmokeTest {
277
318
278
319
String url = " http://localhost:${ target.getMappedPort(8080)} /app/asyncgreeting"
279
320
def request = new Request.Builder (). url(url). get(). build()
280
- // def currentAgentVersion = new JarFile(agentPath).getManifest().getMainAttributes().get(Attributes.Name
281
- // .IMPLEMENTATION_VERSION)
282
321
283
322
when :
284
323
def response = CLIENT . newCall(request). execute()
0 commit comments