mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
SyncFinisher增加setExceptionHandler方法
This commit is contained in:
parent
08343db0f0
commit
d0556a4e48
@ -16,6 +16,8 @@ import org.dromara.hutool.core.lang.Console;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class SyncFinisherTest {
|
public class SyncFinisherTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,16 +25,21 @@ public class SyncFinisherTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void executeExceptionTest() {
|
void executeExceptionTest() {
|
||||||
|
final AtomicBoolean hasException = new AtomicBoolean(false);
|
||||||
final SyncFinisher syncFinisher = new SyncFinisher(10);
|
final SyncFinisher syncFinisher = new SyncFinisher(10);
|
||||||
syncFinisher.addWorker(()->{
|
syncFinisher.addWorker(()->{
|
||||||
Console.log(Integer.parseInt("XYZ"));//这里会抛RuntimeException
|
Console.log(Integer.parseInt("XYZ"));//这里会抛RuntimeException
|
||||||
});
|
});
|
||||||
|
|
||||||
syncFinisher.setExceptionHandler((t, e) -> {
|
syncFinisher.setExceptionHandler((t, e) -> {
|
||||||
|
hasException.set(true);
|
||||||
Assertions.assertEquals("For input string: \"XYZ\"", e.getMessage());
|
Assertions.assertEquals("For input string: \"XYZ\"", e.getMessage());
|
||||||
});
|
});
|
||||||
|
|
||||||
syncFinisher.start();
|
syncFinisher.start();
|
||||||
syncFinisher.close();
|
syncFinisher.close();
|
||||||
|
ThreadUtil.sleep(300);
|
||||||
|
Assertions.assertTrue(hasException.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user