Search in sources :

Example 1 with StubExceptionHandler

use of com.lmax.disruptor.dsl.stubs.StubExceptionHandler 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 StubExceptionHandler

use of com.lmax.disruptor.dsl.stubs.StubExceptionHandler 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 StubExceptionHandler

use of com.lmax.disruptor.dsl.stubs.StubExceptionHandler 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 StubExceptionHandler

use of com.lmax.disruptor.dsl.stubs.StubExceptionHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldBeAbleToOverrideTheExceptionHandlerForAEventProcessor.

@Test
public void shouldBeAbleToOverrideTheExceptionHandlerForAEventProcessor() throws Exception {
    final RuntimeException testException = new RuntimeException();
    final ExceptionThrowingEventHandler eventHandler = new ExceptionThrowingEventHandler(testException);
    disruptor.handleEventsWith(eventHandler);
    AtomicReference<Throwable> reference = new AtomicReference<Throwable>();
    StubExceptionHandler exceptionHandler = new StubExceptionHandler(reference);
    disruptor.handleExceptionsFor(eventHandler).with(exceptionHandler);
    publishEvent();
    waitFor(reference);
}
Also used : ExceptionThrowingEventHandler(com.lmax.disruptor.dsl.stubs.ExceptionThrowingEventHandler) StubExceptionHandler(com.lmax.disruptor.dsl.stubs.StubExceptionHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 5 with StubExceptionHandler

use of com.lmax.disruptor.dsl.stubs.StubExceptionHandler 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

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