Search in sources :

Example 31 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class CatalogTest method shouldThrowExceptionAfterFailureOnPageStraddle.

@Test
void shouldThrowExceptionAfterFailureOnPageStraddle() throws Exception {
    final long newRecordingId = newRecording();
    final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 0));
    try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
        final ByteBuffer bb = allocate(HEADER_LENGTH);
        final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
        flyweight.frameLength(PAGE_SIZE - 128);
        log.write(bb);
        bb.clear();
        flyweight.frameLength(256);
        log.write(bb, PAGE_SIZE - 128);
        bb.clear();
        bb.put(0, (byte) 0).limit(1).position(0);
        log.write(bb, PAGE_SIZE + 127);
    }
    final ArchiveException exception = assertThrows(ArchiveException.class, () -> {
        final Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer);
        catalog.close();
    });
    assertThat(exception.getMessage(), containsString(segmentFile.getAbsolutePath()));
}
Also used : FileChannel(java.nio.channels.FileChannel) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) ArchiveException(io.aeron.archive.client.ArchiveException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class ConsensusModuleAgent method takeSnapshot.

private void takeSnapshot(final long timestamp, final long logPosition, final ServiceAck[] serviceAcks) {
    final long recordingId;
    try (ExclusivePublication publication = aeron.addExclusivePublication(ctx.snapshotChannel(), ctx.snapshotStreamId())) {
        final String channel = ChannelUri.addSessionId(ctx.snapshotChannel(), publication.sessionId());
        archive.startRecording(channel, ctx.snapshotStreamId(), LOCAL, true);
        final CountersReader counters = aeron.countersReader();
        final int counterId = awaitRecordingCounter(counters, publication.sessionId());
        recordingId = RecordingPos.getRecordingId(counters, counterId);
        snapshotState(publication, logPosition, replayLeadershipTermId);
        awaitRecordingComplete(recordingId, publication.position(), counters, counterId);
    } catch (final ArchiveException ex) {
        if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
            ctx.countedErrorHandler().onError(ex);
            unexpectedTermination();
        }
        throw ex;
    }
    final long termBaseLogPosition = recordingLog.getTermEntry(replayLeadershipTermId).termBaseLogPosition;
    for (int serviceId = serviceAcks.length - 1; serviceId >= 0; serviceId--) {
        final long snapshotId = serviceAcks[serviceId].relevantId();
        recordingLog.appendSnapshot(snapshotId, replayLeadershipTermId, termBaseLogPosition, logPosition, timestamp, serviceId);
    }
    recordingLog.appendSnapshot(recordingId, replayLeadershipTermId, termBaseLogPosition, logPosition, timestamp, SERVICE_ID);
    recordingLog.force(ctx.fileSyncLevel());
    recoveryPlan = recordingLog.createRecoveryPlan(archive, ctx.serviceCount(), Aeron.NULL_VALUE);
    ctx.snapshotCounter().incrementOrdered();
    final long nowNs = clusterClock.timeNanos();
    for (final ClusterSession session : sessionByIdMap.values()) {
        session.timeOfLastActivityNs(nowNs);
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 33 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class ArchiveAuthenticationTest method shouldNotBeAbleToConnectWithRejectOnChallengeResponse.

@Test
@InterruptAfter(10)
public void shouldNotBeAbleToConnectWithRejectOnChallengeResponse() {
    final MutableLong authenticatorSessionId = new MutableLong(-1L);
    final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {

        public byte[] encodedCredentials() {
            return NULL_CREDENTIAL;
        }

        public byte[] onChallenge(final byte[] encodedChallenge) {
            assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
            return encodedCredentials;
        }
    });
    final Authenticator authenticator = spy(new Authenticator() {

        boolean challengeRespondedTo = false;

        public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            authenticatorSessionId.value = sessionId;
            assertEquals(0, encodedCredentials.length);
        }

        public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
            assertEquals(sessionId, authenticatorSessionId.value);
            assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
            challengeRespondedTo = true;
        }

        public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
            assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
            sessionProxy.challenge(encodedChallenge);
        }

        public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
            if (challengeRespondedTo) {
                assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
                sessionProxy.reject();
            }
        }
    });
    launchArchivingMediaDriver(() -> authenticator);
    try {
        connectClient(credentialsSupplier);
    } catch (final ArchiveException ex) {
        assertEquals(ArchiveException.AUTHENTICATION_REJECTED, ex.errorCode());
        return;
    }
    fail("should have seen exception");
}
Also used : MutableLong(org.agrona.collections.MutableLong) CredentialsSupplier(io.aeron.security.CredentialsSupplier) SessionProxy(io.aeron.security.SessionProxy) ArchiveException(io.aeron.archive.client.ArchiveException) Authenticator(io.aeron.security.Authenticator) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 34 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class ConsensusModuleAgent method takeSnapshot.

