Search in sources :

Example 1 with ExceptionHandler

use of com.lmax.disruptor.ExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldSupportSpecifyingADefaultExceptionHandlerForEventProcessors.

@Test
public void shouldSupportSpecifyingADefaultExceptionHandlerForEventProcessors() throws Exception {
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);
    disruptor.setDefaultExceptionHandler(exceptionHandler);
    disruptor.handleEventsWith(handler);
    publishEvent();
    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
Also used : FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 2 with ExceptionHandler

use of com.lmax.disruptor.ExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldSupportSpecifyingAExceptionHandlerForEventProcessors.

@Test
public void shouldSupportSpecifyingAExceptionHandlerForEventProcessors() throws Exception {
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);
    disruptor.handleExceptionsWith(exceptionHandler);
    disruptor.handleEventsWith(handler);
    publishEvent();
    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
Also used : FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 with ExceptionHandler

use of com.lmax.disruptor.ExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldApplyDefaultExceptionHandlerToExistingEventProcessors.

@Test
public void shouldApplyDefaultExceptionHandlerToExistingEventProcessors() throws Exception {
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);
    disruptor.handleEventsWith(handler);
    disruptor.setDefaultExceptionHandler(exceptionHandler);
    publishEvent();
    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
Also used : FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 4 with ExceptionHandler

use of com.lmax.disruptor.ExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors.

@Test
public void shouldOnlyApplyExceptionsHandlersSpecifiedViaHandleExceptionsWithOnNewEventProcessors() throws Exception {
    AtomicReference<Throwable> eventHandled = new AtomicReference<Throwable>();
    ExceptionHandler exceptionHandler = new StubExceptionHandler(eventHandled);
    RuntimeException testException = new RuntimeException();
    ExceptionThrowingEventHandler handler = new ExceptionThrowingEventHandler(testException);
    disruptor.handleExceptionsWith(exceptionHandler);
    disruptor.handleEventsWith(handler);
    disruptor.handleExceptionsWith(new FatalExceptionHandler());
    publishEvent();
    final Throwable actualException = waitFor(eventHandled);
    assertSame(testException, actualException);
}
Also used : FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) FatalExceptionHandler(com.lmax.disruptor.FatalExceptionHandler) Test(org.junit.Test)

Aggregations

ExceptionHandler (com.lmax.disruptor.ExceptionHandler)4 FatalExceptionHandler (com.lmax.disruptor.FatalExceptionHandler)4 ExceptionThrowingEventHandler (com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler)4 StubExceptionHandler (com.lmax.disruptor.dsl.stubs.StubExceptionHandler)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Test (org.junit.Test)4