Skip to content

Commit e9095b5

Browse files
committed
Clean up
1 parent 150ab05 commit e9095b5

6 files changed

Lines changed: 53 additions & 50 deletions

File tree

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/buffer/InjectingPipeOutputStreamTest.groovy

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class InjectingPipeOutputStreamTest extends DDSpecification {
112112
piped.close()
113113

114114
then:
115-
counter.value == 12
115+
counter.value == testBytes.length
116116
downstream.toByteArray() == testBytes
117117
}
118118

@@ -130,29 +130,26 @@ class InjectingPipeOutputStreamTest extends DDSpecification {
130130
piped.close()
131131

132132
then:
133-
counter.value == 4
133+
counter.value == testBytes.length
134134
downstream.toByteArray() == testBytes
135135
}
136136

137137
def 'should count bytes correctly with multiple writes'() {
138138
setup:
139-
def part1 = "test".getBytes("UTF-8")
140-
def part2 = " ".getBytes("UTF-8")
141-
def part3 = "content".getBytes("UTF-8")
142-
def testBytes = "test content".getBytes("UTF-8")
139+
def testBytes = "test content"
143140
def downstream = new ByteArrayOutputStream()
144141
def counter = new Counter()
145142
def piped = new InjectingPipeOutputStream(downstream, MARKER_BYTES, CONTEXT_BYTES, null, { long bytes -> counter.incr(bytes) }, null)
146143

147144
when:
148-
piped.write(part1)
149-
piped.write(part2)
150-
piped.write(part3)
145+
piped.write(testBytes[0..4].getBytes("UTF-8"))
146+
piped.write(testBytes[5..5].getBytes("UTF-8"))
147+
piped.write(testBytes[6..-1].getBytes("UTF-8"))
151148
piped.close()
152149

153150
then:
154-
counter.value == 12
155-
downstream.toByteArray() == testBytes
151+
counter.value == testBytes.length()
152+
downstream.toByteArray() == testBytes.getBytes("UTF-8")
156153
}
157154

