Search in sources :

Example 6 with Registration

use of org.wildfly.clustering.Registration in project wildfly by wildfly.

the class ExpiredSessionRemoverTestCase method test.

@Test
public void test() {
    SessionFactory<Object, UUID, UUID, Object> factory = mock(SessionFactory.class);
    SessionMetaDataFactory<UUID> metaDataFactory = mock(SessionMetaDataFactory.class);
    SessionAttributesFactory<Object, UUID> attributesFactory = mock(SessionAttributesFactory.class);
    SessionExpirationListener listener = mock(SessionExpirationListener.class);
    ImmutableSessionAttributes expiredAttributes = mock(ImmutableSessionAttributes.class);
    ImmutableSessionMetaData validMetaData = mock(ImmutableSessionMetaData.class);
    ImmutableSessionMetaData expiredMetaData = mock(ImmutableSessionMetaData.class);
    ImmutableSession expiredSession = mock(ImmutableSession.class);
    String missingSessionId = "missing";
    String expiredSessionId = "expired";
    String validSessionId = "valid";
    UUID expiredMetaDataValue = UUID.randomUUID();
    UUID expiredAttributesValue = UUID.randomUUID();
    UUID validMetaDataValue = UUID.randomUUID();
    ExpiredSessionRemover<Object, UUID, UUID, Object> subject = new ExpiredSessionRemover<>(factory);
    try (Registration regisration = subject.register(listener)) {
        when(factory.getMetaDataFactory()).thenReturn(metaDataFactory);
        when(factory.getAttributesFactory()).thenReturn(attributesFactory);
        when(metaDataFactory.tryValue(missingSessionId)).thenReturn(null);
        when(metaDataFactory.tryValue(expiredSessionId)).thenReturn(expiredMetaDataValue);
        when(metaDataFactory.tryValue(validSessionId)).thenReturn(validMetaDataValue);
        when(metaDataFactory.createImmutableSessionMetaData(expiredSessionId, expiredMetaDataValue)).thenReturn(expiredMetaData);
        when(metaDataFactory.createImmutableSessionMetaData(validSessionId, validMetaDataValue)).thenReturn(validMetaData);
        when(expiredMetaData.isExpired()).thenReturn(true);
        when(validMetaData.isExpired()).thenReturn(false);
        when(attributesFactory.findValue(expiredSessionId)).thenReturn(expiredAttributesValue);
        when(attributesFactory.createImmutableSessionAttributes(expiredSessionId, expiredAttributesValue)).thenReturn(expiredAttributes);
        when(factory.createImmutableSession(same(expiredSessionId), same(expiredMetaData), same(expiredAttributes))).thenReturn(expiredSession);
        subject.remove(missingSessionId);
        subject.remove(expiredSessionId);
        subject.remove(validSessionId);
        verify(factory).remove(expiredSessionId);
        verify(factory, never()).remove(missingSessionId);
        verify(factory, never()).remove(validSessionId);
        verify(listener).sessionExpired(expiredSession);
    }
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) Registration(org.wildfly.clustering.Registration) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Registration (org.wildfly.clustering.Registration)6 ChildResourceProvider (org.jboss.as.clustering.controller.ChildResourceProvider)3 SimpleChildResourceProvider (org.jboss.as.clustering.controller.SimpleChildResourceProvider)2 Test (org.junit.Test)2 UUID (java.util.UUID)1 Cache (org.infinispan.Cache)1 CacheStopped (org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped)1 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)1 ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)1 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)1 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)1