Search in sources :

Example 6 with ReadableCounter

use of io.aeron.status.ReadableCounter in project Aeron by real-logic.

the class CounterTest method shouldCloseReadableCounterOnUnavailableCounter.

@Test
@InterruptAfter(10)
void shouldCloseReadableCounterOnUnavailableCounter() {
    clientB.addAvailableCounterHandler(this::createReadableCounter);
    clientB.addUnavailableCounterHandler(this::unavailableCounterHandler);
    final Counter counter = clientA.addCounter(COUNTER_TYPE_ID, keyBuffer, 0, keyBuffer.capacity(), labelBuffer, 0, COUNTER_LABEL.length());
    while (null == readableCounter) {
        Tests.sleep(1);
    }
    assertFalse(readableCounter.isClosed());
    assertEquals(CountersReader.RECORD_ALLOCATED, readableCounter.state());
    counter.close();
    while (!readableCounter.isClosed()) {
        Tests.sleep(1);
    }
    while (clientA.hasActiveCommands()) {
        Tests.sleep(1);
    }
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 7 with ReadableCounter

use of io.aeron.status.ReadableCounter in project aeron by real-logic.

the class ConsensusModuleAgent method tryCreateAppendPosition.

private boolean tryCreateAppendPosition(final int logSessionId) {
    final CountersReader counters = aeron.countersReader();
    final int counterId = RecordingPos.findCounterIdBySession(counters, logSessionId);
    if (CountersReader.NULL_COUNTER_ID == counterId) {
        return false;
    }
    final long registrationId = counters.getCounterRegistrationId(counterId);
    if (0 == registrationId) {
        return false;
    }
    logRecordingId = RecordingPos.getRecordingId(counters, counterId);
    appendPosition = new ReadableCounter(counters, registrationId, counterId);
    logRecordedPosition = NULL_POSITION;
    return true;
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 8 with ReadableCounter

use of io.aeron.status.ReadableCounter in project aeron by real-logic.

the class CounterTest method shouldBeAbleToAddReadableCounterWithinHandler.

@Test
@InterruptAfter(10)
void shouldBeAbleToAddReadableCounterWithinHandler() {
    clientB.addAvailableCounterHandler(this::createReadableCounter);
    final Counter counter = clientA.addCounter(COUNTER_TYPE_ID, keyBuffer, 0, keyBuffer.capacity(), labelBuffer, 0, COUNTER_LABEL.length());
    while (null == readableCounter) {
        Tests.sleep(1);
    }
    assertEquals(CountersReader.RECORD_ALLOCATED, readableCounter.state());
    assertEquals(counter.id(), readableCounter.counterId());
    assertEquals(counter.registrationId(), readableCounter.registrationId());
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 9 with ReadableCounter

use of io.aeron.status.ReadableCounter in project aeron by real-logic.

the class CounterTest method shouldCloseReadableCounterOnUnavailableCounter.

@Test
@InterruptAfter(10)
void shouldCloseReadableCounterOnUnavailableCounter() {
    clientB.addAvailableCounterHandler(this::createReadableCounter);
    clientB.addUnavailableCounterHandler(this::unavailableCounterHandler);
    final Counter counter = clientA.addCounter(COUNTER_TYPE_ID, keyBuffer, 0, keyBuffer.capacity(), labelBuffer, 0, COUNTER_LABEL.length());
    while (null == readableCounter) {
        Tests.sleep(1);
    }
    assertFalse(readableCounter.isClosed());
    assertEquals(CountersReader.RECORD_ALLOCATED, readableCounter.state());
    counter.close();
    while (!readableCounter.isClosed()) {
        Tests.sleep(1);
    }
    while (clientA.hasActiveCommands()) {
        Tests.sleep(1);
    }
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

ReadableCounter (io.aeron.status.ReadableCounter)9 InterruptAfter (io.aeron.test.InterruptAfter)4 CountersReader (org.agrona.concurrent.status.CountersReader)4 Test (org.junit.jupiter.api.Test)4