SyncFinisher增加setExceptionHandler方法

This commit is contained in:
Looly 2023-05-15 19:46:21 +08:00
parent 08343db0f0
commit d0556a4e48

View File

@ -16,6 +16,8 @@ import org.dromara.hutool.core.lang.Console;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicBoolean;
public class SyncFinisherTest {
/**
@ -23,16 +25,21 @@ public class SyncFinisherTest {
*/
@Test
void executeExceptionTest() {
final AtomicBoolean hasException = new AtomicBoolean(false);
final SyncFinisher syncFinisher = new SyncFinisher(10);
syncFinisher.addWorker(()->{
Console.log(Integer.parseInt("XYZ"));//这里会抛RuntimeException
});
syncFinisher.setExceptionHandler((t, e) -> {
hasException.set(true);
Assertions.assertEquals("For input string: \"XYZ\"", e.getMessage());
});
syncFinisher.start();
syncFinisher.close();
ThreadUtil.sleep(300);
Assertions.assertTrue(hasException.get());
}
}