Search in sources :

Example 1 with SessionExpirationMetaData

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();
}
Also used : TransactionBatch(org.wildfly.clustering.ee.cache.tx.TransactionBatch) Instant(java.time.Instant) SessionExpirationMetaData(org.wildfly.clustering.web.session.SessionExpirationMetaData) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Test(org.junit.Test)

Aggregations

Instant (java.time.Instant)1 Test (org.junit.Test)1 TransactionBatch (org.wildfly.clustering.ee.cache.tx.TransactionBatch)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1 SessionExpirationMetaData (org.wildfly.clustering.web.session.SessionExpirationMetaData)1