private void takeSnapshot(final long timestamp, final long logPosition, final ServiceAck[] serviceAcks) {
    final long recordingId;
    try (ExclusivePublication publication = aeron.addExclusivePublication(ctx.snapshotChannel(), ctx.snapshotStreamId())) {
        final String channel = ChannelUri.addSessionId(ctx.snapshotChannel(), publication.sessionId());
        archive.startRecording(channel, ctx.snapshotStreamId(), LOCAL, true);
        final CountersReader counters = aeron.countersReader();
        final int counterId = awaitRecordingCounter(counters, publication.sessionId());
        recordingId = RecordingPos.getRecordingId(counters, counterId);
        snapshotState(publication, logPosition, replayLeadershipTermId);
        awaitRecordingComplete(recordingId, publication.position(), counters, counterId);
    } catch (final ArchiveException ex) {
        if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
            ctx.countedErrorHandler().onError(ex);
            unexpectedTermination();
        }
        throw ex;
    }
    final long termBaseLogPosition = recordingLog.getTermEntry(replayLeadershipTermId).termBaseLogPosition;
    for (int serviceId = serviceAcks.length - 1; serviceId >= 0; serviceId--) {
        final long snapshotId = serviceAcks[serviceId].relevantId();
        recordingLog.appendSnapshot(snapshotId, replayLeadershipTermId, termBaseLogPosition, logPosition, timestamp, serviceId);
    }
    recordingLog.appendSnapshot(recordingId, replayLeadershipTermId, termBaseLogPosition, logPosition, timestamp, SERVICE_ID);
    recordingLog.force(ctx.fileSyncLevel());
    recoveryPlan = recordingLog.createRecoveryPlan(archive, ctx.serviceCount(), Aeron.NULL_VALUE);
    ctx.snapshotCounter().incrementOrdered();
    final long nowNs = clusterClock.timeNanos();
    for (final ClusterSession session : sessionByIdMap.values()) {
        session.timeOfLastActivityNs(nowNs);
    }
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) CountersReader(org.agrona.concurrent.status.CountersReader)

Example 35 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.

the class ArchiveTest method shouldErrorWhenUnauthorised.

@Test
@InterruptAfter(10)
public void shouldErrorWhenUnauthorised() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final AuthorisationServiceSupplier authorisationServiceSupplier = () -> (protocolId, actionId, type, encodedPrincipal) -> {
        return actionId != TruncateRecordingRequestDecoder.TEMPLATE_ID;
    };
    final Archive.Context archiveCtx = new Archive.Context().deleteArchiveOnStart(true).authorisationServiceSupplier(authorisationServiceSupplier).threadingMode(SHARED);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
        AeronArchive archive = AeronArchive.connect()) {
        try {
            archive.truncateRecording(0, 0);
        } catch (final ArchiveException ex) {
            assertEquals(ArchiveException.UNAUTHORISED_ACTION, ex.errorCode());
            return;
        }
        fail("Expected exception");
    } finally {
        archiveCtx.deleteDirectory();
        driverCtx.deleteDirectory();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Aggregations

ArchiveException (io.aeron.archive.client.ArchiveException)48 Test (org.junit.jupiter.api.Test)26 File (java.io.File)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 InterruptAfter (io.aeron.test.InterruptAfter)12 Catalog (io.aeron.archive.Catalog)10 IOException (java.io.IOException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 ByteBuffer (java.nio.ByteBuffer)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 Context (io.aeron.archive.Archive.Context)6 Checksum (io.aeron.archive.checksum.Checksum)6 AeronArchive (io.aeron.archive.client.AeronArchive)6 MappedByteBuffer (java.nio.MappedByteBuffer)6 Aeron (io.aeron.Aeron)4 CommonContext (io.aeron.CommonContext)4 MediaDriver (io.aeron.driver.MediaDriver)4 FrameDescriptor (io.aeron.logbuffer.FrameDescriptor)4 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)4 Authenticator (io.aeron.security.Authenticator)4