use of org.wildfly.clustering.web.session.SessionExpirationMetaData in project wildfly by wildfly.
the class SessionExpirationSchedulerTestCase method test.
@Test
public void test() throws InterruptedException {
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
Remover<String> remover = mock(Remover.class);
ImmutableSessionMetaDataFactory<Object> metaDataFactory = mock(ImmutableSessionMetaDataFactory.class);
ImmutableSessionMetaData immortalSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData expiringSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData canceledSessionMetaData = mock(ImmutableSessionMetaData.class);
String immortalSessionId = "immortal";
String expiringSessionId = "expiring";
String canceledSessionId = "canceled";
when(batcher.createBatch()).thenReturn(batch);
when(immortalSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ZERO);
when(expiringSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofMillis(1L));
when(canceledSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofSeconds(100L));
Instant now = Instant.now();
when(expiringSessionMetaData.getLastAccessEndTime()).thenReturn(now);
when(canceledSessionMetaData.getLastAccessEndTime()).thenReturn(now);
when(remover.remove(expiringSessionId)).thenReturn(true);
try (Scheduler<String, SessionExpirationMetaData> scheduler = new SessionExpirationScheduler<>(batcher, metaDataFactory, remover, Duration.ZERO)) {
scheduler.schedule(immortalSessionId, immortalSessionMetaData);
scheduler.schedule(canceledSessionId, canceledSessionMetaData);
scheduler.schedule(expiringSessionId, expiringSessionMetaData);
scheduler.cancel(canceledSessionId);
TimeUnit.MILLISECONDS.sleep(500);
}
verify(remover, never()).remove(immortalSessionId);
verify(remover, never()).remove(canceledSessionId);
verify(batch).close();
}
Aggregations