Package org.wildfly.clustering.web.session

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


    @Test
    public void test() throws Exception {
        String name = "cache";
        String evictedSessionId = "evicted";
        String activeSessionId = "active";
        ImmutableSession evictedSession = mock(ImmutableSession.class);
        ImmutableSession activeSession = mock(ImmutableSession.class);
        CommandDispatcherFactory dispatcherFactory = mock(CommandDispatcherFactory.class);
        CommandDispatcher<SessionEvictionContext> dispatcher = mock(CommandDispatcher.class);
        Batcher<TransactionBatch> batcher = mock(Batcher.class);
        TransactionBatch batch = mock(TransactionBatch.class);
        Evictor<String> evictor = mock(Evictor.class);
        ArgumentCaptor<Command> capturedCommand = ArgumentCaptor.forClass(Command.class);
        ArgumentCaptor<SessionEvictionContext> capturedContext = ArgumentCaptor.forClass(SessionEvictionContext.class);

        when(dispatcherFactory.createCommandDispatcher(same(name), capturedContext.capture())).thenReturn(dispatcher);

        try (Scheduler scheduler = new SessionEvictionScheduler(name, batcher, evictor, dispatcherFactory, 1)) {
            SessionEvictionContext context = capturedContext.getValue();
           
            assertSame(scheduler, context);
           
            when(evictedSession.getId()).thenReturn(evictedSessionId);
            when(activeSession.getId()).thenReturn(activeSessionId);
           
            scheduler.schedule(evictedSession);

            verifyZeroInteractions(dispatcher);
View Full Code Here


    @Test
    public void test() throws InterruptedException {
        Batcher<TransactionBatch> batcher = mock(Batcher.class);
        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);
       
        try (Scheduler scheduler = new SessionExpirationScheduler(batcher, remover)) {
            scheduler.schedule(immortalSession);
            scheduler.schedule(canceledSession);
            scheduler.schedule(expiringSession);
View Full Code Here

        this.lastAccessedTime = session.getMetaData().getLastAccessedTime().getTime();
    }

    @Override
    public Void execute(Scheduler scheduler) {
        ImmutableSession session = (this.session != null) ? this.session : new MockImmutableSession(this.id, new SimpleSessionMetaData(null, new Date(this.lastAccessedTime), new Time(this.maxInactiveInterval, TimeUnit.MILLISECONDS)));
        scheduler.schedule(session);
        return null;
    }
View Full Code Here

    @CacheEntryActivated
    public void activated(CacheEntryActivatedEvent<String, ?> event) {
        if (!event.isPre() && !this.persistent) {
            String id = event.getKey();
            InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s was activated", id);
            ImmutableSession session = this.factory.createImmutableSession(id, this.factory.findValue(id));
            triggerPostActivationEvents(session);
        }
    }
View Full Code Here

    @CacheEntryPassivated
    public void passivated(CacheEntryPassivatedEvent<String, ?> event) {
        if (event.isPre() && !this.persistent) {
            String id = event.getKey();
            InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be passivated", id);
            ImmutableSession session = this.factory.createSession(id, this.factory.findValue(id));
            triggerPrePassivationEvents(session);
        }
    }
View Full Code Here

    @CacheEntryRemoved
    public void removed(CacheEntryRemovedEvent<String, ?> event) {
        if (event.isPre()) {
            String id = event.getKey();
            InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be removed", id);
            ImmutableSession session = this.factory.createImmutableSession(id, this.factory.findValue(id));
            ImmutableSessionAttributes attributes = session.getAttributes();

            HttpSession httpSession = new ImmutableHttpSessionAdapter(session);
            HttpSessionEvent sessionEvent = new HttpSessionEvent(httpSession);
            for (HttpSessionListener listener: this.context.getSessionListeners()) {
                listener.sessionDestroyed(sessionEvent);
View Full Code Here

                    Batch batch = this.batcher.createBatch();
                    try {
                        // We need to lookup the session to obtain its meta data
                        V value = this.factory.findValue(sessionId);
                        if (value != null) {
                            ImmutableSession session = this.factory.createImmutableSession(sessionId, value);
                            this.scheduler.schedule(session);
                        }
                    } finally {
                        batch.discard();
                    }
View Full Code Here

    @Override
    public io.undertow.server.session.Session getSession(String sessionId) {
        Batch batch = this.manager.getBatcher().createBatch();
        try {
            ImmutableSession session = this.manager.viewSession(sessionId);
            return (session != null) ? new DistributableImmutableSession(this, session) : null;
        } finally {
            batch.discard();
        }
    }
View Full Code Here

    @Test
    public void getSessionByIdentifier() {
        Batcher<Batch> batcher = mock(Batcher.class);
        Batch batch = mock(Batch.class);
        ImmutableSession session = mock(ImmutableSession.class);
        ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
        ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
        String id = "session";
        String name = "name";
        Object value = new Object();
        Set<String> names = Collections.singleton(name);
        Date creationTime = new Date();
        Date lastAccessedTime = new Date();
        long maxInactiveInterval = 30;

        when(this.manager.getBatcher()).thenReturn(batcher);
        when(this.manager.viewSession(id)).thenReturn(session);
        when(session.getId()).thenReturn(id);
        when(session.getAttributes()).thenReturn(attributes);
        when(attributes.getAttributeNames()).thenReturn(names);
        when(attributes.getAttribute(name)).thenReturn(value);
        when(session.getMetaData()).thenReturn(metaData);
        when(metaData.getCreationTime()).thenReturn(creationTime);
        when(metaData.getLastAccessedTime()).thenReturn(lastAccessedTime);
        when(metaData.getMaxInactiveInterval(TimeUnit.SECONDS)).thenReturn(maxInactiveInterval);
        when(batcher.createBatch()).thenReturn(batch);
       
View Full Code Here

TOP

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

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.