158155
def 'should be resilient to exceptions when onBytesWritten callback is null'() {

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/buffer/InjectingPipeWriterTest.groovy

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,63 +121,66 @@ class InjectingPipeWriterTest extends DDSpecification {
121121
def downstream = new StringWriter()
122122
def counter = new Counter()
123123
def piped = new InjectingPipeWriter(downstream, MARKER_CHARS, CONTEXT_CHARS, null, { long bytes -> counter.incr(bytes) }, null)
124+
def testBytes = "test content"
124125

125126
when:
126-
piped.write("test content".toCharArray())
127+
piped.write(testBytes.toCharArray())
127128
piped.close()
128129

129130
then:
130-
counter.value == 12
131-
downstream.toString() == "test content"
131+
counter.value == testBytes.length()
132+
downstream.toString() == testBytes
132133
}
133134

134135
def 'should count bytes correctly when writing characters individually'() {
135136
setup:
136137
def downstream = new StringWriter()
137138
def counter = new Counter()
138139
def piped = new InjectingPipeWriter(downstream, MARKER_CHARS, CONTEXT_CHARS, null, { long bytes -> counter.incr(bytes) }, null)
140+
def testBytes = "test"
139141

140142
when:
141-
def content = "test"
142-
for (int i = 0; i < content.length(); i++) {
143-
piped.write((int) content.charAt(i))
143+
for (int i = 0; i < testBytes.length(); i++) {
144+
piped.write((int) testBytes.charAt(i))
144145
}
145146
piped.close()
146147

147148
then:
148-
counter.value == 4
149-
downstream.toString() == "test"
149+
counter.value == testBytes.length()
150+
downstream.toString() == testBytes
150151
}
151152

152153
def 'should count bytes correctly with multiple writes'() {
153154
setup:
154155
def downstream = new StringWriter()
155156
def counter = new Counter()
156157
def piped = new InjectingPipeWriter(downstream, MARKER_CHARS, CONTEXT_CHARS, null, { long bytes -> counter.incr(bytes) }, null)
158+
def testBytes = "test content"
157159

158160
when:
159-
piped.write("test".toCharArray())
160-
piped.write(" ".toCharArray())
161-
piped.write("content".toCharArray())
161+
piped.write(testBytes[0..4].toCharArray())
162+
piped.write(testBytes[5..5].toCharArray())
163+
piped.write(testBytes[6..-1].toCharArray())
162164
piped.close()
163165

164166
then:
165-
counter.value == 12
166-
downstream.toString() == "test content"
167+
counter.value == testBytes.length()
168+
downstream.toString() == testBytes
167169
}
168170

169171
def 'should be resilient to exceptions when onBytesWritten callback is null'() {
170172
setup:
171173
def downstream = new StringWriter()
172174
def piped = new InjectingPipeWriter(downstream, MARKER_CHARS, CONTEXT_CHARS)
175+
def testBytes = "test content"
173176

174177
when:
175-
piped.write("test content".toCharArray())
178+
piped.write(testBytes.toCharArray())
176179
piped.close()
177180

178181
then:
179182
noExceptionThrown()
180-
downstream.toString() == "test content"
183+
downstream.toString() == testBytes
181184
}
182185

183186
def 'should call timing callback when injection happens'() {

dd-java-agent/instrumentation/servlet/request-3/src/test/groovy/RumHttpServletResponseWrapperTest.groovy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
2525

2626
void setup() {
2727
mockRequest.getServletContext() >> mockServletContext
28-
mockServletContext.getEffectiveMajorVersion() >> 3
28+
mockServletContext.getEffectiveMajorVersion() >> Integer.parseInt(SERVLET_VERSION)
2929
wrapper = new RumHttpServletResponseWrapper(mockRequest, mockResponse)
3030
RumInjector.setTelemetryCollector(mockTelemetryCollector)
3131
}
@@ -172,14 +172,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
172172
}
173173
def wrappedStream = new WrappedServletOutputStream(
174174
downstream, marker, contentToInject, null, onBytesWritten, null)
175+
def testBytes = "test content"
175176

176177
when:
177-
wrappedStream.write("test".getBytes("UTF-8"))
178-
wrappedStream.write("content".getBytes("UTF-8"))
178+
wrappedStream.write(testBytes[0..5].getBytes("UTF-8"))
179+
wrappedStream.write(testBytes[6..-1].getBytes("UTF-8"))
179180
wrappedStream.close()
180181

181182
then:
182-
1 * mockTelemetryCollector.onInjectionResponseSize(SERVLET_VERSION, 11)
183+
1 * mockTelemetryCollector.onInjectionResponseSize(SERVLET_VERSION, testBytes.length())
183184
}
184185

185186
void 'response sizes are reported by the InjectingPipeOutputStream callback'() {
@@ -190,14 +191,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
190191
def onBytesWritten = Mock(LongConsumer)
191192
def stream = new InjectingPipeOutputStream(
192193
downstream, marker, contentToInject, null, onBytesWritten, null)
194+
def testBytes = "test content"
193195

194196
when:
195-
stream.write("test".getBytes("UTF-8"))
196-
stream.write("content".getBytes("UTF-8"))
197+
stream.write(testBytes[0..5].getBytes("UTF-8"))
198+
stream.write(testBytes[6..-1].getBytes("UTF-8"))
197199
stream.close()
198200

199201
then:
200-
1 * onBytesWritten.accept(11)
202+
1 * onBytesWritten.accept(testBytes.length())
201203
}
202204

203205
void 'response sizes are reported by the InjectingPipeWriter callback'() {
@@ -208,14 +210,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
208210
def onBytesWritten = Mock(LongConsumer)
209211
def writer = new InjectingPipeWriter(
210212
downstream, marker, contentToInject, null, onBytesWritten, null)
213+
def testBytes = "test content"
211214

212215
when:
213-
writer.write("test".toCharArray())
214-
writer.write("content".toCharArray())
216+
writer.write(testBytes[0..5].toCharArray())
217+
writer.write(testBytes[6..-1].toCharArray())
215218
writer.close()
216219

217220
then:
218-
1 * onBytesWritten.accept(11)
221+
1 * onBytesWritten.accept(testBytes.length())
219222
}
220223

221224
void 'injection timing is reported by the InjectingPipeOutputStream callback'() {

dd-java-agent/instrumentation/servlet/request-5/src/test/groovy/RumHttpServletResponseWrapperTest.groovy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
2525

2626
void setup() {
2727
mockRequest.getServletContext() >> mockServletContext
28-
mockServletContext.getEffectiveMajorVersion() >> 5
28+
mockServletContext.getEffectiveMajorVersion() >> Integer.parseInt(SERVLET_VERSION)
2929
wrapper = new RumHttpServletResponseWrapper(mockRequest, mockResponse)
3030
RumInjector.setTelemetryCollector(mockTelemetryCollector)
3131
}
@@ -172,14 +172,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
172172
}
173173
def wrappedStream = new WrappedServletOutputStream(
174174
downstream, marker, contentToInject, null, onBytesWritten, null)
175+
def testBytes = "test content"
175176

176177
when:
177-
wrappedStream.write("test".getBytes("UTF-8"))
178-
wrappedStream.write("content".getBytes("UTF-8"))
178+
wrappedStream.write(testBytes[0..5].getBytes("UTF-8"))
179+
wrappedStream.write(testBytes[6..-1].getBytes("UTF-8"))
179180
wrappedStream.close()
180181

181182
then:
182-
1 * mockTelemetryCollector.onInjectionResponseSize(SERVLET_VERSION, 11)
183+
1 * mockTelemetryCollector.onInjectionResponseSize(SERVLET_VERSION, testBytes.length())
183184
}
184185

