Skip to content

Commit 412a3f8

Browse files
committed
Address jacoco coverage and injectingpipeoutstream interface updates
1 parent 7a5cd68 commit 412a3f8

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
lines changed

dd-java-agent/agent-bootstrap/src/jmh/java/datadog/trace/bootstrap/instrumentation/buffer/InjectingPipeOutputStreamBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public class InjectingPipeOutputStreamBenchmark {
5151
public void withPipe() throws Exception {
5252
try (final PrintWriter out =
5353
new PrintWriter(
54-
new InjectingPipeOutputStream(new ByteArrayOutputStream(), marker, content, null))) {
54+
new InjectingPipeOutputStream(
55+
new ByteArrayOutputStream(), marker, content, null, null))) {
5556
htmlContent.forEach(out::println);
5657
}
5758
}

internal-api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ val excludedClassesBranchCoverage by extra(
250250
"datadog.trace.api.env.CapturedEnvironment.ProcessInfo",
251251
"datadog.trace.util.TempLocationManager",
252252
"datadog.trace.util.TempLocationManager.*",
253+
// Branches depend on RUM injector state that cannot be reliably controlled in unit tests
254+
"datadog.trace.api.rum.RumInjectorMetrics",
253255
)
254256
)
255257

internal-api/src/main/java/datadog/trace/api/rum/RumTelemetryCollector.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,58 @@ public String summary() {
3636
}
3737
};
3838

39+
/**
40+
* Reports successful RUM injection.
41+
*
42+
* @param integrationVersion The version of the integration that was injected.
43+
*/
3944
void onInjectionSucceed(String integrationVersion);
4045

46+
/**
47+
* Reports failed RUM injection.
48+
*
49+
* @param integrationVersion The version of the integration that was injected.
50+
* @param contentEncoding The content encoding of the response that was injected.
51+
*/
4152
void onInjectionFailed(String integrationVersion, String contentEncoding);
4253

54+
/**
55+
* Reports skipped RUM injection.
56+
*
57+
* @param integrationVersion The version of the integration that was injected.
58+
*/
4359
void onInjectionSkipped(String integrationVersion);
4460

61+
/** Reports successful RUM injector initialization. */
4562
void onInitializationSucceed();
4663

64+
/**
65+
* Reports content security policy detected in the response header to be injected.
66+
*
67+
* @param integrationVersion The version of the integration that was injected.
68+
*/
4769
void onContentSecurityPolicyDetected(String integrationVersion);
4870

71+
/**
72+
* Reports the size of the response before injection.
73+
*
74+
* @param integrationVersion The version of the integration that was injected.
75+
* @param bytes The size of the response before injection.
76+
*/
4977
void onInjectionResponseSize(String integrationVersion, long bytes);
5078

79+
/**
80+
* Reports the time taken to inject the RUM SDK.
81+
*
82+
* @param integrationVersion The version of the integration that was injected.
83+
* @param milliseconds The time taken to inject the RUM SDK.
84+
*/
5185
void onInjectionTime(String integrationVersion, long milliseconds);
5286

87+
/** Closes the telemetry collector. */
5388
default void close() {}
5489

90+
/** Returns a human-readable summary of the telemetry collected. */
5591
default String summary() {
5692
return "";
5793
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package datadog.trace.api.rum
2+
3+
import spock.lang.Specification
4+
5+
class RumTelemetryCollectorTest extends Specification {
6+
7+
def "test default NO_OP does not throw exception"() {
8+
when:
9+
RumTelemetryCollector.NO_OP.onInjectionSucceed("3")
10+
RumTelemetryCollector.NO_OP.onInjectionSucceed("5")
11+
RumTelemetryCollector.NO_OP.onInjectionFailed("3", "gzip")
12+
RumTelemetryCollector.NO_OP.onInjectionFailed("5", "none")
13+
RumTelemetryCollector.NO_OP.onInjectionSkipped("3")
14+
RumTelemetryCollector.NO_OP.onInjectionSkipped("5")
15+
RumTelemetryCollector.NO_OP.onInitializationSucceed()
16+
RumTelemetryCollector.NO_OP.onContentSecurityPolicyDetected("3")
17+
RumTelemetryCollector.NO_OP.onContentSecurityPolicyDetected("5")
18+
RumTelemetryCollector.NO_OP.onInjectionResponseSize("3", 256L)
19+
RumTelemetryCollector.NO_OP.onInjectionResponseSize("5", 512L)
20+
RumTelemetryCollector.NO_OP.onInjectionTime("3", 10L)
21+
RumTelemetryCollector.NO_OP.onInjectionTime("5", 20L)
22+
RumTelemetryCollector.NO_OP.close()
23+
24+
then:
25+
noExceptionThrown()
26+
}
27+
28+
def "test default NO_OP summary returns an empty string"() {
29+
when:
30+
def summary = RumTelemetryCollector.NO_OP.summary()
31+
32+
then:
33+
summary == ""
34+
}
35+
36+
def "test default NO_OP close method does not throw exception"() {
37+
when:
38+
RumTelemetryCollector.NO_OP.close()
39+
40+
then:
41+
noExceptionThrown()
42+
}
43+
44+
def "test defining a custom implementation does not throw exception"() {
45+
setup:
46+
def customCollector = new RumTelemetryCollector() {
47+
@Override
48+
void onInjectionSucceed(String integrationVersion) {
49+
}
50+
51+
@Override
52+
void onInjectionFailed(String integrationVersion, String contentEncoding) {
53+
}
54+
55+
@Override
56+
void onInjectionSkipped(String integrationVersion) {
57+
}
58+
59+
@Override
60+
void onInitializationSucceed() {
61+
}
62+
63+
@Override
64+
void onContentSecurityPolicyDetected(String integrationVersion) {
65+
}
66+
67+
@Override
68+
void onInjectionResponseSize(String integrationVersion, long bytes) {
69+
}
70+
71+
@Override
72+
void onInjectionTime(String integrationVersion, long milliseconds) {
73+
}
74+
}
75+
76+
when:
77+
customCollector.close()
78+
def summary = customCollector.summary()
79+
80+
then:
81+
noExceptionThrown()
82+
summary == ""
83+
}
84+
85+
def "test multiple close calls do not throw exception"() {
86+
when:
87+
RumTelemetryCollector.NO_OP.close()
88+
RumTelemetryCollector.NO_OP.close()
89+
RumTelemetryCollector.NO_OP.close()
90+
91+
then:
92+
noExceptionThrown()
93+
}
94+
95+
def "test multiple summary calls return the same empty string"() {
96+
when:
97+
def summary1 = RumTelemetryCollector.NO_OP.summary()
98+
def summary2 = RumTelemetryCollector.NO_OP.summary()
99+
def summary3 = RumTelemetryCollector.NO_OP.summary()
100+
101+
then:
102+
summary1 == ""
103+
summary1 == summary2
104+
summary2 == summary3
105+
}
106+
}

0 commit comments

Comments
 (0)