Search in sources :

Example 16 with ImmutableSession

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

the class InfinispanSessionFactoryTestCase method createImmutableSession.

@Test
public void createImmutableSession() {
    Map.Entry<InfinispanSessionMetaData<Object>, Object> entry = mock(Map.Entry.class);
    SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
    SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
    InfinispanSessionMetaData<Object> metaDataValue = new InfinispanSessionMetaData<>(creationMetaData, accessMetaData, null);
    Object attributesValue = new Object();
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    String id = "id";
    when(entry.getKey()).thenReturn(metaDataValue);
    when(entry.getValue()).thenReturn(attributesValue);
    when(this.metaDataFactory.createImmutableSessionMetaData(id, metaDataValue)).thenReturn(metaData);
    when(this.attributesFactory.createImmutableSessionAttributes(id, attributesValue)).thenReturn(attributes);
    ImmutableSession result = this.factory.createImmutableSession(id, entry);
    assertSame(id, result.getId());
    assertSame(metaData, result.getMetaData());
    assertSame(attributes, result.getAttributes());
}
Also used : ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Map(java.util.Map) Test(org.junit.Test)

Example 17 with ImmutableSession

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

the class ConcurrentSessionManagerTestCase method readSession.

@Test
public void readSession() {
    SessionManager<Void, Batch> manager = mock(SessionManager.class);
    SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
    ImmutableSession expected = mock(ImmutableSession.class);
    String id = "foo";
    when(manager.readSession(id)).thenReturn(expected);
    ImmutableSession result = subject.readSession(id);
    assertSame(expected, result);
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) SimpleManager(org.wildfly.clustering.ee.cache.SimpleManager) Test(org.junit.Test)

Example 18 with ImmutableSession

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

the class OOBSessionTestCase method getMaxInactiveInterval.

@Test
public void getMaxInactiveInterval() {
    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()::getMaxInactiveInterval);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    Duration expected = Duration.ZERO;
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getMaxInactiveInterval()).thenReturn(expected);
    Duration result = this.session.getMetaData().getMaxInactiveInterval();
    Assert.assertSame(expected, result);
    verify(batch).close();
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) Duration(java.time.Duration) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Test(org.junit.Test)

Example 19 with ImmutableSession

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

the class OOBSessionTestCase method getAttributeNames.

@Test
public void getAttributeNames() {
    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.getAttributes()::getAttributeNames);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
    Set<String> expected = Collections.singleton("foo");
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(expected);
    Set<String> result = this.session.getAttributes().getAttributeNames();
    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 20 with ImmutableSession

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

the class OOBSessionTestCase method getLastAccessEndTime.

@Test
public void getLastAccessEndTime() {
    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()::getLastAccessEndTime);
    verify(batch).close();
    reset(batch);
    ImmutableSession session = mock(ImmutableSession.class);
    ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
    Instant expected = Instant.now();
    when(this.manager.readSession(this.id)).thenReturn(session);
    when(session.getMetaData()).thenReturn(metaData);
    when(metaData.getLastAccessEndTime()).thenReturn(expected);
    Instant result = this.session.getMetaData().getLastAccessEndTime();
    Assert.assertSame(expected, result);
    verify(batch).close();
}
Also used : ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) Batch(org.wildfly.clustering.ee.Batch) Instant(java.time.Instant) ImmutableSessionMetaData(org.wildfly.clustering.web.session.ImmutableSessionMetaData) Test(org.junit.Test)

Aggregations

ImmutableSession (org.wildfly.clustering.web.session.ImmutableSession)35 Test (org.junit.Test)27 Batch (org.wildfly.clustering.ee.Batch)13 ImmutableSessionMetaData (org.wildfly.clustering.web.session.ImmutableSessionMetaData)13 ServletContext (javax.servlet.ServletContext)12 ImmutableSessionAttributes (org.wildfly.clustering.web.session.ImmutableSessionAttributes)9 Map (java.util.Map)7 Instant (java.time.Instant)5 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)4 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)4 Session (io.undertow.server.session.Session)2 Duration (java.time.Duration)2 SimpleImmutableSession (org.wildfly.clustering.web.cache.session.SimpleImmutableSession)2 ValidSession (org.wildfly.clustering.web.cache.session.ValidSession)2 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)2 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