Search in sources :

Example 1 with Context

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

the class AeronArchiveTest method closeOwningAeronClient.

@Test
void closeOwningAeronClient() {
    final long controlSessionId = 42;
    final Aeron.Context aeronContext = mock(Aeron.Context.class);
    when(aeronContext.nanoClock()).thenReturn(SystemNanoClock.INSTANCE);
    when(aeron.context()).thenReturn(aeronContext);
    final IllegalMonitorStateException aeronException = new IllegalMonitorStateException("aeron closed");
    doThrow(aeronException).when(aeron).close();
    final Publication publication = mock(Publication.class);
    when(publication.isConnected()).thenReturn(true);
    doThrow(new IllegalStateException("publication is closed")).when(publication).close();
    final Subscription subscription = mock(Subscription.class);
    when(controlResponsePoller.subscription()).thenReturn(subscription);
    doThrow(new IndexOutOfBoundsException("subscription")).when(subscription).close();
    when(archiveProxy.publication()).thenReturn(publication);
    final IndexOutOfBoundsException closeSessionException = new IndexOutOfBoundsException();
    when(archiveProxy.closeSession(controlSessionId)).thenThrow(closeSessionException);
    final Context context = new Context().aeron(aeron).idleStrategy(NoOpIdleStrategy.INSTANCE).messageTimeoutNs(100).lock(NoOpLock.INSTANCE).errorHandler(errorHandler).ownsAeronClient(true);
    final AeronArchive aeronArchive = new AeronArchive(context, controlResponsePoller, archiveProxy, controlSessionId);
    final IllegalMonitorStateException ex = assertThrows(IllegalMonitorStateException.class, aeronArchive::close);
    assertSame(aeronException, ex);
    final InOrder inOrder = inOrder(errorHandler);
    inOrder.verify(errorHandler).onError(closeSessionException);
    inOrder.verifyNoMoreInteractions();
}
Also used : Context(io.aeron.archive.client.AeronArchive.Context) InOrder(org.mockito.InOrder) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) Test(org.junit.jupiter.api.Test)

Example 2 with Context

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

the class AeronArchiveTest method closeNotOwningAeronClient.

@Test
void closeNotOwningAeronClient() {
    final long controlSessionId = 42;
    final Aeron.Context aeronContext = mock(Aeron.Context.class);
    when(aeronContext.nanoClock()).thenReturn(SystemNanoClock.INSTANCE);
    when(aeron.context()).thenReturn(aeronContext);
    doThrow(new IllegalMonitorStateException("aeron closed")).when(aeron).close();
    final Publication publication = mock(Publication.class);
    when(publication.isConnected()).thenReturn(true);
    final IllegalStateException publicationException = new IllegalStateException("publication is closed");
    doThrow(publicationException).when(publication).close();
    final Subscription subscription = mock(Subscription.class);
    when(controlResponsePoller.subscription()).thenReturn(subscription);
    final IndexOutOfBoundsException subscriptionException = new IndexOutOfBoundsException("subscription");
    doThrow(subscriptionException).when(subscription).close();
    when(archiveProxy.publication()).thenReturn(publication);
    final IndexOutOfBoundsException closeSessionException = new IndexOutOfBoundsException();
    when(archiveProxy.closeSession(controlSessionId)).thenThrow(closeSessionException);
    final Context context = new Context().aeron(aeron).idleStrategy(NoOpIdleStrategy.INSTANCE).messageTimeoutNs(100).lock(NoOpLock.INSTANCE).errorHandler(errorHandler).ownsAeronClient(false);
    final AeronArchive aeronArchive = new AeronArchive(context, controlResponsePoller, archiveProxy, controlSessionId);
    aeronArchive.close();
    final InOrder inOrder = inOrder(errorHandler);
    inOrder.verify(errorHandler).onError(closeSessionException);
    inOrder.verify(errorHandler).onError(publicationException);
    inOrder.verify(errorHandler).onError(subscriptionException);
    inOrder.verifyNoMoreInteractions();
}
Also used : Context(io.aeron.archive.client.AeronArchive.Context) InOrder(org.mockito.InOrder) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) Test(org.junit.jupiter.api.Test)

Example 3 with Context

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

the class AeronArchiveTest method closeOwningAeronClient.

