use of org.wildfly.clustering.web.session.ImmutableSessionMetaData in project wildfly by wildfly.
the class ExpiredSessionRemoverTestCase method test.
@Test
public void test() {
SessionFactory<UUID, UUID, Object> factory = mock(SessionFactory.class);
SessionMetaDataFactory<UUID, Object> metaDataFactory = mock(SessionMetaDataFactory.class);
SessionAttributesFactory<UUID> attributesFactory = mock(SessionAttributesFactory.class);
SessionExpirationListener listener = mock(SessionExpirationListener.class);
ImmutableSessionAttributes expiredAttributes = mock(ImmutableSessionAttributes.class);
ImmutableSessionMetaData validMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData expiredMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSession expiredSession = mock(ImmutableSession.class);
String missingSessionId = "missing";
String expiredSessionId = "expired";
String validSessionId = "valid";
UUID expiredMetaDataValue = UUID.randomUUID();
UUID expiredAttributesValue = UUID.randomUUID();
UUID validMetaDataValue = UUID.randomUUID();
Remover<String> subject = new ExpiredSessionRemover<>(factory, listener);
when(factory.getMetaDataFactory()).thenReturn(metaDataFactory);
when(factory.getAttributesFactory()).thenReturn(attributesFactory);
when(metaDataFactory.tryValue(missingSessionId)).thenReturn(null);
when(metaDataFactory.tryValue(expiredSessionId)).thenReturn(expiredMetaDataValue);
when(metaDataFactory.tryValue(validSessionId)).thenReturn(validMetaDataValue);
when(metaDataFactory.createImmutableSessionMetaData(expiredSessionId, expiredMetaDataValue)).thenReturn(expiredMetaData);
when(metaDataFactory.createImmutableSessionMetaData(validSessionId, validMetaDataValue)).thenReturn(validMetaData);
when(expiredMetaData.isExpired()).thenReturn(true);
when(validMetaData.isExpired()).thenReturn(false);
when(attributesFactory.findValue(expiredSessionId)).thenReturn(expiredAttributesValue);
when(attributesFactory.createImmutableSessionAttributes(expiredSessionId, expiredAttributesValue)).thenReturn(expiredAttributes);
when(factory.createImmutableSession(same(expiredSessionId), same(expiredMetaData), same(expiredAttributes))).thenReturn(expiredSession);
subject.remove(missingSessionId);
subject.remove(expiredSessionId);
subject.remove(validSessionId);
verify(factory).remove(expiredSessionId);
verify(factory, never()).remove(missingSessionId);
verify(factory, never()).remove(validSessionId);
verify(listener).sessionExpired(expiredSession);
}
use of org.wildfly.clustering.web.session.ImmutableSessionMetaData 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());
}
use of org.wildfly.clustering.web.session.ImmutableSessionMetaData in project wildfly by wildfly.
the class SessionEvictionSchedulerTestCase method test.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void test() throws Exception {
String name = "cache";
String evictedSessionId = "evicted";
String activeSessionId = "active";
ImmutableSessionMetaData evictedSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData activeSessionMetaData = mock(ImmutableSessionMetaData.class);
CommandDispatcherFactory dispatcherFactory = mock(CommandDispatcherFactory.class);
CommandDispatcher<SessionEvictionContext> dispatcher = mock(CommandDispatcher.class);
Evictor<String> evictor = mock(Evictor.class);
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
ArgumentCaptor<Command> capturedCommand = ArgumentCaptor.forClass(Command.class);
ArgumentCaptor<SessionEvictionContext> capturedContext = ArgumentCaptor.forClass(SessionEvictionContext.class);
when(dispatcherFactory.createCommandDispatcher(same(name), capturedContext.capture())).thenReturn(dispatcher);
try (Scheduler scheduler = new SessionEvictionScheduler(name, evictor, batcher, dispatcherFactory, 1)) {
SessionEvictionContext context = capturedContext.getValue();
assertSame(scheduler, context);
scheduler.schedule(evictedSessionId, evictedSessionMetaData);
verifyZeroInteractions(dispatcher);
scheduler.schedule(activeSessionId, activeSessionMetaData);
verify(dispatcher).submitOnCluster(capturedCommand.capture());
when(batcher.createBatch()).thenReturn(batch);
capturedCommand.getValue().execute(context);
verify(evictor).evict(evictedSessionId);
verify(batch).close();
verify(evictor, never()).evict(activeSessionId);
}
verify(dispatcher).close();
}
use of org.wildfly.clustering.web.session.ImmutableSessionMetaData in project wildfly by wildfly.
the class SessionExpirationSchedulerTestCase method test.
@Test
public void test() throws InterruptedException {
Batcher<TransactionBatch> batcher = mock(Batcher.class);
TransactionBatch batch = mock(TransactionBatch.class);
Remover<String> remover = mock(Remover.class);
ImmutableSessionMetaData immortalSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData expiringSessionMetaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionMetaData canceledSessionMetaData = mock(ImmutableSessionMetaData.class);
String immortalSessionId = "immortal";
String expiringSessionId = "expiring";
String canceledSessionId = "canceled";
when(batcher.createBatch()).thenReturn(batch);
when(immortalSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ZERO);
when(expiringSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofMillis(1L));
when(canceledSessionMetaData.getMaxInactiveInterval()).thenReturn(Duration.ofSeconds(100L));
Instant now = Instant.now();
when(expiringSessionMetaData.getLastAccessedTime()).thenReturn(now);
when(canceledSessionMetaData.getLastAccessedTime()).thenReturn(now);
try (Scheduler scheduler = new SessionExpirationScheduler(batcher, remover)) {
scheduler.schedule(immortalSessionId, immortalSessionMetaData);
scheduler.schedule(canceledSessionId, canceledSessionMetaData);
scheduler.schedule(expiringSessionId, expiringSessionMetaData);
TimeUnit.SECONDS.sleep(1L);
scheduler.cancel(canceledSessionId);
scheduler.schedule(canceledSessionId, canceledSessionMetaData);
}
verify(remover, never()).remove(immortalSessionId);
verify(remover).remove(expiringSessionId);
verify(remover, never()).remove(canceledSessionId);
verify(batch).close();
}
Aggregations