Search in sources :

Example 1 with ErrorHandler

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);
}
Also used : ErrorHandler(safety4j.ErrorHandler) CountDownLatch(java.util.concurrent.CountDownLatch) Actor(actor4j.core.actors.Actor) UUID(java.util.UUID) ActorFactory(actor4j.core.utils.ActorFactory) Test(org.junit.Test)

Aggregations

Actor (actor4j.core.actors.Actor)1 ActorFactory (actor4j.core.utils.ActorFactory)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 ErrorHandler (safety4j.ErrorHandler)1