Search in sources :

Example 1 with ConcurrentManager

use of org.wildfly.clustering.ee.cache.ConcurrentManager in project wildfly by wildfly.

the class ConcurrentSessionManagerTestCase method findInvalidSession.

@SuppressWarnings("unchecked")
@Test
public void findInvalidSession() {
    SessionManager<Void, Batch> manager = mock(SessionManager.class);
    SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
    Session<Void> expected1 = mock(Session.class);
    String id = "foo";
    SessionMetaData metaData1 = mock(SessionMetaData.class);
    SessionAttributes attributes1 = mock(SessionAttributes.class);
    when(manager.findSession(id)).thenReturn(expected1, (Session<Void>) null);
    when(expected1.getId()).thenReturn(id);
    when(expected1.isValid()).thenReturn(true);
    when(expected1.getAttributes()).thenReturn(attributes1);
    when(expected1.getMetaData()).thenReturn(metaData1);
    try (Session<Void> session1 = subject.findSession(id)) {
        assertNotNull(session1);
        assertSame(id, session1.getId());
        assertSame(metaData1, session1.getMetaData());
        assertSame(attributes1, session1.getAttributes());
        session1.invalidate();
        verify(expected1).invalidate();
        verify(expected1).close();
        Session<Void> session2 = subject.findSession(id);
        assertNull(session2);
    }
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) ConcurrentManager(org.wildfly.clustering.ee.cache.ConcurrentManager) Test(org.junit.Test)

Example 2 with ConcurrentManager

use of org.wildfly.clustering.ee.cache.ConcurrentManager in project wildfly by wildfly.

the class ConcurrentSessionManagerTestCase method createSession.

@SuppressWarnings("unchecked")
@Test
public void createSession() {
    SessionManager<Void, Batch> manager = mock(SessionManager.class);
    SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
    Session<Void> expected1 = mock(Session.class);
    Session<Void> expected2 = mock(Session.class);
    String id = "foo";
    SessionMetaData metaData1 = mock(SessionMetaData.class);
    SessionAttributes attributes1 = mock(SessionAttributes.class);
    SessionMetaData metaData2 = mock(SessionMetaData.class);
    SessionAttributes attributes2 = mock(SessionAttributes.class);
    when(manager.createSession(id)).thenReturn(expected1, expected2);
    when(expected1.getId()).thenReturn(id);
    when(expected1.isValid()).thenReturn(true);
    when(expected1.getAttributes()).thenReturn(attributes1);
    when(expected1.getMetaData()).thenReturn(metaData1);
    when(expected2.getId()).thenReturn(id);
    when(expected2.isValid()).thenReturn(true);
    when(expected2.getAttributes()).thenReturn(attributes2);
    when(expected2.getMetaData()).thenReturn(metaData2);
    try (Session<Void> session1 = subject.createSession(id)) {
        assertNotNull(session1);
        assertSame(id, session1.getId());
        assertSame(metaData1, session1.getMetaData());
        assertSame(attributes1, session1.getAttributes());
        try (Session<Void> session2 = subject.findSession(id)) {
            assertNotNull(session2);
            // Should return the same session without invoking the manager
            assertSame(session1, session2);
        }
        // Should not trigger Session.close() yet
        verify(expected1, never()).close();
    }
    verify(expected1).close();
    // Should use second session instance
    try (Session<Void> session = subject.createSession(id)) {
        assertNotNull(session);
        assertSame(id, session.getId());
        assertSame(metaData2, session.getMetaData());
        assertSame(attributes2, session.getAttributes());
    }
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) ConcurrentManager(org.wildfly.clustering.ee.cache.ConcurrentManager) Test(org.junit.Test)

Example 3 with ConcurrentManager

use of org.wildfly.clustering.ee.cache.ConcurrentManager in project wildfly by wildfly.

the class ConcurrentSessionManagerTestCase method findSession.

