58370
|
1 |
package jdk.jfr.api.consumer.recordingstream;
|
|
2 |
|
|
3 |
import java.util.concurrent.CountDownLatch;
|
|
4 |
import java.util.concurrent.atomic.AtomicBoolean;
|
|
5 |
|
|
6 |
public class TestUtils {
|
|
7 |
|
|
8 |
public static final class TestError extends Error {
|
|
9 |
private static final long serialVersionUID = 1L;
|
|
10 |
}
|
|
11 |
|
|
12 |
public static final class TestException extends Exception {
|
|
13 |
private static final long serialVersionUID = 1L;
|
|
14 |
private volatile boolean printed;
|
|
15 |
|
|
16 |
@Override
|
|
17 |
public void printStackTrace() {
|
|
18 |
super.printStackTrace();
|
|
19 |
printed = true;
|
|
20 |
}
|
|
21 |
|
|
22 |
public boolean isPrinted() {
|
|
23 |
return printed;
|
|
24 |
}
|
|
25 |
}
|
|
26 |
|
|
27 |
// Can throw checked exception as unchecked.
|
|
28 |
@SuppressWarnings("unchecked")
|
|
29 |
public static <T extends Throwable> void throwUnchecked(Throwable e) throws T {
|
|
30 |
throw (T) e;
|
|
31 |
}
|
|
32 |
|
|
33 |
public static void installUncaughtException(CountDownLatch receivedError, Throwable expected) {
|
|
34 |
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
|
|
35 |
if (throwable == expected) {
|
|
36 |
System.out.println("Received uncaught exception " + expected.getClass());
|
|
37 |
receivedError.countDown();
|
|
38 |
}
|
|
39 |
});
|
|
40 |
}
|
|
41 |
}
|