Search in sources :

Example 1 with ExpandableArrayBuffer

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

the class FileSender method sendFileCreate.

private static void sendFileCreate(final Publication publication, final long correlationId, final int length, final String filename) {
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
    buffer.putInt(VERSION_OFFSET, VERSION, LITTLE_ENDIAN);
    buffer.putInt(TYPE_OFFSET, FILE_CREATE_TYPE, LITTLE_ENDIAN);
    buffer.putLong(CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN);
    buffer.putLong(FILE_LENGTH_OFFSET, length, LITTLE_ENDIAN);
    final int msgLength = FILE_NAME_OFFSET + buffer.putStringUtf8(FILE_NAME_OFFSET, filename);
    long result;
    while ((result = publication.offer(buffer, 0, msgLength)) < 0) {
        checkResult(result);
        Thread.yield();
    }
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 2 with ExpandableArrayBuffer

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

the class BasicArchiveTest method offer.

private static void offer(final Publication publication, final int count, final String prefix) {
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
    for (int i = 0; i < count; i++) {
        final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);
        while (publication.offer(buffer, 0, length) <= 0) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 3 with ExpandableArrayBuffer

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

the class ExtendRecordingTest method offer.

private static void offer(final Publication publication, final int startIndex, final int count, final String prefix) {
    final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
    for (int i = startIndex; i < (startIndex + count); i++) {
        final int length = buffer.putStringWithoutLengthAscii(0, prefix + i);
        while (publication.offer(buffer, 0, length) <= 0) {
            SystemTest.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer)

Example 4 with ExpandableArrayBuffer

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

the class ClusterNodeTest method shouldScheduleEventInService.

@Test(timeout = 10_000)
public void shouldScheduleEventInService() {
    container = launchTimedService();
    aeronCluster = connectToCluster();
    final Aeron aeron = aeronCluster.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    final Publication publication = aeronCluster.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
        TestUtil.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger messageCount = new MutableInteger();
    final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {

        public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertThat(correlationId, is(msgCorrelationId));
            assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg + "-scheduled"));
            messageCount.value += 1;
        }
    }, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
    while (messageCount.get() == 0) {
        if (adapter.poll() <= 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Example 5 with ExpandableArrayBuffer

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

the class ClusterNodeTest method shouldEchoMessageViaService.

@Test(timeout = 10_000)
public void shouldEchoMessageViaService() {
    container = launchEchoService();
    aeronCluster = connectToCluster();
    final Aeron aeron = aeronCluster.context().aeron();
    final SessionDecorator sessionDecorator = new SessionDecorator(aeronCluster.clusterSessionId());
    final Publication publication = aeronCluster.ingressPublication();
    final ExpandableArrayBuffer msgBuffer = new ExpandableArrayBuffer();
    final long msgCorrelationId = aeron.nextCorrelationId();
    final String msg = "Hello World!";
    msgBuffer.putStringWithoutLengthAscii(0, msg);
    while (sessionDecorator.offer(publication, msgCorrelationId, msgBuffer, 0, msg.length()) < 0) {
        TestUtil.checkInterruptedStatus();
        Thread.yield();
    }
    final MutableInteger messageCount = new MutableInteger();
    final EgressAdapter adapter = new EgressAdapter(new StubEgressListener() {

        public void onMessage(final long correlationId, final long clusterSessionId, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
            assertThat(correlationId, is(msgCorrelationId));
            assertThat(buffer.getStringWithoutLengthAscii(offset, length), is(msg));
            messageCount.value += 1;
        }
    }, aeronCluster.egressSubscription(), FRAGMENT_LIMIT);
    while (messageCount.get() == 0) {
        if (adapter.poll() <= 0) {
            TestUtil.checkInterruptedStatus();
            Thread.yield();
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MutableInteger(org.agrona.collections.MutableInteger) Publication(io.aeron.Publication) SessionDecorator(io.aeron.cluster.client.SessionDecorator) Aeron(io.aeron.Aeron) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) EgressAdapter(io.aeron.cluster.client.EgressAdapter) Test(org.junit.Test)

Aggregations

ExpandableArrayBuffer (org.agrona.ExpandableArrayBuffer)21 Header (io.aeron.logbuffer.Header)11 DirectBuffer (org.agrona.DirectBuffer)11 ClusteredService (io.aeron.cluster.service.ClusteredService)10 AeronCluster (io.aeron.cluster.client.AeronCluster)9 ClientSession (io.aeron.cluster.service.ClientSession)9 StubClusteredService (io.aeron.test.cluster.StubClusteredService)8 Archive (io.aeron.archive.Archive)7 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)7 CLUSTER_MEMBERS (io.aeron.cluster.ClusterTestConstants.CLUSTER_MEMBERS)7 INGRESS_ENDPOINTS (io.aeron.cluster.ClusterTestConstants.INGRESS_ENDPOINTS)7 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)7 MediaDriver (io.aeron.driver.MediaDriver)7 ThreadingMode (io.aeron.driver.ThreadingMode)7 ClusterTests (io.aeron.test.cluster.ClusterTests)7 CloseHelper (org.agrona.CloseHelper)7 AfterEach (org.junit.jupiter.api.AfterEach)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 Test (org.junit.jupiter.api.Test)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7