Search in sources :

Example 11 with ImmutableSessionAttributes

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class OOBSessionTestCase method getAttribute.

@Test
public void getAttribute() {
    Batcher<Batch> batcher = mock(Batcher.class);
    Batch batch = mock(Batch.class);
    String attributeName = "foo";
    when(this.manager.getBatcher()).thenReturn(batcher);
    when(batcher.createBatch()).thenReturn(batch);
    when(this.manager.readSession(this.id)).thenReturn(null);
    Assert.assertThrows(IllegalStateException.class, () -> this.session.getAttributes().getAttribute(attributeName));
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    Object expected = new Object();
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttribute(attributeName)).thenReturn(expected);
    Object result = this.session.getAttributes().getAttribute(attributeName);
    Assert.assertSame(expected, result);
    verify(batch).close();
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) Test(org.junit.Test)

Example 12 with ImmutableSessionAttributes

use of org.wildfly.clustering.web.session.ImmutableSessionAttributes in project wildfly by wildfly.

the class UndertowSessionExpirationListener method sessionExpired.

@Override
public void sessionExpired(ImmutableSession session) {
    UndertowSessionManager manager = (UndertowSessionManager) this.deployment.getSessionManager();
    Session undertowSession = new DistributableImmutableSession(manager, session);
    Batcher<Batch> batcher = manager.getSessionManager().getBatcher();
    // Perform listener invocation in isolated batch context
    Batch batch = batcher.suspendBatch();
    try {
        this.listeners.sessionDestroyed(undertowSession, null, SessionListener.SessionDestroyedReason.TIMEOUT);
    } finally {
        batcher.resumeBatch(batch);
    }
    // Trigger attribute listeners
    ImmutableSessionAttributes attributes = session.getAttributes();
    for (String name : attributes.getAttributeNames()) {
        Object value = attributes.getAttribute(name);
        manager.getSessionListeners().attributeRemoved(undertowSession, name, value);
    }
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) Batch(org.wildfly.clustering.ee.Batch) Session(io.undertow.server.session.Session) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession)

Aggregations

ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)12 ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)9 Test (org.junit.Test)7 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)7 Map (java.util.Map)4 Batch (org.wildfly.clustering.ee.Batch)4 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)4 Session (io.undertow.server.session.Session)2 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)1 SessionConfig (io.undertow.server.session.SessionConfig)1 SessionListener (io.undertow.server.session.SessionListener)1 SessionListeners (io.undertow.server.session.SessionListeners)1 Deployment (io.undertow.servlet.api.Deployment)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 ClientCacheEntryExpired (org.infinispan.client.hotrod.annotation.ClientCacheEntryExpired)1 Marshaller (org.infinispan.commons.marshall.Marshaller)1 Registration (org.wildfly.clustering.Registration)1 BatchContext (org.wildfly.clustering.ee.BatchContext)1