use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class ClusteredServiceAgent method onTakeSnapshot.
private long onTakeSnapshot(final long logPosition, final long leadershipTermId) {
try (AeronArchive archive = AeronArchive.connect(ctx.archiveContext().clone());
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(publication.sessionId(), counters, archive);
final long recordingId = RecordingPos.getRecordingId(counters, counterId);
snapshotState(publication, logPosition, leadershipTermId);
checkForClockTick();
archive.checkForErrorResponse();
service.onTakeSnapshot(publication);
awaitRecordingComplete(recordingId, publication.position(), counters, counterId, archive);
return recordingId;
} catch (final ArchiveException ex) {
if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
throw new AgentTerminationException(ex);
}
throw ex;
}
}
use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class ArchiveAuthenticationTest method shouldNotBeAbleToConnectWithRejectOnConnectRequest.
@Test
@InterruptAfter(10)
public void shouldNotBeAbleToConnectWithRejectOnConnectRequest() {
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() {
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) {
fail();
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.reject();
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
fail();
}
});
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 BasicArchiveTest method purgeRecordingFailsIfThereAreActiveReplays.
@Test
@InterruptAfter(10)
@SuppressWarnings("try")
public void purgeRecordingFailsIfThereAreActiveReplays() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
}
aeronArchive.stopRecording(subscriptionId);
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
assertEquals(stopPosition, aeronArchive.getStopPosition(recordingIdFromCounter));
final long position = 0L;
final long length = stopPosition - position;
try (Subscription ignore = aeronArchive.replay(recordingId, position, length, REPLAY_CHANNEL, REPLAY_STREAM_ID)) {
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge recording with active replay " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
}
use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class BasicArchiveTest method purgeRecordingFailsIfRecordingIsActive.
@Test
@InterruptAfter(10)
public void purgeRecordingFailsIfRecordingIsActive() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long stopPosition;
final long subscriptionId = aeronArchive.startRecording(RECORDED_CHANNEL, RECORDED_STREAM_ID, LOCAL);
try {
final long recordingIdFromCounter;
final int sessionId;
try (Subscription subscription = aeron.addSubscription(RECORDED_CHANNEL, RECORDED_STREAM_ID);
Publication publication = aeron.addPublication(RECORDED_CHANNEL, RECORDED_STREAM_ID)) {
sessionId = publication.sessionId();
final CountersReader counters = aeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, sessionId);
recordingIdFromCounter = RecordingPos.getRecordingId(counters, counterId);
assertEquals(CommonContext.IPC_CHANNEL, RecordingPos.getSourceIdentity(counters, counterId));
offer(publication, messageCount, messagePrefix);
consume(subscription, messageCount, messagePrefix);
stopPosition = publication.position();
awaitPosition(counters, counterId, stopPosition);
final long joinPosition = subscription.imageBySessionId(sessionId).joinPosition();
assertEquals(joinPosition, aeronArchive.getStartPosition(recordingIdFromCounter));
assertEquals(stopPosition, aeronArchive.getRecordingPosition(recordingIdFromCounter));
assertEquals(NULL_VALUE, aeronArchive.getStopPosition(recordingIdFromCounter));
final long recordingId = aeronArchive.findLastMatchingRecording(0, "alias=" + RECORDED_CHANNEL_ALIAS, RECORDED_STREAM_ID, sessionId);
assertEquals(recordingIdFromCounter, recordingId);
final ArchiveException exception = assertThrows(ArchiveException.class, () -> aeronArchive.purgeRecording(recordingId));
assertThat(exception.getMessage(), endsWith("error: cannot purge active recording " + recordingId));
final String[] segmentFiles = Catalog.listSegmentFiles(archiveDir, recordingId);
assertNotNull(segmentFiles);
assertNotEquals(0, segmentFiles.length);
for (final String segmentFile : segmentFiles) {
assertTrue(new File(archiveDir, segmentFile).exists());
}
}
} finally {
aeronArchive.stopRecording(subscriptionId);
}
}
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()));
}
Aggregations