Package org.wildfly.clustering.web.session

Examples of org.wildfly.clustering.web.session.SessionMetaData


        SessionFactory<Object, Object> factory = mock(SessionFactory.class);
        Remover<String> remover = new ExpiredSessionRemover<>(factory);
        Session<Object> validSession = mock(Session.class);
        Session<Object> expiredSession = mock(Session.class);
        Session<Object> invalidSession = mock(Session.class);
        SessionMetaData validMetaData = mock(SessionMetaData.class);
        SessionMetaData expiredMetaData = mock(SessionMetaData.class);
        String missingSessionId = "missing";
        String expiredSessionId = "expired";
        String validSessionId = "valid";
        String invalidSessionId = "invalid";
        Object expiredValue = new Object();
        Object validValue = new Object();
        Object invalidValue = new Object();
       
        when(factory.findValue(missingSessionId)).thenReturn(null);
        when(factory.findValue(expiredSessionId)).thenReturn(expiredValue);
        when(factory.findValue(validSessionId)).thenReturn(validValue);
        when(factory.findValue(invalidSessionId)).thenReturn(invalidValue);
       
        when(factory.createSession(expiredSessionId, expiredValue)).thenReturn(expiredSession);
        when(factory.createSession(validSessionId, validValue)).thenReturn(validSession);
        when(factory.createSession(invalidSessionId, invalidValue)).thenReturn(invalidSession);
       
        when(expiredSession.isValid()).thenReturn(true);
        when(validSession.isValid()).thenReturn(true);
        when(invalidSession.isValid()).thenReturn(false);
       
        when(expiredSession.getMetaData()).thenReturn(expiredMetaData);
        when(validSession.getMetaData()).thenReturn(validMetaData);
        when(invalidSession.getMetaData()).thenReturn(validMetaData);
       
        when(expiredMetaData.isExpired()).thenReturn(true);
        when(validMetaData.isExpired()).thenReturn(false);
       
        remover.remove(missingSessionId);
        remover.remove(expiredSessionId);
        remover.remove(validSessionId);
View Full Code Here


import static org.junit.Assert.*;

public class SimpleSessionMetaDataTestCase {
    @Test
    public void isNew() {
        SessionMetaData metaData = new SimpleSessionMetaData();
        assertTrue(metaData.isNew());

        metaData.setLastAccessedTime(new Date());
        assertFalse(metaData.isNew());

        metaData = new SimpleSessionMetaData(new Date(), new Date(), new Time(0, TimeUnit.SECONDS));
        assertFalse(metaData.isNew());
    }
View Full Code Here

        assertFalse(metaData.isNew());
    }

    @Test
    public void isExpired() {
        SessionMetaData metaData = new SimpleSessionMetaData();
        assertFalse(metaData.isExpired());

        Date now = new Date();

        metaData.setMaxInactiveInterval(1, TimeUnit.MINUTES);
        assertFalse(metaData.isExpired());

        metaData.setLastAccessedTime(new Date(now.getTime() - metaData.getMaxInactiveInterval(TimeUnit.MILLISECONDS) - 1));
        assertTrue(metaData.isExpired());
    }
View Full Code Here

        TransactionBatch batch = mock(TransactionBatch.class);
        Remover<String> remover = mock(Remover.class);
        ImmutableSession immortalSession = mock(ImmutableSession.class);
        ImmutableSession expiringSession = mock(ImmutableSession.class);
        ImmutableSession canceledSession = mock(ImmutableSession.class);
        SessionMetaData immortalMetaData = mock(SessionMetaData.class);
        SessionMetaData shortTimeoutMetaData = mock(SessionMetaData.class);
        SessionMetaData longTimeoutMetaData = mock(SessionMetaData.class);
        String immortalSessionId = "immortal";
        String expiringSessionId = "expiring";
        String canceledSessionId = "canceled";

        when(batcher.createBatch()).thenReturn(batch);

        when(immortalSession.isValid()).thenReturn(true);
        when(expiringSession.isValid()).thenReturn(true);
        when(canceledSession.isValid()).thenReturn(true);

        when(immortalSession.getMetaData()).thenReturn(immortalMetaData);
        when(expiringSession.getMetaData()).thenReturn(shortTimeoutMetaData);
        when(canceledSession.getMetaData()).thenReturn(longTimeoutMetaData);
       
        when(immortalMetaData.getMaxInactiveInterval(TimeUnit.MILLISECONDS)).thenReturn(0L);
        when(shortTimeoutMetaData.getMaxInactiveInterval(TimeUnit.MILLISECONDS)).thenReturn(1L);
        when(longTimeoutMetaData.getMaxInactiveInterval(TimeUnit.MILLISECONDS)).thenReturn(10000L);

        Date now = new Date();
        when(shortTimeoutMetaData.getLastAccessedTime()).thenReturn(now);
        when(longTimeoutMetaData.getLastAccessedTime()).thenReturn(now);
       
        when(immortalSession.getId()).thenReturn(immortalSessionId);
        when(expiringSession.getId()).thenReturn(expiringSessionId);
        when(canceledSession.getId()).thenReturn(canceledSessionId);
       
