use of org.wildfly.clustering.ee.infinispan.TransactionBatch in project wildfly by wildfly.
the class InfinispanSessionManagerFactory method createSessionManager.
@Override
public <L> SessionManager<L, TransactionBatch> createSessionManager(final SessionManagerConfiguration<L> configuration) {
final Batcher<TransactionBatch> batcher = new InfinispanBatcher(this.config.getCache());
final Cache<Key<String>, ?> cache = this.config.getCache();
final CacheProperties properties = new InfinispanCacheProperties(cache.getCacheConfiguration());
final IdentifierFactory<String> factory = new AffinityIdentifierFactory<>(configuration.getIdentifierFactory(), cache, this.config.getKeyAffinityServiceFactory());
final CommandDispatcherFactory dispatcherFactory = this.config.getCommandDispatcherFactory();
final NodeFactory<Address> nodeFactory = this.config.getNodeFactory();
final int maxActiveSessions = this.config.getSessionManagerFactoryConfiguration().getMaxActiveSessions();
InfinispanSessionManagerConfiguration config = new InfinispanSessionManagerConfiguration() {
@Override
public SessionExpirationListener getExpirationListener() {
return configuration.getExpirationListener();
}
@Override
public ServletContext getServletContext() {
return configuration.getServletContext();
}
@Override
public Cache<Key<String>, ?> getCache() {
return cache;
}
@Override
public CacheProperties getProperties() {
return properties;
}
@Override
public IdentifierFactory<String> getIdentifierFactory() {
return factory;
}
@Override
public Batcher<TransactionBatch> getBatcher() {
return batcher;
}
@Override
public CommandDispatcherFactory getCommandDispatcherFactory() {
return dispatcherFactory;
}
@Override
public NodeFactory<Address> getNodeFactory() {
return nodeFactory;
}
@Override
public int getMaxActiveSessions() {
return maxActiveSessions;
}
@Override
public Recordable<ImmutableSession> getInactiveSessionRecorder() {
return configuration.getInactiveSessionRecorder();
}
};
return new InfinispanSessionManager<>(this.createSessionFactory(properties, configuration.getLocalContextFactory()), config);
}
use of org.wildfly.clustering.ee.infinispan.TransactionBatch 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();
}
Aggregations