Search in sources :

Example 6 with DriverEventCode

use of io.aeron.agent.DriverEventCode in project aeron by real-logic.

the class DriverEventLoggerTest method logString.

@Test
void logString() {
    final int recordOffset = align(100, ALIGNMENT);
    logBuffer.putLong(CAPACITY + TAIL_POSITION_OFFSET, recordOffset);
    final DriverEventCode eventCode = CMD_IN_ADD_PUBLICATION;
    final String value = "abc";
    final int captureLength = value.length() + SIZE_OF_INT;
    logger.logString(eventCode, value);
    verifyLogHeader(logBuffer, recordOffset, toEventCodeId(eventCode), captureLength, captureLength);
    assertEquals(value, logBuffer.getStringAscii(encodedMsgOffset(recordOffset + LOG_HEADER_LENGTH), LITTLE_ENDIAN));
}
Also used : DriverEventCode(io.aeron.agent.DriverEventCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with DriverEventCode

use of io.aeron.agent.DriverEventCode in project Aeron by real-logic.

the class DriverEventLoggerTest method logAddress.

@Test
void logAddress() {
    final int recordOffset = 64;
    logBuffer.putLong(CAPACITY + TAIL_POSITION_OFFSET, recordOffset);
    final DriverEventCode eventCode = NAME_RESOLUTION_NEIGHBOR_REMOVED;
    final int captureLength = 12;
    logger.logAddress(eventCode, new InetSocketAddress("localhost", 5656));
    verifyLogHeader(logBuffer, recordOffset, toEventCodeId(eventCode), captureLength, captureLength);
    assertEquals(5656, logBuffer.getInt(encodedMsgOffset(recordOffset + LOG_HEADER_LENGTH), LITTLE_ENDIAN));
    assertEquals(4, logBuffer.getInt(encodedMsgOffset(recordOffset + LOG_HEADER_LENGTH + SIZE_OF_INT), LITTLE_ENDIAN));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DriverEventCode(io.aeron.agent.DriverEventCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with DriverEventCode

use of io.aeron.agent.DriverEventCode in project Aeron by real-logic.

the class DriverLoggingAgentTest method testLogMediaDriverEvents.

private void testLogMediaDriverEvents(final String channel, final String enabledEvents, final EnumSet<DriverEventCode> expectedEvents) {
    before(enabledEvents, expectedEvents);
    final MediaDriver.Context driverCtx = new MediaDriver.Context().errorHandler(Tests::onError).publicationLingerTimeoutNs(0).timerIntervalNs(TimeUnit.MILLISECONDS.toNanos(1));
    try (MediaDriver mediaDriver = MediaDriver.launch(driverCtx)) {
        try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
            Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
            Publication publication = aeron.addPublication(channel, STREAM_ID)) {
            final UnsafeBuffer offerBuffer = new UnsafeBuffer(new byte[32]);
            while (publication.offer(offerBuffer) < 0) {
                Tests.yield();
            }
            final MutableInteger counter = new MutableInteger();
            final FragmentHandler handler = (buffer, offset, length, header) -> counter.value++;
            while (0 == subscription.poll(handler, 1)) {
                Tests.yield();
            }
            assertEquals(counter.get(), 1);
        }
        final Supplier<String> errorMessage = () -> "Pending events: " + WAIT_LIST;
        while (!WAIT_LIST.isEmpty()) {
            Tests.yieldingIdle(errorMessage);
        }
    }
}
Also used : Tests(io.aeron.test.Tests) DriverEventCode(io.aeron.agent.DriverEventCode) Subscription(io.aeron.Subscription) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) EnumSource(org.junit.jupiter.params.provider.EnumSource) Supplier(java.util.function.Supplier) Collections.synchronizedSet(java.util.Collections.synchronizedSet) MessageHandler(org.agrona.concurrent.MessageHandler) EVENT_READER_FRAME_LIMIT(io.aeron.agent.EventConfiguration.EVENT_READER_FRAME_LIMIT) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EVENT_RING_BUFFER(io.aeron.agent.EventConfiguration.EVENT_RING_BUFFER) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Publication(io.aeron.Publication) Agent(org.agrona.concurrent.Agent) MutableInteger(org.agrona.collections.MutableInteger) EnumSet(java.util.EnumSet) MediaDriver(io.aeron.driver.MediaDriver) Aeron(io.aeron.Aeron) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) EnumMap(java.util.EnumMap) Set(java.util.Set) IPC_CHANNEL(io.aeron.CommonContext.IPC_CHANNEL) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) InterruptAfter(io.aeron.test.InterruptAfter) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) INCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.INCLUDE) MutableDirectBuffer(org.agrona.MutableDirectBuffer) FragmentHandler(io.aeron.logbuffer.FragmentHandler) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) Tests(io.aeron.test.Tests) Aeron(io.aeron.Aeron) MediaDriver(io.aeron.driver.MediaDriver) FragmentHandler(io.aeron.logbuffer.FragmentHandler) Subscription(io.aeron.Subscription) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 9 with DriverEventCode

