Search in sources :

Example 6 with ClusterException

use of io.aeron.cluster.client.ClusterException in project Aeron by real-logic.

the class LogReplication method isDone.

boolean isDone(final long nowNs) {
    if (position == stopPosition && isStopped) {
        return true;
    }
    if (position > stopPosition) {
        throw new ClusterException("log replication has progressed past stopPosition: " + this);
    }
    if (nowNs >= progressCheckDeadlineNs) {
        progressCheckDeadlineNs = nowNs + progressCheckIntervalNs;
        if (NULL_COUNTER_ID != recordingPositionCounterId) {
            final CountersReader counters = archive.context().aeron().countersReader();
            final long recordingPosition = counters.getCounterValue(recordingPositionCounterId);
            if (RecordingPos.isActive(counters, recordingPositionCounterId, recordingId) && recordingPosition > position) {
                position = recordingPosition;
                progressDeadlineNs = nowNs + progressCheckTimeoutNs;
            }
        }
    }
    if (nowNs >= progressDeadlineNs) {
        if (position < stopPosition) {
            throw new ClusterException("log replication has not progressed: " + this, AeronException.Category.WARN);
        } else {
            throw new ClusterException("log replication failed to stop: " + this);
        }
    }
    return false;
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 7 with ClusterException

use of io.aeron.cluster.client.ClusterException in project Aeron by real-logic.

the class ConsensusModuleContextTest method unknownTimerServiceSupplier.

@Test
void unknownTimerServiceSupplier() {
    final String supplierName = "unknown timer service supplier";
    System.setProperty(TIMER_SERVICE_SUPPLIER_PROP_NAME, supplierName);
    try {
        final ClusterException exception = assertThrows(ClusterException.class, context::conclude);
        assertEquals("ERROR - invalid TimerServiceSupplier: " + supplierName, exception.getMessage());
    } finally {
        System.clearProperty(TIMER_SERVICE_SUPPLIER_PROP_NAME);
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ClusterException

use of io.aeron.cluster.client.ClusterException in project Aeron by real-logic.

the class RecordingLogTest method shouldNotAllowInvalidateOfSnapshotWithoutParentTerm.

@Test
void shouldNotAllowInvalidateOfSnapshotWithoutParentTerm() {
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        recordingLog.appendSnapshot(-10, 1L, 0, 777L, 0, 0);
        recordingLog.appendSnapshot(-11, 1L, 0, 777L, 0, SERVICE_ID);
        final ClusterException ex = assertThrows(ClusterException.class, recordingLog::invalidateLatestSnapshot);
        assertEquals("ERROR - no matching term for snapshot: leadershipTermId=1", ex.getMessage());
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test)

Example 9 with ClusterException

use of io.aeron.cluster.client.ClusterException in project Aeron by real-logic.

the class RecordingLogTest method appendTermShouldRejectNullValueAsRecordingId.

@Test
void appendTermShouldRejectNullValueAsRecordingId() {
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        final ClusterException exception = assertThrows(ClusterException.class, () -> recordingLog.appendTerm(NULL_VALUE, 0, 0, 0));
        assertEquals("ERROR - invalid recordingId=-1", exception.getMessage());
        assertEquals(0, recordingLog.entries().size());
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test)

Example 10 with ClusterException

use of io.aeron.cluster.client.ClusterException in project Aeron by real-logic.

the class RecordingLogTest method appendTermShouldNotAcceptDifferentRecordingIds.

@Test
void appendTermShouldNotAcceptDifferentRecordingIds() {
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        recordingLog.appendTerm(42, 0, 0, 0);
        final ClusterException exception = assertThrows(ClusterException.class, () -> recordingLog.appendTerm(21, 1, 0, 0));
        assertEquals("ERROR - invalid TERM recordingId=21, expected recordingId=42", exception.getMessage());
        assertEquals(1, recordingLog.entries().size());
    }
    try (RecordingLog recordingLog = new RecordingLog(tempDir, true)) {
        final ClusterException exception = assertThrows(ClusterException.class, () -> recordingLog.appendTerm(-5, -5, -5, -5));
        assertEquals("ERROR - invalid TERM recordingId=-5, expected recordingId=42", exception.getMessage());
        assertEquals(1, recordingLog.entries().size());
    }
}
Also used : ClusterException(io.aeron.cluster.client.ClusterException) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterException (io.aeron.cluster.client.ClusterException)34 Test (org.junit.jupiter.api.Test)12 AgentTerminationException (org.agrona.concurrent.AgentTerminationException)6 CountersReader (org.agrona.concurrent.status.CountersReader)4 AeronException (io.aeron.exceptions.AeronException)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ByteBuffer (java.nio.ByteBuffer)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 FileChannel (java.nio.channels.FileChannel)2 Path (java.nio.file.Path)2 TimeUnit (java.util.concurrent.TimeUnit)2 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2