Improve test coverage for RecordingStream::enable(...) and RecordingStream:disable(...) JEP-349-branch
authoregahlin
Fri, 27 Sep 2019 13:20:04 +0200
branchJEP-349-branch
changeset 58373 849a45ac808a
parent 58371 a6d44d9bf80b
child 58374 a5ef6febbd26
Improve test coverage for RecordingStream::enable(...) and RecordingStream:disable(...)
test/jdk/jdk/jfr/api/consumer/recordingstream/TestDisable.java
test/jdk/jdk/jfr/api/consumer/recordingstream/TestEnable.java
--- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestDisable.java	Fri Sep 27 13:03:11 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestDisable.java	Fri Sep 27 13:20:04 2019 +0200
@@ -27,6 +27,7 @@
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;
 
 import jdk.jfr.Event;
 import jdk.jfr.consumer.RecordingStream;
@@ -48,6 +49,19 @@
     }
 
     public static void main(String... args) throws Exception {
+        testDisableWithClass();
+        testDisableWithEventName();
+    }
+
+    private static void testDisableWithEventName() {
+        test(r -> r.disable(DisabledEvent.class.getName()));
+    }
+
+    private static void testDisableWithClass() {
+        test(r -> r.disable(DisabledEvent.class));
+    }
+
+    private static void test(Consumer<RecordingStream> disablement) {
         CountDownLatch twoEvent = new CountDownLatch(2);
         AtomicBoolean fail = new AtomicBoolean(false);
         try(RecordingStream r = new RecordingStream()) {
@@ -57,7 +71,7 @@
                 }
                 twoEvent.countDown();
             });
-            r.disable(DisabledEvent.class.getName());
+            disablement.accept(r);
             r.startAsync();
             EnabledEvent e1 = new EnabledEvent();
             e1.commit();
@@ -65,9 +79,13 @@
             d1.commit();
             EnabledEvent e2 = new EnabledEvent();
             e2.commit();
-            twoEvent.await();
+            try {
+                twoEvent.await();
+            } catch (InterruptedException ie) {
+                throw new RuntimeException("Unexpexpected interruption of thread", ie);
+            }
             if (fail.get()) {
-                throw new Exception("Should not receive a disabled event");
+                throw new RuntimeException("Should not receive a disabled event");
             }
         }
     }
--- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestEnable.java	Fri Sep 27 13:03:11 2019 +0200
+++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestEnable.java	Fri Sep 27 13:20:04 2019 +0200
@@ -26,6 +26,7 @@
 package jdk.jfr.api.consumer.recordingstream;
 
 import java.util.concurrent.CountDownLatch;
+import java.util.function.Consumer;
 
 import jdk.jfr.Enabled;
 import jdk.jfr.Event;
@@ -46,16 +47,33 @@
     }
 
     public static void main(String... args) throws Exception {
+        testEnableWithClass();
+        testEnableWithEventName();
+    }
+
+    private static void testEnableWithEventName() {
+        test(r -> r.enable(EnabledEvent.class.getName()));
+    }
+
+    private static void testEnableWithClass() {
+        test(r -> r.enable(EnabledEvent.class));
+    }
+
+    private static void test(Consumer<RecordingStream> enablement) {
         CountDownLatch event = new CountDownLatch(1);
         try (RecordingStream r = new RecordingStream()) {
             r.onEvent(e -> {
                 event.countDown();
             });
-            r.enable(EnabledEvent.class.getName());
+            enablement.accept(r);
             r.startAsync();
             EnabledEvent e = new EnabledEvent();
             e.commit();
-            event.await();
+            try {
+                event.await();
+            } catch (InterruptedException ie) {
+                throw new RuntimeException("Unexpected interruption of latch", ie);
+            }
         }
     }
 }