Search in sources :

Example 26 with BatchContext

use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.

the class DistributableSessionTestCase method getLastAccessedTime.

@Test
public void getLastAccessedTime() {
    this.validate(session -> session.getLastAccessedTime());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Instant now = Instant.now();
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getLastAccessedTime()).thenReturn(now);
    long result = this.adapter.getLastAccessedTime();
    assertEquals(now.toEpochMilli(), result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) Instant(java.time.Instant) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 27 with BatchContext

use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.

the class DistributableSessionTestCase method setAttribute.

@Test
public void setAttribute() {
    String name = "name";
    Integer value = Integer.valueOf(1);
    this.validate(session -> session.setAttribute(name, value));
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    SessionListener listener = mock(SessionListener.class);
    SessionListeners listeners = new SessionListeners();
    listeners.addSessionListener(listener);
    Object expected = new Object();
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.setAttribute(name, value)).thenReturn(expected);
    when(this.manager.getSessionListeners()).thenReturn(listeners);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    Object result = this.adapter.setAttribute(name, value);
    assertSame(expected, result);
    verify(listener, never()).attributeAdded(this.adapter, name, value);
    verify(listener).attributeUpdated(this.adapter, name, value, expected);
    verify(listener, never()).attributeRemoved(same(this.adapter), same(name), any());
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionListeners(io.undertow.server.session.SessionListeners) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) BatchContext(org.wildfly.clustering.ee.BatchContext) SessionListener(io.undertow.server.session.SessionListener) Test(org.junit.Test)

Example 28 with BatchContext

use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.

the class DistributableSessionTestCase method getCreationTime.

@Test
public void getCreationTime() {
    this.validate(session -> session.getCreationTime());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    Instant now = Instant.now();
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    when(this.session.getMetaData()).thenReturn(metaData);
    when(metaData.getCreationTime()).thenReturn(now);
    long result = this.adapter.getCreationTime();
    assertEquals(now.toEpochMilli(), result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) Instant(java.time.Instant) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 29 with BatchContext

use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.

the class DistributableSessionTestCase method getAttributeNames.

@Test
public void getAttributeNames() {
    this.validate(session -> session.getAttributeNames());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionAttributes attributes = mock(SessionAttributes.class);
    Set<String> expected = Collections.singleton("name");
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.getAttributeNames()).thenReturn(expected);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    Object result = this.adapter.getAttributeNames();
    assertSame(expected, result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionAttributes(org.wildfly.clustering.web.session.SessionAttributes) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 30 with BatchContext

use of org.wildfly.clustering.ee.BatchContext in project wildfly by wildfly.

the class DistributableSessionTestCase method requestDone.

@Test
public void requestDone() {
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    HttpServerExchange exchange = new HttpServerExchange(null);
    when(this.session.isValid()).thenReturn(true);
    when(this.manager.getSessionManager()).thenReturn(manager);
    when(manager.getBatcher()).thenReturn(batcher);
    when(batcher.resumeBatch(this.batch)).thenReturn(context);
    this.adapter.requestDone(exchange);
    verify(this.session).close();
    verify(this.batch).close();
    verify(context).close();
    verify(this.closeTask).run();
    reset(this.batch, this.session, context, this.closeTask);
    when(this.session.isValid()).thenReturn(false);
    this.adapter.requestDone(exchange);
    verify(this.session, never()).close();
    verify(this.batch, never()).close();
    verify(context, never()).close();
    verify(this.closeTask, never()).run();
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Batch(org.wildfly.clustering.ee.Batch) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Aggregations

BatchContext (org.wildfly.clustering.ee.BatchContext)42 Test (org.junit.Test)30 Batch (org.wildfly.clustering.ee.Batch)19 AuthenticatedSession (io.undertow.security.api.AuthenticatedSessionManager.AuthenticatedSession)15 SessionAttributes (org.wildfly.clustering.web.session.SessionAttributes)11 SessionListeners (io.undertow.server.session.SessionListeners)9 SessionListener (io.undertow.server.session.SessionListener)8 Session (io.undertow.server.session.Session)6 SessionManager (io.undertow.server.session.SessionManager)6 HttpServerExchange (io.undertow.server.HttpServerExchange)5 SessionMetaData (org.wildfly.clustering.web.session.SessionMetaData)5 Account (io.undertow.security.idm.Account)4 Instant (java.time.Instant)3 SessionConfig (io.undertow.server.session.SessionConfig)2 CachedAuthenticatedSessionHandler (io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler)2 Transaction (javax.transaction.Transaction)2 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1