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()));
}
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);
}
}
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");
}
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);
}
}
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();
}
}
Aggregations