@SuppressWarnings("unchecked")
@Test
public void findSession() {
    SessionManager<Void, Batch> manager = mock(SessionManager.class);
    SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
    Session<Void> expected1 = mock(Session.class);
    Session<Void> expected2 = mock(Session.class);
    String id = "foo";
    SessionMetaData metaData1 = mock(SessionMetaData.class);
    SessionAttributes attributes1 = mock(SessionAttributes.class);
    SessionMetaData metaData2 = mock(SessionMetaData.class);
    SessionAttributes attributes2 = mock(SessionAttributes.class);
    when(manager.findSession(id)).thenReturn(expected1, expected2);
    when(expected1.getId()).thenReturn(id);
    when(expected1.isValid()).thenReturn(true);
    when(expected1.getAttributes()).thenReturn(attributes1);
    when(expected1.getMetaData()).thenReturn(metaData1);
    when(expected2.getId()).thenReturn(id);
    when(expected2.isValid()).thenReturn(true);
    when(expected2.getAttributes()).thenReturn(attributes2);
    when(expected2.getMetaData()).thenReturn(metaData2);
    try (Session<Void> session1 = subject.findSession(id)) {
        assertNotNull(session1);
        assertSame(id, session1.getId());
        assertSame(metaData1, session1.getMetaData());
        assertSame(attributes1, session1.getAttributes());
        try (Session<Void> session2 = subject.findSession(id)) {
            assertNotNull(session2);
            // Should return the same session without invoking the manager
            assertSame(session1, session2);
        }
        // Should not trigger Session.close() yet
        verify(expected1, never()).close();
    }
    verify(expected1).close();
    // Should use second session instance
    try (Session<Void> session = subject.findSession(id)) {
        assertNotNull(session);
        assertSame(id, session.getId());
        assertSame(metaData2, session.getMetaData());
        assertSame(attributes2, session.getAttributes());
    }
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) ConcurrentManager(org.wildfly.clustering.ee.cache.ConcurrentManager) Test(org.junit.Test)

Example 4 with ConcurrentManager

use of org.wildfly.clustering.ee.cache.ConcurrentManager in project wildfly by wildfly.

the class HotRodSessionManagerFactory method createSessionManager.

@Override
public SessionManager<LC, TransactionBatch> createSessionManager(SessionManagerConfiguration<SC> configuration) {
    Registrar<SessionExpirationListener> expirationRegistrar = this.expirationRegistrar;
    Batcher<TransactionBatch> batcher = this.batcher;
    Duration transactionTimeout = this.transactionTimeout;
    HotRodSessionManagerConfiguration<SC> config = new HotRodSessionManagerConfiguration<SC>() {

        @Override
        public SessionExpirationListener getExpirationListener() {
            return configuration.getExpirationListener();
        }

        @Override
        public Registrar<SessionExpirationListener> getExpirationRegistrar() {
            return expirationRegistrar;
        }

        @Override
        public Supplier<String> getIdentifierFactory() {
            return configuration.getIdentifierFactory();
        }

        @Override
        public SC getServletContext() {
            return configuration.getServletContext();
        }

        @Override
        public Batcher<TransactionBatch> getBatcher() {
            return batcher;
        }

        @Override
        public Duration getStopTimeout() {
            return transactionTimeout;
        }
    };
    return new ConcurrentSessionManager<>(new HotRodSessionManager<>(this.factory, config), ConcurrentManager::new);
}
Also used : SessionExpirationListener(org.wildfly.clustering.web.session.SessionExpirationListener) TransactionBatch(org.wildfly.clustering.ee.cache.tx.TransactionBatch) ConcurrentManager(org.wildfly.clustering.ee.cache.ConcurrentManager) Duration(java.time.Duration) ConcurrentSessionManager(org.wildfly.clustering.web.cache.session.ConcurrentSessionManager)

Aggregations

ConcurrentManager (org.wildfly.clustering.ee.cache.ConcurrentManager)4 Test (org.junit.Test)3 Batch (org.wildfly.clustering.ee.Batch)3 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)3 Duration (java.time.Duration)1 TransactionBatch (org.wildfly.clustering.ee.cache.tx.TransactionBatch)1 ConcurrentSessionManager (org.wildfly.clustering.web.cache.session.ConcurrentSessionManager)1 SessionExpirationListener (org.wildfly.clustering.web.session.SessionExpirationListener)1