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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations