@Test public void shouldCloseTerminatedSession() { final CachedEpochClock clock = new CachedEpochClock(); final long startMs = 7L; clock.update(startMs); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationId = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationId, 2, 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 + 1; clock.update(timeMs); 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.ERROR), eq(SESSION_TERMINATED_MSG)); }
@Test public void shouldUpdateEpochClock() { final long timestamp = 333L; final CachedEpochClock clock = new CachedEpochClock(); assertThat(clock.time(), is(0L)); clock.update(timestamp); assertThat(clock.time(), is(timestamp)); } }
@Test public void shouldCloseInactiveSession() { final CachedEpochClock clock = new CachedEpochClock(); final long startMs = 7L; clock.update(startMs); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationId = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationId, 2, RESPONSE_CHANNEL_ONE, new byte[0]); agent.doWork(); verify(mockLogPublisher).appendSessionOpen(any(ClusterSession.class), anyLong(), eq(startMs)); final long timeMs = startMs + TimeUnit.NANOSECONDS.toMillis(ConsensusModule.Configuration.sessionTimeoutNs()); clock.update(timeMs); agent.doWork(); final long timeoutMs = timeMs + 1L; clock.update(timeoutMs); agent.doWork(); verify(mockTimedOutClientCounter).incrementOrdered(); verify(mockLogPublisher).appendSessionClose(any(ClusterSession.class), anyLong(), eq(timeoutMs)); verify(mockEgressPublisher).sendEvent( any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.ERROR), eq(SESSION_TIMEOUT_MSG)); }
@Test public void shouldLimitActiveSessions() { final CachedEpochClock clock = new CachedEpochClock(); ctx.maxConcurrentSessions(1); ctx.epochClock(clock); final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx); final long correlationIdOne = 1L; agent.state(ConsensusModule.State.ACTIVE); agent.role(Cluster.Role.LEADER); agent.appendedPositionCounter(mock(ReadableCounter.class)); agent.onSessionConnect(correlationIdOne, 2, RESPONSE_CHANNEL_ONE, new byte[0]); clock.update(1); agent.doWork(); verify(mockLogPublisher).appendSessionOpen(any(ClusterSession.class), anyLong(), anyLong()); final long correlationIdTwo = 2L; agent.onSessionConnect(correlationIdTwo, 3, RESPONSE_CHANNEL_TWO, new byte[0]); clock.update(2); agent.doWork(); verify(mockEgressPublisher).sendEvent( any(ClusterSession.class), anyLong(), anyInt(), eq(EventCode.ERROR), eq(SESSION_LIMIT_MSG)); }
.cachedEpochClock(new CachedEpochClock()) .cachedNanoClock(mockCachedNanoClock) .controlTransportPoller(mockTransportPoller)
@Test public void shouldSuspendThenResume() final CachedEpochClock clock = new CachedEpochClock();
.epochClock(epochClock) .nanoClock(nanoClock) .cachedEpochClock(new CachedEpochClock()) .cachedNanoClock(new CachedNanoClock()) .sendChannelEndpointSupplier(Configuration.sendChannelEndpointSupplier())
.driverCommandQueue(mock(ManyToOneConcurrentArrayQueue.class)) .epochClock(new SystemEpochClock()) .cachedEpochClock(new CachedEpochClock()) .cachedNanoClock(new CachedNanoClock()) .countersManager(countersManager)
cachedEpochClock = new CachedEpochClock();
cachedEpochClock = new CachedEpochClock();
cachedEpochClock = new CachedEpochClock();