Search in sources :

Example 11 with TestClusterClock

use of io.aeron.test.cluster.TestClusterClock in project Aeron by real-logic.

the class ConsensusModuleAgentTest method shouldThrowClusterTerminationExceptionUponShutdown.

@Test
public void shouldThrowClusterTerminationExceptionUponShutdown() {
    final TestClusterClock clock = new TestClusterClock(TimeUnit.MILLISECONDS);
    final CountedErrorHandler countedErrorHandler = mock(CountedErrorHandler.class);
    final MutableLong stateValue = new MutableLong();
    final Counter mockState = mock(Counter.class);
    when(mockState.get()).thenAnswer((invocation) -> stateValue.value);
    doAnswer((invocation) -> {
        stateValue.value = invocation.getArgument(0);
        return null;
    }).when(mockState).set(anyLong());
    ctx.countedErrorHandler(countedErrorHandler).moduleStateCounter(mockState).epochClock(clock).clusterClock(clock);
    final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx);
    agent.state(ConsensusModule.State.QUITTING);
    assertThrows(ClusterTerminationException.class, () -> agent.onServiceAck(1024, 100, 0, 55, 0));
}
Also used : MutableLong(org.agrona.collections.MutableLong) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) ReadableCounter(io.aeron.status.ReadableCounter) TestClusterClock(io.aeron.test.cluster.TestClusterClock) Test(org.junit.jupiter.api.Test)

Example 12 with TestClusterClock

use of io.aeron.test.cluster.TestClusterClock in project Aeron by real-logic.

the class ConsensusModuleAgentTest method shouldCloseTerminatedSession.

@Test
public void shouldCloseTerminatedSession() {
    final TestClusterClock clock = new TestClusterClock(TimeUnit.MILLISECONDS);
    final long startMs = SLOW_TICK_INTERVAL_MS;
    clock.update(startMs, TimeUnit.MILLISECONDS);
    ctx.epochClock(clock).clusterClock(clock);
    final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx);
    final long correlationId = 1L;
    agent.state(ConsensusModule.State.ACTIVE);
    agent.role(Cluster.Role.LEADER);
    Tests.setField(agent, "appendPosition", mock(ReadableCounter.class));
    agent.onSessionConnect(correlationId, 2, PROTOCOL_SEMANTIC_VERSION, RESPONSE_CHANNEL_ONE, new byte[0]);
    agent.doWork();
    final ArgumentCaptor<ClusterSession> sessionCaptor = ArgumentCaptor.forClass(ClusterSession.class);
    verify(mockLogPublisher).appendSessionOpen(sessionCaptor.capture(), anyLong(), eq(startMs));
    final long timeMs = startMs + SLOW_TICK_INTERVAL_MS;
    clock.update(timeMs, TimeUnit.MILLISECONDS);
    agent.doWork();
    agent.onServiceCloseSession(sessionCaptor.getValue().id());
    verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeMs));
    verify(mockEgressPublisher).sendEvent(any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.CLOSED), eq(CloseReason.SERVICE_ACTION.name()));
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) TestClusterClock(io.aeron.test.cluster.TestClusterClock) Test(org.junit.jupiter.api.Test)

Example 13 with TestClusterClock

use of io.aeron.test.cluster.TestClusterClock in project aeron by real-logic.

the class ConsensusModuleAgentTest method shouldCloseTerminatedSession.

@Test
public void shouldCloseTerminatedSession() {
    final TestClusterClock clock = new TestClusterClock(TimeUnit.MILLISECONDS);
    final long startMs = SLOW_TICK_INTERVAL_MS;
    clock.update(startMs, TimeUnit.MILLISECONDS);
    ctx.epochClock(clock).clusterClock(clock);
    final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx);
    final long correlationId = 1L;
    agent.state(ConsensusModule.State.ACTIVE);
    agent.role(Cluster.Role.LEADER);
    Tests.setField(agent, "appendPosition", mock(ReadableCounter.class));
    agent.onSessionConnect(correlationId, 2, PROTOCOL_SEMANTIC_VERSION, RESPONSE_CHANNEL_ONE, new byte[0]);
    agent.doWork();
    final ArgumentCaptor<ClusterSession> sessionCaptor = ArgumentCaptor.forClass(ClusterSession.class);
    verify(mockLogPublisher).appendSessionOpen(sessionCaptor.capture(), anyLong(), eq(startMs));
    final long timeMs = startMs + SLOW_TICK_INTERVAL_MS;
    clock.update(timeMs, TimeUnit.MILLISECONDS);
    agent.doWork();
    agent.onServiceCloseSession(sessionCaptor.getValue().id());
    verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeMs));
    verify(mockEgressPublisher).sendEvent(any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.CLOSED), eq(CloseReason.SERVICE_ACTION.name()));
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) TestClusterClock(io.aeron.test.cluster.TestClusterClock) Test(org.junit.jupiter.api.Test)

Example 14 with TestClusterClock

use of io.aeron.test.cluster.TestClusterClock in project aeron by real-logic.

the class ConsensusModuleAgentTest method shouldCloseInactiveSession.

@Test
public void shouldCloseInactiveSession() {
    final TestClusterClock clock = new TestClusterClock(TimeUnit.MILLISECONDS);
    final long startMs = SLOW_TICK_INTERVAL_MS;
    clock.update(startMs, TimeUnit.MILLISECONDS);
    ctx.epochClock(clock).clusterClock(clock);
    final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx);
    final long correlationId = 1L;
    agent.state(ConsensusModule.State.ACTIVE);
    agent.role(Cluster.Role.LEADER);
    Tests.setField(agent, "appendPosition", mock(ReadableCounter.class));
    agent.onSessionConnect(correlationId, 2, PROTOCOL_SEMANTIC_VERSION, RESPONSE_CHANNEL_ONE, new byte[0]);
    agent.doWork();
    verify(mockLogPublisher).appendSessionOpen(any(ClusterSession.class), anyLong(), eq(startMs));
    verify(mockTimeConsumer).accept(clock.time());
    final long timeMs = startMs + TimeUnit.NANOSECONDS.toMillis(ConsensusModule.Configuration.sessionTimeoutNs());
    clock.update(timeMs, TimeUnit.MILLISECONDS);
    agent.doWork();
    final long timeoutMs = timeMs + SLOW_TICK_INTERVAL_MS;
    clock.update(timeoutMs, TimeUnit.MILLISECONDS);
    agent.doWork();
    verify(mockTimeConsumer).accept(clock.time());
    verify(mockTimedOutClientCounter).incrementOrdered();
    verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeoutMs));
    verify(mockEgressPublisher).sendEvent(any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.CLOSED), eq(CloseReason.TIMEOUT.name()));
}
Also used : ReadableCounter(io.aeron.status.ReadableCounter) TestClusterClock(io.aeron.test.cluster.TestClusterClock) Test(org.junit.jupiter.api.Test)

Aggregations

TestClusterClock (io.aeron.test.cluster.TestClusterClock)14 Test (org.junit.jupiter.api.Test)14 ReadableCounter (io.aeron.status.ReadableCounter)10 MutableLong (org.agrona.collections.MutableLong)4 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)4 InOrder (org.mockito.InOrder)2