Search in sources :

Example 21 with BatchContext

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

the class DistributableSessionTestCase method removeNonExistingAttribute.

@Test
public void removeNonExistingAttribute() {
    String name = "name";
    this.validate(session -> session.removeAttribute(name));
    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);
    when(this.session.getAttributes()).thenReturn(attributes);
    when(attributes.removeAttribute(name)).thenReturn(null);
    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.removeAttribute(name);
    assertNull(result);
    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 22 with BatchContext

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

the class DistributableSessionTestCase method getMaxInactiveInterval.

@Test
public void getMaxInactiveInterval() {
    this.validate(session -> session.getMaxInactiveInterval());
    SessionManager<LocalSessionContext, Batch> manager = mock(SessionManager.class);
    Batcher<Batch> batcher = mock(Batcher.class);
    BatchContext context = mock(BatchContext.class);
    SessionMetaData metaData = mock(SessionMetaData.class);
    long expected = 3600L;
    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.getMaxInactiveInterval()).thenReturn(Duration.ofSeconds(expected));
    long result = this.adapter.getMaxInactiveInterval();
    assertEquals(expected, result);
    verify(context).close();
}
Also used : Batch(org.wildfly.clustering.ee.Batch) SessionMetaData(org.wildfly.clustering.web.session.SessionMetaData) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 23 with BatchContext

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

the class InfinispanBatcherTestCase method resumeBatch.

@Test
public void resumeBatch() throws Exception {
    TransactionBatch batch = mock(TransactionBatch.class);
    Transaction tx = mock(Transaction.class);
    when(batch.getTransaction()).thenReturn(tx);
    try (BatchContext context = this.batcher.resumeBatch(batch)) {
        verify(this.tm, never()).suspend();
        verify(this.tm).resume(tx);
        reset(this.tm);
        assertSame(batch, InfinispanBatcher.CURRENT_BATCH.get());
    }
    verify(this.tm).suspend();
    verify(this.tm, never()).resume(any());
    assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
Also used : Transaction(javax.transaction.Transaction) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 24 with BatchContext

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

the class InfinispanBatcherTestCase method resumeBatchExisting.

@Test
public void resumeBatchExisting() throws Exception {
    TransactionBatch existingBatch = mock(TransactionBatch.class);
    Transaction existingTx = mock(Transaction.class);
    InfinispanBatcher.CURRENT_BATCH.set(existingBatch);
    TransactionBatch batch = mock(TransactionBatch.class);
    Transaction tx = mock(Transaction.class);
    when(existingBatch.getTransaction()).thenReturn(existingTx);
    when(batch.getTransaction()).thenReturn(tx);
    when(this.tm.suspend()).thenReturn(existingTx);
    try (BatchContext context = this.batcher.resumeBatch(batch)) {
        verify(this.tm).resume(tx);
        reset(this.tm);
        assertSame(batch, InfinispanBatcher.CURRENT_BATCH.get());
        when(this.tm.suspend()).thenReturn(tx);
    }
    verify(this.tm).resume(existingTx);
    assertSame(existingBatch, InfinispanBatcher.CURRENT_BATCH.get());
}
Also used : Transaction(javax.transaction.Transaction) BatchContext(org.wildfly.clustering.ee.BatchContext) Test(org.junit.Test)

Example 25 with BatchContext

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

the class InfinispanBatcherTestCase method resumeNonTxBatch.

@Test
public void resumeNonTxBatch() throws Exception {
    TransactionBatch existingBatch = mock(TransactionBatch.class);
    InfinispanBatcher.CURRENT_BATCH.set(existingBatch);
    TransactionBatch batch = mock(TransactionBatch.class);
    try (BatchContext context = this.batcher.resumeBatch(batch)) {
        verifyZeroInteractions(this.tm);
        assertSame(batch, InfinispanBatcher.CURRENT_BATCH.get());
    }
    verifyZeroInteractions(this.tm);
    assertSame(existingBatch, InfinispanBatcher.CURRENT_BATCH.get());
}
Also used : 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