Search in sources :

Example 6 with ErrorHandler

use of org.agrona.ErrorHandler in project Aeron by real-logic.

the class MultiDestinationCastTest method addDestinationWithSpySubscriptionsShouldFailWithRegistrationException.

@Test
@InterruptAfter(10)
void addDestinationWithSpySubscriptionsShouldFailWithRegistrationException() {
    final ErrorHandler mockErrorHandler = mock(ErrorHandler.class);
    launch(mockErrorHandler);
    publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
    final RegistrationException registrationException = assertThrows(RegistrationException.class, () -> publication.addDestination(CommonContext.SPY_PREFIX + PUB_MDC_DYNAMIC_URI));
    assertThat(registrationException.getMessage(), containsString("spies are invalid"));
}
Also used : ErrorHandler(org.agrona.ErrorHandler) RegistrationException(io.aeron.exceptions.RegistrationException) Test(org.junit.jupiter.api.Test)

Example 7 with ErrorHandler

use of org.agrona.ErrorHandler in project aeron by real-logic.

the class MultiDestinationCastTest method addDestinationWithSpySubscriptionsShouldFailWithRegistrationException.

@Test
@InterruptAfter(10)
void addDestinationWithSpySubscriptionsShouldFailWithRegistrationException() {
    final ErrorHandler mockErrorHandler = mock(ErrorHandler.class);
    launch(mockErrorHandler);
    publication = clientA.addPublication(PUB_MDC_MANUAL_URI, STREAM_ID);
    final RegistrationException registrationException = assertThrows(RegistrationException.class, () -> publication.addDestination(CommonContext.SPY_PREFIX + PUB_MDC_DYNAMIC_URI));
    assertThat(registrationException.getMessage(), containsString("spies are invalid"));
}
Also used : ErrorHandler(org.agrona.ErrorHandler) RegistrationException(io.aeron.exceptions.RegistrationException) Test(org.junit.jupiter.api.Test)

Example 8 with ErrorHandler

use of org.agrona.ErrorHandler in project aeron by real-logic.

the class ClientErrorHandlerTest method shouldHaveCorrectTermBufferLength.

@Test
@InterruptAfter(10)
@SuppressWarnings("try")
void shouldHaveCorrectTermBufferLength() {
    final MediaDriver.Context ctx = new MediaDriver.Context().errorHandler(Tests::onError).dirDeleteOnStart(true);
    final ErrorHandler mockErrorHandlerOne = mock(ErrorHandler.class);
    final Aeron.Context clientCtxOne = new Aeron.Context().errorHandler(mockErrorHandlerOne);
    final ErrorHandler mockErrorHandlerTwo = mock(ErrorHandler.class);
    final Aeron.Context clientCtxTwo = new Aeron.Context().errorHandler(mockErrorHandlerTwo).subscriberErrorHandler(RethrowingErrorHandler.INSTANCE);
    try (TestMediaDriver ignore = TestMediaDriver.launch(ctx, testWatcher);
        Aeron aeronOne = Aeron.connect(clientCtxOne);
        Aeron aeronTwo = Aeron.connect(clientCtxTwo);
        Publication publication = aeronOne.addPublication(CHANNEL, STREAM_ID);
        Subscription subscriptionOne = aeronOne.addSubscription(CHANNEL, STREAM_ID);
        Subscription subscriptionTwo = aeronTwo.addSubscription(CHANNEL, STREAM_ID)) {
        awaitConnected(subscriptionOne);
        awaitConnected(subscriptionTwo);
        assertEquals(clientCtxOne.errorHandler(), clientCtxOne.subscriberErrorHandler());
        assertNotEquals(clientCtxTwo.errorHandler(), clientCtxTwo.subscriberErrorHandler());
        final UnsafeBuffer buffer = new UnsafeBuffer(new byte[100]);
        while (publication.offer(buffer) < 0) {
            Tests.yield();
        }
        final RuntimeException expectedException = new RuntimeException("Expected");
        final FragmentHandler handler = (buffer1, offset, length, header) -> {
            throw expectedException;
        };
        while (0 == subscriptionOne.poll(handler, 1)) {
            Tests.yield();
        }
        verify(mockErrorHandlerOne).onError(expectedException);
        try {
            while (0 == subscriptionTwo.poll(handler, 1)) {
                Tests.yield();
            }
            fail("Expected exception");
        } catch (final Exception ex) {
            assertEquals(expectedException, ex);
        }
        verify(mockErrorHandlerTwo, never()).onError(any());
    } finally {
        ctx.deleteDirectory();
    }
}
Also used : MediaDriver(io.aeron.driver.MediaDriver) SystemTestWatcher(io.aeron.test.SystemTestWatcher) Tests(io.aeron.test.Tests) ErrorHandler(org.agrona.ErrorHandler) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) Mockito(org.mockito.Mockito) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) FragmentHandler(io.aeron.logbuffer.FragmentHandler) Tests.awaitConnected(io.aeron.test.Tests.awaitConnected) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) ErrorHandler(org.agrona.ErrorHandler) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) TestMediaDriver(io.aeron.test.driver.TestMediaDriver) FragmentHandler(io.aeron.logbuffer.FragmentHandler) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 9 with ErrorHandler