185186
void 'response sizes are reported by the InjectingPipeOutputStream callback'() {
@@ -190,14 +191,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
190191
def onBytesWritten = Mock(LongConsumer)
191192
def stream = new InjectingPipeOutputStream(
192193
downstream, marker, contentToInject, null, onBytesWritten, null)
194+
def testBytes = "test content"
193195

194196
when:
195-
stream.write("test".getBytes("UTF-8"))
196-
stream.write("content".getBytes("UTF-8"))
197+
stream.write(testBytes[0..5].getBytes("UTF-8"))
198+
stream.write(testBytes[6..-1].getBytes("UTF-8"))
197199
stream.close()
198200

199201
then:
200-
1 * onBytesWritten.accept(11)
202+
1 * onBytesWritten.accept(testBytes.length())
201203
}
202204

203205
void 'response sizes are reported by the InjectingPipeWriter callback'() {
@@ -208,14 +210,15 @@ class RumHttpServletResponseWrapperTest extends AgentTestRunner {
208210
def onBytesWritten = Mock(LongConsumer)
209211
def writer = new InjectingPipeWriter(
210212
downstream, marker, contentToInject, null, onBytesWritten, null)
213+
def testBytes = "test content"
211214

212215
when:
213-
writer.write("test".toCharArray())
214-
writer.write("content".toCharArray())
216+
writer.write(testBytes[0..5].toCharArray())
217+
writer.write(testBytes[6..-1].toCharArray())
215218
writer.close()
216219

217220
then:
218-
1 * onBytesWritten.accept(11)
221+
1 * onBytesWritten.accept(testBytes.length())
219222
}
220223

221224
void 'injection timing is reported by the InjectingPipeOutputStream callback'() {

internal-api/src/test/groovy/datadog/trace/api/rum/RumInjectorMetricsTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RumInjectorMetricsTest extends Specification {
1616
}
1717
}
1818

19-
// Note: application_id and remote_config_used are dynamic runtime values that depend on
19+
// Note: application_id and remote_config_used tags need dynamic runtime values that depend on
2020
// the RUM configuration state, so we do not test them here.
2121
def "test onInjectionSucceed"() {
2222
when:

internal-api/src/test/groovy/datadog/trace/api/rum/RumInjectorTest.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ class RumInjectorTest extends DDSpecification {
134134

135135
void 'telemetry integration works end-to-end'() {
136136
when:
137-
// simulate CoreTracer enabling telemetry
138137
RumInjector.enableTelemetry(mock(datadog.trace.api.StatsDClient))
139138

140-
// simulate reporting injection telemetry
141139
def telemetryCollector = RumInjector.getTelemetryCollector()
142140
telemetryCollector.onInjectionSucceed("3")
143141
telemetryCollector.onInjectionFailed("3", "gzip")
@@ -146,7 +144,6 @@ class RumInjectorTest extends DDSpecification {
146144
telemetryCollector.onInjectionResponseSize("3", 256)
147145
telemetryCollector.onInjectionTime("3", 5L)
148146

149-
// verify metrics are collected
150147
def summary = telemetryCollector.summary()
151148

152149
then:

0 commit comments

Comments
 (0)