Search in sources :

Example 46 with ArchiveException

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);
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) ArchiveException(io.aeron.archive.client.ArchiveException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 47 with ArchiveException

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

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