use of org.agrona.ErrorHandler in project aeron by real-logic.

the class AsyncResourceTest method shouldDetectInvalidUri.

@Test
@Timeout(10)
void shouldDetectInvalidUri() {
    final ErrorHandler mockClientErrorHandler = mock(ErrorHandler.class);
    final Aeron.Context clientCtx = new Aeron.Context().errorHandler(mockClientErrorHandler);
    try (Aeron aeron = Aeron.connect(clientCtx)) {
        testWatcher.ignoreErrorsMatching((s) -> s.contains("Aeron URIs must start with") || s.contains("invalid channel"));
        final long registrationId = aeron.asyncAddPublication("invalid" + AERON_IPC, STREAM_ID);
        verify(mockClientErrorHandler, timeout(5000)).onError(any(RegistrationException.class));
        assertFalse(aeron.isCommandActive(registrationId));
        assertFalse(aeron.hasActiveCommands());
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) RegistrationException(io.aeron.exceptions.RegistrationException) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 10 with ErrorHandler

use of org.agrona.ErrorHandler in project aeron by real-logic.

the class AeronArchive method close.

/**
 * Notify the archive that this control session is closed, so it can promptly release resources then close the
 * local resources associated with the client.
 */
public void close() {
    lock.lock();
    try {
        if (!isClosed) {
            isClosed = true;
            final ErrorHandler errorHandler = context.errorHandler();
            if (archiveProxy.publication().isConnected()) {
                CloseHelper.close(errorHandler, () -> archiveProxy.closeSession(controlSessionId));
            }
            if (!context.ownsAeronClient()) {
                CloseHelper.close(errorHandler, archiveProxy.publication());
                CloseHelper.close(errorHandler, controlResponsePoller.subscription());
            }
            context.close();
        }
    } finally {
        lock.unlock();
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler)

Aggregations

ErrorHandler (org.agrona.ErrorHandler)30 Test (org.junit.jupiter.api.Test)18 MediaDriver (io.aeron.driver.MediaDriver)10 RegistrationException (io.aeron.exceptions.RegistrationException)6 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)6 Archive (io.aeron.archive.Archive)4 SlowTest (io.aeron.test.SlowTest)4 TestMediaDriver (io.aeron.test.driver.TestMediaDriver)4 DistinctErrorLog (org.agrona.concurrent.errors.DistinctErrorLog)4 LoggingErrorHandler (org.agrona.concurrent.errors.LoggingErrorHandler)4 Timeout (org.junit.jupiter.api.Timeout)4 AeronException (io.aeron.exceptions.AeronException)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 InterruptAfter (io.aeron.test.InterruptAfter)2 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)2 SystemTestWatcher (io.aeron.test.SystemTestWatcher)2 Tests (io.aeron.test.Tests)2 Tests.awaitConnected (io.aeron.test.Tests.awaitConnected)2 MutableReference (org.agrona.collections.MutableReference)2 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2