use of safety4j.ErrorHandler in project actor4j-core by relvaner.
the class SafetyFeature method test.
@Test(timeout = 2000)
public void test() {
CountDownLatch testDone = new CountDownLatch(1);
UUID dest = system.addActor(new ActorFactory() {
@Override
public Actor create() {
return new Actor("SafetyFeatureActor") {
@Override
public void receive(ActorMessage<?> message) {
throw new NullPointerException();
}
@Override
public void preRestart(Exception reason) {
super.preRestart(reason);
assertEquals(new NullPointerException().getMessage(), reason.getMessage());
}
@Override
public void postRestart(Exception reason) {
super.postRestart(reason);
assertEquals(new NullPointerException().getMessage(), reason.getMessage());
}
};
}
});
ErrorHandler errorHandler = system.underlyingImpl().getExecuterService().getSafetyManager().getErrorHandler();
system.underlyingImpl().getExecuterService().getSafetyManager().setErrorHandler(new ErrorHandler() {
@Override
public void handle(Throwable t, String message, UUID uuid) {
errorHandler.handle(t, message, uuid);
assertEquals(new NullPointerException().getMessage(), t.getMessage());
assertEquals("actor", message);
assertEquals(dest, uuid);
testDone.countDown();
}
});
system.send(new ActorMessage<Object>(null, 0, system.SYSTEM_ID, dest));
system.send(new ActorMessage<Object>(null, 0, system.SYSTEM_ID, dest));
system.start();
try {
testDone.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
system.shutdown(true);
}
Aggregations