Improve TestFilledChunks.java JEP-349-branch
authoregahlin
Wed, 23 Oct 2019 15:01:32 +0200
branchJEP-349-branch
changeset 58755 ac3504a5597c
parent 58724 3d0a172353fc
child 58757 df9b65cc99e8
Improve TestFilledChunks.java
test/jdk/jdk/jfr/api/consumer/streaming/TestFilledChunks.java
--- a/test/jdk/jdk/jfr/api/consumer/streaming/TestFilledChunks.java	Mon Oct 21 20:09:06 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/streaming/TestFilledChunks.java	Wed Oct 23 15:01:32 2019 +0200
@@ -26,8 +26,6 @@
 package jdk.jfr.api.consumer.streaming;
 
 import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import jdk.jfr.Event;
 import jdk.jfr.consumer.RecordingStream;
@@ -55,23 +53,22 @@
     private static final int EVENT_COUNT = 5_000_000;
 
     public static void main(String... args) throws Exception {
-        CountDownLatch end = new CountDownLatch(1);
-        AtomicInteger idCounter = new AtomicInteger();
-        try (RecordingStream es = new RecordingStream()) {
-            es.onEvent(EndEvent.class.getName(), e -> end.countDown());
-            es.onEvent(FillEvent.class.getName(), e -> {
-                idCounter.incrementAndGet();
-//                if (id != expected) {
-//                    throw new Error("Expected id " + expected + ", but got " + id);
-//                }
+        try (RecordingStream rs = new RecordingStream()) {
+            rs.onEvent(FillEvent.class.getName(), e -> {
+                int id = e.getInt("id");
+                // Some events may get lost due to
+                // buffer being full.
+                if (id > EVENT_COUNT / 2) {
+                    rs.close();
+                }
             });
-            es.startAsync();
+            rs.startAsync();
             long seed = System.currentTimeMillis();
             System.out.println("Random seed: " + seed);
             Random r = new Random(seed);
             for (int i = 1; i < EVENT_COUNT; i++) {
                 FillEvent f = new FillEvent();
-                f.message = i %2 == 0 ? "ko" : "kak";
+                f.message = i % 2 == 0 ? "hello, hello, hello, hello, hello!" : "hi!";
                 f.value = r.nextInt(10000);
                 f.id = i;
                 f.commit();
@@ -79,14 +76,7 @@
                     System.out.println("Emitted " + i + " events");
                 }
             }
-            System.out.println("Awaiting end event");
-            Thread.sleep(1_000);
-            for (int i = 1; i < EVENT_COUNT; i++) {
-                EndEvent e = new EndEvent();
-                e.commit();
-            }
-            end.await();
-
+            rs.awaitTermination();
         }
     }
 }