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();
}
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);
}
}
Aggregations