View Full Code Here

        this.localContextFactory = localContextFactory;
    }

    @Override
    public Session<L> createSession(String id, FineSessionCacheEntry<L> entry) {
        SessionMetaData metaData = entry.getMetaData();
        Mutator mutator = metaData.isNew() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.sessionCache, id, entry);
        SessionAttributes attributes = new FineSessionAttributes<>(id, this.attributeCache, this.marshaller);
        return new InfinispanSession<>(id, entry.getMetaData(), attributes, entry.getLocalContext(), this.localContextFactory, this.context, mutator, this);
    }
View Full Code Here

    }

    @Override
    public Session<L> createSession(String id, CoarseSessionEntry<L> entry) {
        CoarseSessionCacheEntry<L> cacheEntry = entry.getCacheEntry();
        SessionMetaData metaData = cacheEntry.getMetaData();
        MarshalledValue<Map<String, Object>, MarshallingContext> value = entry.getAttributes();
        Mutator attributesMutator = metaData.isNew() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.attributesCache, new SessionAttributesCacheKey(id), value);
        SessionAttributes attributes = new CoarseSessionAttributes(value, this.marshaller, attributesMutator);
        Mutator sessionMutator = metaData.isNew() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.sessionCache, id, cacheEntry);
        return new InfinispanSession<>(id, metaData, attributes, cacheEntry.getLocalContext(), this.localContextFactory, this.context, sessionMutator, this);
    }
View Full Code Here

    @Test
    public void getCreationTime() {
        SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
        Batcher<Batch> batcher = mock(Batcher.class);
        BatchContext context = mock(BatchContext.class);
        SessionMetaData metaData = mock(SessionMetaData.class);
        Date date = new Date();
       
        when(this.manager.getSessionManager()).thenReturn(manager);
        when(manager.getBatcher()).thenReturn(batcher);
        when(batcher.resumeBatch(this.batch)).thenReturn(context);
        when(this.session.getMetaData()).thenReturn(metaData);
        when(metaData.getCreationTime()).thenReturn(date);
       
        long result = this.adapter.getCreationTime();
       
        assertEquals(date.getTime(), result);
View Full Code Here

    @Test
    public void getLastAccessedTime() {
        SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
        Batcher<Batch> batcher = mock(Batcher.class);
        BatchContext context = mock(BatchContext.class);
        SessionMetaData metaData = mock(SessionMetaData.class);
        Date date = new Date();
       
        when(this.manager.getSessionManager()).thenReturn(manager);
        when(manager.getBatcher()).thenReturn(batcher);
        when(batcher.resumeBatch(this.batch)).thenReturn(context);
        when(this.session.getMetaData()).thenReturn(metaData);
        when(metaData.getLastAccessedTime()).thenReturn(date);
       
        long result = this.adapter.getLastAccessedTime();
       
        assertEquals(date.getTime(), result);
View Full Code Here

    @Test
    public void getMaxInactiveInterval() {
        SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
        Batcher<Batch> batcher = mock(Batcher.class);
        BatchContext context = mock(BatchContext.class);
        SessionMetaData metaData = mock(SessionMetaData.class);
        long expected = 3600L;
       
        when(this.manager.getSessionManager()).thenReturn(manager);
        when(manager.getBatcher()).thenReturn(batcher);
        when(batcher.resumeBatch(this.batch)).thenReturn(context);
        when(this.session.getMetaData()).thenReturn(metaData);
        when(metaData.getMaxInactiveInterval(TimeUnit.SECONDS)).thenReturn(expected);
       
        long result = this.adapter.getMaxInactiveInterval();
       
        assertEquals(expected, result);
View Full Code Here

    @Test
    public void setMaxInactiveInterval() {
        SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
        Batcher<Batch> batcher = mock(Batcher.class);
        BatchContext context = mock(BatchContext.class);
        SessionMetaData metaData = mock(SessionMetaData.class);
        int interval = 3600;
       
        when(this.manager.getSessionManager()).thenReturn(manager);
        when(manager.getBatcher()).thenReturn(batcher);
        when(batcher.resumeBatch(this.batch)).thenReturn(context);
View Full Code Here

TOP

Related Classes of org.wildfly.clustering.web.session.SessionMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.