--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestUtils.java Fri Sep 27 13:01:55 2019 +0200
@@ -0,0 +1,41 @@
+package jdk.jfr.api.consumer.recordingstream;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class TestUtils {
+
+ public static final class TestError extends Error {
+ private static final long serialVersionUID = 1L;
+ }
+
+ public static final class TestException extends Exception {
+ private static final long serialVersionUID = 1L;
+ private volatile boolean printed;
+
+ @Override
+ public void printStackTrace() {
+ super.printStackTrace();
+ printed = true;
+ }
+
+ public boolean isPrinted() {
+ return printed;
+ }
+ }
+
+ // Can throw checked exception as unchecked.
+ @SuppressWarnings("unchecked")
+ public static <T extends Throwable> void throwUnchecked(Throwable e) throws T {
+ throw (T) e;
+ }
+
+ public static void installUncaughtException(CountDownLatch receivedError, Throwable expected) {
+ Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
+ if (throwable == expected) {
+ System.out.println("Received uncaught exception " + expected.getClass());
+ receivedError.countDown();
+ }
+ });
+ }
+}