@Test
void closeOwningAeronClient() {
    final long controlSessionId = 42;
    final Aeron.Context aeronContext = mock(Aeron.Context.class);
    when(aeronContext.nanoClock()).thenReturn(SystemNanoClock.INSTANCE);
    when(aeron.context()).thenReturn(aeronContext);
    final IllegalMonitorStateException aeronException = new IllegalMonitorStateException("aeron closed");
    doThrow(aeronException).when(aeron).close();
    final Publication publication = mock(Publication.class);
    when(publication.isConnected()).thenReturn(true);
    doThrow(new IllegalStateException("publication is closed")).when(publication).close();
    final Subscription subscription = mock(Subscription.class);
    when(controlResponsePoller.subscription()).thenReturn(subscription);
    doThrow(new IndexOutOfBoundsException("subscription")).when(subscription).close();
    when(archiveProxy.publication()).thenReturn(publication);
    final IndexOutOfBoundsException closeSessionException = new IndexOutOfBoundsException();
    when(archiveProxy.closeSession(controlSessionId)).thenThrow(closeSessionException);
    final Context context = new Context().aeron(aeron).idleStrategy(NoOpIdleStrategy.INSTANCE).messageTimeoutNs(100).lock(NoOpLock.INSTANCE).errorHandler(errorHandler).ownsAeronClient(true);
    final AeronArchive aeronArchive = new AeronArchive(context, controlResponsePoller, archiveProxy, controlSessionId);
    final IllegalMonitorStateException ex = assertThrows(IllegalMonitorStateException.class, aeronArchive::close);
    assertSame(aeronException, ex);
    final InOrder inOrder = inOrder(errorHandler);
    inOrder.verify(errorHandler).onError(closeSessionException);
    inOrder.verifyNoMoreInteractions();
}
Also used : Context(io.aeron.archive.client.AeronArchive.Context) InOrder(org.mockito.InOrder) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) Test(org.junit.jupiter.api.Test)

Example 4 with Context

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

the class AeronArchiveTest method closeNotOwningAeronClient.

@Test
void closeNotOwningAeronClient() {
    final long controlSessionId = 42;
    final Aeron.Context aeronContext = mock(Aeron.Context.class);
    when(aeronContext.nanoClock()).thenReturn(SystemNanoClock.INSTANCE);
    when(aeron.context()).thenReturn(aeronContext);
    doThrow(new IllegalMonitorStateException("aeron closed")).when(aeron).close();
    final Publication publication = mock(Publication.class);
    when(publication.isConnected()).thenReturn(true);
    final IllegalStateException publicationException = new IllegalStateException("publication is closed");
    doThrow(publicationException).when(publication).close();
    final Subscription subscription = mock(Subscription.class);
    when(controlResponsePoller.subscription()).thenReturn(subscription);
    final IndexOutOfBoundsException subscriptionException = new IndexOutOfBoundsException("subscription");
    doThrow(subscriptionException).when(subscription).close();
    when(archiveProxy.publication()).thenReturn(publication);
    final IndexOutOfBoundsException closeSessionException = new IndexOutOfBoundsException();
    when(archiveProxy.closeSession(controlSessionId)).thenThrow(closeSessionException);
    final Context context = new Context().aeron(aeron).idleStrategy(NoOpIdleStrategy.INSTANCE).messageTimeoutNs(100).lock(NoOpLock.INSTANCE).errorHandler(errorHandler).ownsAeronClient(false);
    final AeronArchive aeronArchive = new AeronArchive(context, controlResponsePoller, archiveProxy, controlSessionId);
    aeronArchive.close();
    final InOrder inOrder = inOrder(errorHandler);
    inOrder.verify(errorHandler).onError(closeSessionException);
    inOrder.verify(errorHandler).onError(publicationException);
    inOrder.verify(errorHandler).onError(subscriptionException);
    inOrder.verifyNoMoreInteractions();
}
Also used : Context(io.aeron.archive.client.AeronArchive.Context) InOrder(org.mockito.InOrder) Publication(io.aeron.Publication) Subscription(io.aeron.Subscription) Aeron(io.aeron.Aeron) Test(org.junit.jupiter.api.Test)

Aggregations

Aeron (io.aeron.Aeron)4 Publication (io.aeron.Publication)4 Subscription (io.aeron.Subscription)4 Context (io.aeron.archive.client.AeronArchive.Context)4 Test (org.junit.jupiter.api.Test)4 InOrder (org.mockito.InOrder)4