38
38
import java .util .concurrent .TimeUnit ;
39
39
import java .util .concurrent .TimeoutException ;
40
40
import java .util .function .Predicate ;
41
+ import java .util .stream .Stream ;
41
42
import okhttp3 .mockwebserver .Dispatcher ;
42
43
import okhttp3 .mockwebserver .MockResponse ;
43
44
import okhttp3 .mockwebserver .MockWebServer ;
53
54
import org .junit .jupiter .api .TestInfo ;
54
55
import org .junit .jupiter .api .condition .DisabledIfSystemProperty ;
55
56
import org .junit .jupiter .params .ParameterizedTest ;
56
- import org .junit .jupiter .params .provider .ValueSource ;
57
+ import org .junit .jupiter .params .provider .Arguments ;
58
+ import org .junit .jupiter .params .provider .MethodSource ;
57
59
import org .openjdk .jmc .common .IMCStackTrace ;
58
60
import org .openjdk .jmc .common .item .Aggregators ;
59
61
import org .openjdk .jmc .common .item .IAttribute ;
@@ -154,57 +156,29 @@ void teardown() throws Exception {
154
156
}
155
157
}
156
158
157
- @ ParameterizedTest
158
- @ ValueSource (strings = {"jfr" , "ddprof" })
159
- @ DisplayName ("Test continuous recording - no jmx delay, default compression" )
160
- public void testContinuousRecording_no_jmx_delay (String profiler , final TestInfo testInfo )
161
- throws Exception {
162
- Assumptions .assumeTrue ("jfr" .equals (profiler ) || OperatingSystem .isLinux ());
163
- testWithRetry (
164
- () ->
165
- testContinuousRecording (
166
- 0 , ENDPOINT_COLLECTION_ENABLED , "ddprof" .equals (profiler ), false ),
167
- testInfo ,
168
- 5 );
169
- }
170
-
171
- @ ParameterizedTest
172
- @ ValueSource (strings = {"jfr" , "ddprof" })
173
- @ DisplayName ("Test continuous recording - no jmx delay, zstd compression" )
174
- public void testContinuousRecording_no_jmx_delay_zstd (String profiler , final TestInfo testInfo )
175
- throws Exception {
176
- Assumptions .assumeTrue ("jfr" .equals (profiler ) || OperatingSystem .isLinux ());
159
+ private static Stream <Arguments > testArguments () {
160
+ return Stream .of (
161
+ Arguments .of (0 , "on" , "jfr" ),
162
+ Arguments .of (0 , "on" , "ddprof" ),
163
+ Arguments .of (0 , "lz4" , "jfr" ),
164
+ Arguments .of (0 , "lz4" , "ddprof" ),
165
+ Arguments .of (1 , "on" , "jfr" ),
166
+ Arguments .of (1 , "on" , "ddprof" ),
167
+ Arguments .of (1 , "lz4" , "jfr" ),
168
+ Arguments .of (1 , "lz4" , "ddprof" ));
169
+ }
170
+
171
+ @ ParameterizedTest (name = "Continuous recording [jmx delay: {0}, compression: {1}, mode: {2}]" )
172
+ @ MethodSource ("testArguments" )
173
+ public void testContinuousRecording_with_params (
174
+ int jmxDelay , String compression , String mode , final TestInfo testInfo ) throws Exception {
175
+ Assumptions .assumeTrue ("jfr" .equals (mode ) || OperatingSystem .isLinux ());
176
+ // Do not test compressions for Oracle JDK 8 - it will always be GZIP
177
+ Assumptions .assumeTrue (!JavaVirtualMachine .isOracleJDK8 () || "on" .equals (mode ));
177
178
testWithRetry (
178
179
() ->
179
180
testContinuousRecording (
180
- 0 , ENDPOINT_COLLECTION_ENABLED , "ddprof" .equals (profiler ), true ),
181
- testInfo ,
182
- 5 );
183
- }
184
-
185
- @ ParameterizedTest
186
- @ ValueSource (strings = {"jfr" , "ddprof" })
187
- @ DisplayName ("Test continuous recording - 1 sec jmx delay, default compression" )
188
- public void testContinuousRecording (String profiler , final TestInfo testInfo ) throws Exception {
189
- Assumptions .assumeTrue ("jfr" .equals (profiler ) || OperatingSystem .isLinux ());
190
- testWithRetry (
191
- () ->
192
- testContinuousRecording (
193
- 1 , ENDPOINT_COLLECTION_ENABLED , "ddprof" .equals (profiler ), false ),
194
- testInfo ,
195
- 5 );
196
- }
197
-
198
- @ ParameterizedTest
199
- @ ValueSource (strings = {"jfr" , "ddprof" })
200
- @ DisplayName ("Test continuous recording - 1 sec jmx delay, zstd compression" )
201
- public void testContinuousRecording_zstd (String profiler , final TestInfo testInfo )
202
- throws Exception {
203
- Assumptions .assumeTrue ("jfr" .equals (profiler ) || OperatingSystem .isLinux ());
204
- testWithRetry (
205
- () ->
206
- testContinuousRecording (
207
- 1 , ENDPOINT_COLLECTION_ENABLED , "ddprof" .equals (profiler ), true ),
181
+ jmxDelay , ENDPOINT_COLLECTION_ENABLED , "ddprof" .equals (mode ), compression ),
208
182
testInfo ,
209
183
5 );
210
184
}
@@ -213,7 +187,7 @@ private void testContinuousRecording(
213
187
final int jmxFetchDelay ,
214
188
final boolean endpointCollectionEnabled ,
215
189
final boolean asyncProfilerEnabled ,
216
- final boolean withZstd )
190
+ final String withCompression )
217
191
throws Exception {
218
192
final ObjectMapper mapper = new ObjectMapper ();
219
193
try {
@@ -222,7 +196,7 @@ private void testContinuousRecording(
222
196
jmxFetchDelay ,
223
197
endpointCollectionEnabled ,
224
198
asyncProfilerEnabled ,
225
- withZstd ,
199
+ withCompression ,
226
200
logFilePath )
227
201
.start ();
228
202
@@ -277,9 +251,7 @@ private void testContinuousRecording(
277
251
278
252
assertFalse (logHasErrors (logFilePath ));
279
253
InputStream eventStream = new ByteArrayInputStream (rawJfr .get ());
280
- if (withZstd ) {
281
- eventStream = new ZstdInputStream (eventStream );
282
- }
254
+ eventStream = decompressStream (withCompression , eventStream );
283
255
IItemCollection events = JfrLoaderToolkit .loadEvents (eventStream );
284
256
assertTrue (events .hasItems ());
285
257
Pair <Instant , Instant > rangeStartAndEnd = getRangeStartAndEnd (events );
@@ -328,9 +300,7 @@ private void testContinuousRecording(
328
300
() -> "Upload period = " + period + "ms, expected (0, " + upperLimit + "]ms" );
329
301
330
302
eventStream = new ByteArrayInputStream (rawJfr .get ());
331
- if (withZstd ) {
332
- eventStream = new ZstdInputStream (eventStream );
333
- }
303
+ eventStream = decompressStream (withCompression , eventStream );
334
304
events = JfrLoaderToolkit .loadEvents (eventStream );
335
305
assertTrue (events .hasItems ());
336
306
verifyDatadogEventsNotCorrupt (events );
@@ -372,6 +342,20 @@ private void testContinuousRecording(
372
342
}
373
343
}
374
344
345
+ private static InputStream decompressStream (String withCompression , InputStream eventStream ) {
346
+ if (!JavaVirtualMachine .isOracleJDK8 ()) {
347
+ if ("zstd" .equals (withCompression ) || "on" .equals (withCompression )) {
348
+ eventStream = new ZstdInputStream (eventStream );
349
+ } else {
350
+ // nothing; jmc already handles lz4 and gzip
351
+ }
352
+ } else {
353
+ // Oracle JDK 8 JFR writes files in GZIP format; jmc already can handle that
354
+ }
355
+
356
+ return eventStream ;
357
+ }
358
+
375
359
private static void verifyJdkEventsDisabled (IItemCollection events ) {
376
360
assertFalse (events .apply (ItemFilters .type ("jdk.ExecutionSample" )).hasItems ());
377
361
assertFalse (events .apply (ItemFilters .type ("jdk.ThreadPark" )).hasItems ());
@@ -466,7 +450,7 @@ void testBogusApiKey(final TestInfo testInfo) throws Exception {
466
450
PROFILING_UPLOAD_PERIOD_SECONDS ,
467
451
ENDPOINT_COLLECTION_ENABLED ,
468
452
true ,
469
- false ,
453
+ "off" ,
470
454
exitDelay ,
471
455
logFilePath )
472
456
.start ();
@@ -524,7 +508,7 @@ void testShutdown(final TestInfo testInfo) throws Exception {
524
508
PROFILING_UPLOAD_PERIOD_SECONDS ,
525
509
ENDPOINT_COLLECTION_ENABLED ,
526
510
true ,
527
- false ,
511
+ "off" ,
528
512
duration ,
529
513
logFilePath )
530
514
.start ();
@@ -752,7 +736,7 @@ private ProcessBuilder createDefaultProcessBuilder(
752
736
final int jmxFetchDelay ,
753
737
final boolean endpointCollectionEnabled ,
754
738
final boolean asyncProfilerEnabled ,
755
- final boolean withZstd ,
739
+ final String withCompression ,
756
740
final Path logFilePath ) {
757
741
return createProcessBuilder (
758
742
VALID_API_KEY ,
@@ -761,7 +745,7 @@ private ProcessBuilder createDefaultProcessBuilder(
761
745
PROFILING_UPLOAD_PERIOD_SECONDS ,
762
746
endpointCollectionEnabled ,
763
747
asyncProfilerEnabled ,
764
- withZstd ,
748
+ withCompression ,
765
749
0 ,
766
750
logFilePath );
767
751
}
@@ -773,7 +757,7 @@ private ProcessBuilder createProcessBuilder(
773
757
final int profilingUploadPeriodSecs ,
774
758
final boolean endpointCollectionEnabled ,
775
759
final boolean asyncProfilerEnabled ,
776
- final boolean withZstd ,
760
+ final String withCompression ,
777
761
final int exitDelay ,
778
762
final Path logFilePath ) {
779
763
return createProcessBuilder (
@@ -785,7 +769,7 @@ private ProcessBuilder createProcessBuilder(
785
769
profilingUploadPeriodSecs ,
786
770
endpointCollectionEnabled ,
787
771
asyncProfilerEnabled ,
788
- withZstd ,
772
+ withCompression ,
789
773
exitDelay ,
790
774
logFilePath );
791
775
}
@@ -799,7 +783,7 @@ private static ProcessBuilder createProcessBuilder(
799
783
final int profilingUploadPeriodSecs ,
800
784
final boolean endpointCollectionEnabled ,
801
785
final boolean asyncProfilerEnabled ,
802
- final boolean withZstd ,
786
+ final String withCompression ,
803
787
final int exitDelay ,
804
788
final Path logFilePath ) {
805
789
final String templateOverride =
@@ -833,7 +817,7 @@ private static ProcessBuilder createProcessBuilder(
833
817
"-Ddd.profiling.debug.dump_path=/tmp/dd-profiler" ,
834
818
"-Ddd.profiling.queueing.time.enabled=true" ,
835
819
"-Ddd.profiling.queueing.time.threshold.millis=0" ,
836
- "-Ddd.profiling.debug.upload.compression=" + ( withZstd ? "zstd" : "on" ) ,
820
+ "-Ddd.profiling.debug.upload.compression=" + withCompression ,
837
821
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug" ,
838
822
"-Ddd.profiling.context.attributes=foo,bar" ,
839
823
"-Dorg.slf4j.simpleLogger.defaultLogLevel=debug" ,
0 commit comments