|
1 | 1 | package net.lamgc.utils.event; |
2 | 2 |
|
| 3 | +import org.junit.Assert; |
3 | 4 | import org.junit.Test; |
4 | 5 |
|
5 | 6 | import java.util.concurrent.ArrayBlockingQueue; |
6 | 7 | import java.util.concurrent.ThreadPoolExecutor; |
7 | 8 | import java.util.concurrent.TimeUnit; |
| 9 | +import java.util.concurrent.atomic.AtomicBoolean; |
8 | 10 |
|
9 | 11 | public class EventExecutorTest { |
10 | 12 |
|
@@ -55,16 +57,23 @@ public void caughtExceptionTest() throws IllegalAccessException, InterruptedExce |
55 | 57 | }); |
56 | 58 | EventExecutor executor = new EventExecutor(threadPoolExecutor); |
57 | 59 |
|
58 | | - executor.setEventUncaughtExceptionHandler((handler, handlerMethod, event, cause) -> { |
59 | | - System.out.println("Handler: " + handler.toString() + ", MethodName: " + handlerMethod.getName() + |
60 | | - ", Event: " + event.getClass().getSimpleName() + " throw Exception: " + cause.getMessage()); |
| 60 | + AtomicBoolean handlerException = new AtomicBoolean(false); |
| 61 | + executor.setEventUncaughtExceptionHandler((t, handler, handlerMethod, event, cause) -> { |
| 62 | + System.out.println( |
| 63 | + "Thread: [" + t.getId() + "] " + t.getName() + |
| 64 | + ", Handler: " + handler.toString() + |
| 65 | + ", MethodName: " + handlerMethod.getName() + |
| 66 | + ", Event: " + event.getClass().getSimpleName() + |
| 67 | + " throw Exception: " + cause.getMessage()); |
61 | 68 | cause.printStackTrace(); |
| 69 | + handlerException.set(true); |
62 | 70 | }); |
63 | 71 |
|
64 | 72 | SimpleEventHandler handler = new SimpleEventHandler("handler1"); |
65 | 73 | executor.addHandler(handler); |
66 | 74 | executor.executor(new ExceptionThrowEvent(new NullPointerException())); |
67 | 75 | Thread.sleep(1000L); |
| 76 | + Assert.assertTrue(handlerException.get()); |
68 | 77 | } |
69 | 78 |
|
70 | 79 | } |
0 commit comments