11package datadog .smoketest ;
22
3+ import static org .junit .jupiter .api .Assertions .assertEquals ;
34import static org .junit .jupiter .api .Assertions .assertNotNull ;
45import static org .junit .jupiter .api .Assertions .assertTrue ;
56import static org .junit .jupiter .api .Assumptions .assumeFalse ;
1011import com .squareup .moshi .Moshi ;
1112import datadog .environment .JavaVirtualMachine ;
1213import datadog .environment .OperatingSystem ;
13- import datadog .libs .ddprof .DdprofLibraryLoader ;
1414import java .io .File ;
1515import java .io .IOException ;
1616import java .nio .charset .StandardCharsets ;
2222import java .util .Arrays ;
2323import java .util .Comparator ;
2424import java .util .List ;
25+ import java .util .Map ;
2526import java .util .concurrent .BlockingQueue ;
2627import java .util .concurrent .LinkedBlockingQueue ;
2728import java .util .concurrent .TimeUnit ;
@@ -49,15 +50,12 @@ public class CrashtrackingSmokeTest {
4950 private MockWebServer tracingServer ;
5051 private TestUDPServer udpServer ;
5152 private final BlockingQueue <CrashTelemetryData > crashEvents = new LinkedBlockingQueue <>();
53+ private final Moshi moshi = new Moshi .Builder ().build ();
5254
5355 @ BeforeAll
5456 static void setupAll () {
5557 // Only Hotspot based implementation are supported
5658 assumeFalse (JavaVirtualMachine .isJ9 ());
57- // Currently, we require the ddprof java library for crash-tracking; bail out if not supported
58- assumeTrue (
59- DdprofLibraryLoader .jvmAccess ().getReasonNotLoaded () == null ,
60- "JVM Access is not available" );
6159 }
6260
6361 private Path tempDir ;
@@ -68,7 +66,6 @@ void setup() throws Exception {
6866
6967 crashEvents .clear ();
7068
71- Moshi moshi = new Moshi .Builder ().build ();
7269 tracingServer = new MockWebServer ();
7370 tracingServer .setDispatcher (
7471 new Dispatcher () {
@@ -203,7 +200,7 @@ void testCrashTracking() throws Exception {
203200 OUTPUT .captureOutput (p , LOG_FILE_DIR .resolve ("testProcess.testCrashTracking.log" ).toFile ());
204201
205202 assertExpectedCrash (p );
206- assertCrashData ();
203+ assertCrashData (assertCrashPing () );
207204 }
208205
209206 /*
@@ -239,7 +236,7 @@ void testCrashTrackingLegacy() throws Exception {
239236
240237 assertExpectedCrash (p );
241238
242- assertCrashData ();
239+ assertCrashData (assertCrashPing () );
243240 }
244241
245242 /*
@@ -318,7 +315,7 @@ void testCombineTracking() throws Exception {
318315 OUTPUT .captureOutput (p , LOG_FILE_DIR .resolve ("testProcess.testCombineTracking.log" ).toFile ());
319316
320317 assertExpectedCrash (p );
321- assertCrashData ();
318+ assertCrashData (assertCrashPing () );
322319 assertOOMEvent ();
323320 }
324321
@@ -328,11 +325,24 @@ private static void assertExpectedCrash(Process p) throws InterruptedException {
328325 assertTrue (p .waitFor () > 0 , "Application should have crashed" );
329326 }
330327
331- private void assertCrashData () throws InterruptedException {
328+ private String assertCrashPing () throws InterruptedException , IOException {
329+ CrashTelemetryData crashData = crashEvents .poll (DATA_TIMEOUT_MS , TimeUnit .MILLISECONDS );
330+ assertNotNull (crashData , "Crash ping not sent" );
331+ assertTrue (crashData .payload .get (0 ).tags .contains ("is_crash_ping:true" ), "Not a crash ping" );
332+ final Map <?, ?> map = moshi .adapter (Map .class ).fromJson (crashData .payload .get (0 ).message );
333+ final Object uuid = map .get ("crash_uuid" );
334+ assertNotNull (uuid , "crash uuid not found" );
335+ return uuid .toString ();
336+ }
337+
338+ private void assertCrashData (String uuid ) throws InterruptedException , IOException {
332339 CrashTelemetryData crashData = crashEvents .poll (DATA_TIMEOUT_MS , TimeUnit .MILLISECONDS );
333340 assertNotNull (crashData , "Crash data not uploaded" );
334341 assertTrue (crashData .payload .get (0 ).message .contains ("OutOfMemory" ));
335342 assertTrue (crashData .payload .get (0 ).tags .contains ("severity:crash" ));
343+ final Map <?, ?> map = moshi .adapter (Map .class ).fromJson (crashData .payload .get (0 ).message );
344+ final Object receivedUuid = map .get ("uuid" );
345+ assertEquals (uuid , receivedUuid , "crash uuid should match the one sent with the ping" );
336346 }
337347
338348 private void assertOOMEvent () throws InterruptedException {
0 commit comments