Search in sources :

Example 26 with ErrorHandler

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

the class AuthorisationServiceTest method shouldForbidAllCommandsIfDenyAllIsUsed.

@Test
void shouldForbidAllCommandsIfDenyAllIsUsed() {
    final byte[] encodedCredentials = { 0x4, 0x5, 0x6 };
    final ErrorHandler errorHandler = mock(ErrorHandler.class);
    final int protocolId = 77;
    final int actionId = ThreadLocalRandom.current().nextInt();
    assertFalse(DENY_ALL.isAuthorised(protocolId, actionId, null, encodedCredentials));
    verifyNoInteractions(errorHandler);
}
Also used : ErrorHandler(org.agrona.ErrorHandler) Test(org.junit.jupiter.api.Test)

Example 27 with ErrorHandler

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

the class ArchivingMediaDriver method launch.

/**
 * Launch a new {@link ArchivingMediaDriver} with provided contexts.
 *
 * @param driverCtx  for configuring the {@link MediaDriver}.
 * @param archiveCtx for configuring the {@link Archive}.
 * @return a new {@link ArchivingMediaDriver} with the provided contexts.
 */
public static ArchivingMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx) {
    MediaDriver driver = null;
    Archive archive = null;
    try {
        driver = MediaDriver.launch(driverCtx);
        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
        final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
        archive = Archive.launch(archiveCtx.mediaDriverAgentInvoker(driver.sharedAgentInvoker()).aeronDirectoryName(driverCtx.aeronDirectoryName()).errorHandler(errorHandler).errorCounter(errorCounter));
        return new ArchivingMediaDriver(driver, archive);
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(archive, driver);
        throw ex;
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) MediaDriver(io.aeron.driver.MediaDriver) AtomicCounter(org.agrona.concurrent.status.AtomicCounter)

Example 28 with ErrorHandler

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

the class AsyncResourceTest method shouldDetectUnknownHost.

@Test
@SlowTest
@Timeout(60)
void shouldDetectUnknownHost() {
    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("unresolved"));
        final long registrationId = aeron.asyncAddPublication("aeron:udp?endpoint=wibble:1234", STREAM_ID);
        verify(mockClientErrorHandler, timeout(55_000)).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) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 29 with ErrorHandler

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

the class SingleNodeCluster method close.

/**
 * {@inheritDoc}
 */
public void close() {
    final ErrorHandler errorHandler = clusteredMediaDriver.mediaDriver().context().errorHandler();
    CloseHelper.close(errorHandler, client);
    CloseHelper.close(errorHandler, clientMediaDriver);
    CloseHelper.close(errorHandler, clusteredMediaDriver.consensusModule());
    CloseHelper.close(errorHandler, container);
    // ErrorHandler will be closed during that call so can't use it
    CloseHelper.close(clusteredMediaDriver);
}
Also used : ErrorHandler(org.agrona.ErrorHandler)

Example 30 with ErrorHandler

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

the class ReentrantClientTest method shouldThrowWhenReentering.

@Test
void shouldThrowWhenReentering() {
    final MutableReference<Throwable> expectedException = new MutableReference<>();
    final ErrorHandler errorHandler = expectedException::set;
    try (Aeron aeron = Aeron.connect(new Aeron.Context().errorHandler(errorHandler))) {
        final String channel = CommonContext.IPC_CHANNEL;
        final AvailableImageHandler mockHandler = mock(AvailableImageHandler.class);
        doAnswer((invocation) -> aeron.addSubscription(channel, 3)).when(mockHandler).onAvailableImage(any(Image.class));
        final Subscription sub = aeron.addSubscription(channel, 1001, mockHandler, null);
        final Publication pub = aeron.addPublication(channel, 1001);
        verify(mockHandler, timeout(5000L)).onAvailableImage(any(Image.class));
        pub.close();
        sub.close();
        assertThat(expectedException.get(), instanceOf(AeronException.class));
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) AeronException(io.aeron.exceptions.AeronException) MutableReference(org.agrona.collections.MutableReference) Test(org.junit.jupiter.api.Test)

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