Fix race conditation in test and add logging for TestLatestEvent JEP-349-branch
authoregahlin
Mon, 21 Oct 2019 20:09:06 +0200
branchJEP-349-branch
changeset 58724 3d0a172353fc
parent 58721 2576ae69235f
child 58755 ac3504a5597c
Fix race conditation in test and add logging for TestLatestEvent
test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java
test/jdk/jdk/jfr/api/consumer/streaming/TestLatestEvent.java
--- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java	Mon Oct 21 18:35:30 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java	Mon Oct 21 20:09:06 2019 +0200
@@ -30,8 +30,6 @@
 import java.nio.file.Paths;
 import java.time.Duration;
 import java.time.Instant;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import jdk.jfr.Event;
@@ -43,7 +41,6 @@
 import jdk.jfr.consumer.RecordedEvent;
 import jdk.jfr.consumer.RecordingFile;
 import jdk.jfr.consumer.RecordingStream;
-import jdk.test.lib.jfr.Events;
 
 /**
  * @test
--- a/test/jdk/jdk/jfr/api/consumer/streaming/TestLatestEvent.java	Mon Oct 21 18:35:30 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/streaming/TestLatestEvent.java	Mon Oct 21 20:09:06 2019 +0200
@@ -65,9 +65,11 @@
             r.onEvent("MakeChunks", event-> {
                 beginChunks.countDown();
             });
+            System.out.println("Waitning for first chunk");
             beginChunks.await();
             // Create 5 chunks with events in the repository
             for (int i = 0; i < 5; i++) {
+                System.out.println("Creating empty chunk");
                 try (Recording r1 = new Recording()) {
                     r1.start();
                     NotLatestEvent notLatest = new NotLatestEvent();
@@ -75,24 +77,27 @@
                     r1.stop();
                 }
             }
-
+            System.out.println("All empty chunks created");
             // Create an event in a segment, typically the first.
             NotLatestEvent notLatest = new NotLatestEvent();
             notLatest.commit();
-
             try (EventStream s = EventStream.openRepository()) {
+                System.out.println("EventStream opened");
                 awaitFlush(r); // ensure that NotLatest is included
                 s.startAsync();
                 AtomicBoolean foundLatest = new AtomicBoolean();
-                // Emit the latest event
-                LatestEvent latest = new LatestEvent();
-                latest.commit();
+                System.out.println("Added onEvent handler");
                 s.onEvent(event -> {
                     String name = event.getEventType().getName();
                     System.out.println("Found event " + name);
                     foundLatest.set(name.equals("Latest"));
                     s.close();
                 });
+                // Emit the latest event
+                LatestEvent latest = new LatestEvent();
+                latest.commit();
+                System.out.println("Latest event emitted");
+                System.out.println("Waiting for termination");
                 s.awaitTermination();
                 if (!foundLatest.get()) {
                     throw new Exception("Didn't find latest event!");
@@ -103,9 +108,12 @@
 
     private static void awaitFlush(RecordingStream r) throws InterruptedException {
         CountDownLatch latch = new CountDownLatch(1);
+        System.out.println("Waiting for flush...");
         r.onFlush(() -> {
+            System.out.println("Flush arrived!");
             latch.countDown();
         });
         latch.await();
+
     }
 }