use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class Catalog method growCatalog.
void growCatalog(final long maxCatalogCapacity, final int frameLength) {
final long oldCapacity = capacity;
final long recordingOffset = nextRecordingDescriptorOffset;
final long targetCapacity = recordingOffset + frameLength;
if (targetCapacity > maxCatalogCapacity) {
if (maxCatalogCapacity == oldCapacity) {
throw new ArchiveException("catalog is full, max capacity reached: " + maxCatalogCapacity);
} else {
throw new ArchiveException("recording is too big: total recording length is " + frameLength + " bytes," + " available space is " + (maxCatalogCapacity - recordingOffset) + " bytes");
}
}
long newCapacity = oldCapacity;
while (newCapacity < targetCapacity) {
newCapacity = min(newCapacity + (newCapacity >> 1), maxCatalogCapacity);
}
final MappedByteBuffer mappedByteBuffer;
try {
unmapAndCloseChannel();
catalogChannel = FileChannel.open(catalogFile.toPath(), READ, WRITE, SPARSE);
mappedByteBuffer = catalogChannel.map(READ_WRITE, 0, newCapacity);
} catch (final Exception ex) {
close();
LangUtil.rethrowUnchecked(ex);
return;
}
capacity = newCapacity;
initBuffers(mappedByteBuffer);
final UnsafeBuffer catalogHeaderBuffer = new UnsafeBuffer(catalogByteBuffer);
catalogHeaderDecoder.wrap(catalogHeaderBuffer, 0, CatalogHeaderDecoder.BLOCK_LENGTH, CatalogHeaderDecoder.SCHEMA_VERSION);
catalogHeaderEncoder.wrap(catalogHeaderBuffer, 0);
catalogResized(oldCapacity, newCapacity);
}
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 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");
}
Aggregations