use of io.aeron.agent.DriverEventCode in project aeron by real-logic.

the class DriverEventLoggerTest method log.

@Test
void log() {
    final DriverEventCode eventCode = CMD_IN_TERMINATE_DRIVER;
    DRIVER_EVENT_CODES.add(eventCode);
    final int recordOffset = align(13, ALIGNMENT);
    logBuffer.putLong(CAPACITY + TAIL_POSITION_OFFSET, recordOffset);
    final int length = 100;
    final int srcOffset = 20;
    buffer.setMemory(srcOffset, length, (byte) 5);
    logger.log(eventCode, buffer, srcOffset, length);
    verifyLogHeader(logBuffer, recordOffset, toEventCodeId(eventCode), length, length);
    for (int i = 0; i < length; i++) {
        assertEquals(5, logBuffer.getByte(encodedMsgOffset(recordOffset + LOG_HEADER_LENGTH + i)));
    }
}
Also used : DriverEventCode(io.aeron.agent.DriverEventCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with DriverEventCode

use of io.aeron.agent.DriverEventCode in project aeron by real-logic.

the class DriverEventDissectorTest method dissectCommandUnknown.

@Test
void dissectCommandUnknown() {
    final DriverEventCode eventCode = SEND_CHANNEL_CREATION;
    internalEncodeLogHeader(buffer, 0, 5, 5, () -> 1_000_000_000L);
    dissectCommand(eventCode, buffer, 0, builder);
    assertEquals("[1.0] " + CONTEXT + ": " + eventCode.name() + " [5/5]: COMMAND_UNKNOWN: " + eventCode, builder.toString());
}
Also used : DriverEventCode(io.aeron.agent.DriverEventCode) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DriverEventCode (io.aeron.agent.DriverEventCode)10 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Aeron (io.aeron.Aeron)2 IPC_CHANNEL (io.aeron.CommonContext.IPC_CHANNEL)2 Publication (io.aeron.Publication)2 Subscription (io.aeron.Subscription)2 EVENT_READER_FRAME_LIMIT (io.aeron.agent.EventConfiguration.EVENT_READER_FRAME_LIMIT)2 EVENT_RING_BUFFER (io.aeron.agent.EventConfiguration.EVENT_RING_BUFFER)2 MediaDriver (io.aeron.driver.MediaDriver)2 FragmentHandler (io.aeron.logbuffer.FragmentHandler)2 InterruptAfter (io.aeron.test.InterruptAfter)2 InterruptingTestCallback (io.aeron.test.InterruptingTestCallback)2 Tests (io.aeron.test.Tests)2 InetSocketAddress (java.net.InetSocketAddress)2 Collections.synchronizedSet (java.util.Collections.synchronizedSet)2 EnumMap (java.util.EnumMap)2 EnumSet (java.util.EnumSet)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2