use of org.wildfly.clustering.web.session.ImmutableSession 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.ImmutableSession 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);
}
}
use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.
the class OOBSessionTestCase method isExpired.
@Test
public void isExpired() {
Batcher<Batch> batcher = mock(Batcher.class);
Batch batch = mock(Batch.class);
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.getMetaData()::isExpired);
verify(batch).close();
reset(batch);
ImmutableSession session = mock(ImmutableSession.class);
ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
boolean expected = true;
when(this.manager.readSession(this.id)).thenReturn(session);
when(session.getMetaData()).thenReturn(metaData);
when(metaData.isExpired()).thenReturn(expected);
boolean result = this.session.getMetaData().isExpired();
Assert.assertEquals(expected, result);
verify(batch).close();
}
use of org.wildfly.clustering.web.session.ImmutableSession 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);
}
}
use of org.wildfly.clustering.web.session.ImmutableSession in project wildfly by wildfly.
the class ExpiredSessionRemover method remove.
@Override
public boolean remove(String id) {
MV metaDataValue = this.factory.getMetaDataFactory().tryValue(id);
if (metaDataValue != null) {
ImmutableSessionMetaData metaData = this.factory.getMetaDataFactory().createImmutableSessionMetaData(id, metaDataValue);
if (metaData.isExpired()) {
AV attributesValue = this.factory.getAttributesFactory().findValue(id);
if (attributesValue != null) {
ImmutableSessionAttributes attributes = this.factory.getAttributesFactory().createImmutableSessionAttributes(id, attributesValue);
ImmutableSession session = this.factory.createImmutableSession(id, metaData, attributes);
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s has expired.", id);
for (SessionExpirationListener listener : this.listeners) {
listener.sessionExpired(session);
}
}
return this.factory.remove(id);
}
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s is not yet expired.", id);
} else {
InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s was not found or is currently in use.", id);
}
return false;
}
Aggregations