use of org.infinispan.util.ControlledTimeService in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method setup.
@BeforeMethod(alwaysRun = true)
public void setup() {
nextInterceptor = new ControlledNextInterceptor();
timeService = new ControlledTimeService();
ctx = new SingleKeyNonTxInvocationContext(null);
interceptor = new CacheMgmtInterceptor();
interceptor.setNextInterceptor(nextInterceptor);
TestingUtil.inject(interceptor, timeService);
interceptor.start();
interceptor.setStatisticsEnabled(true);
}
use of org.infinispan.util.ControlledTimeService in project infinispan by infinispan.
the class CacheContainerStatsMBeanTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
timeService = new ControlledTimeService();
ConfigurationBuilder defaultConfig = new ConfigurationBuilder();
GlobalConfigurationBuilder gcb1 = GlobalConfigurationBuilder.defaultClusteredBuilder();
gcb1.cacheContainer().statistics(true).jmx().enabled(true).domain(JMX_DOMAIN).mBeanServerLookup(mBeanServerLookup).metrics().accurateSize(true);
CacheContainer cacheManager1 = TestCacheManagerFactory.createClusteredCacheManager(gcb1, defaultConfig, new TransportFlags());
TestingUtil.replaceComponent(cacheManager1, TimeService.class, timeService, true);
cacheManager1.start();
GlobalConfigurationBuilder gcb2 = GlobalConfigurationBuilder.defaultClusteredBuilder();
gcb2.cacheContainer().statistics(true).jmx().enabled(true).domain(JMX_DOMAIN + 2).mBeanServerLookup(mBeanServerLookup);
CacheContainer cacheManager2 = TestCacheManagerFactory.createClusteredCacheManager(gcb2, defaultConfig, new TransportFlags());
TestingUtil.replaceComponent(cacheManager2, TimeService.class, timeService, true);
cacheManager2.start();
registerCacheManager(cacheManager1, cacheManager2);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.clustering().cacheMode(CacheMode.REPL_SYNC).statistics().enable();
defineConfigurationOnAllManagers(cachename, cb);
defineConfigurationOnAllManagers(cachename2, cb);
waitForClusterToForm(cachename);
}
use of org.infinispan.util.ControlledTimeService in project infinispan by infinispan.
the class StatsMinNodeTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
ConfigurationBuilder cfg = getDefaultClusteredCacheConfig(cacheMode, false);
configure(cfg);
for (int i = 0; i < NUM_NODES; ++i) {
addClusterEnabledCacheManager(cfg);
}
waitForClusterToForm();
timeService = new ControlledTimeService();
for (int i = 0; i < NUM_NODES; ++i) {
TestingUtil.replaceComponent(manager(i), TimeService.class, timeService, true);
}
}
use of org.infinispan.util.ControlledTimeService in project infinispan by infinispan.
the class OffHeapSingleNodeTest method configureTimeService.
protected void configureTimeService() {
timeService = new ControlledTimeService();
TestingUtil.replaceComponent(cacheManagers.get(0), TimeService.class, timeService, true);
}
use of org.infinispan.util.ControlledTimeService in project infinispan by infinispan.
the class TestSessionAccessImpl method mockSession.
@Override
public Object mockSession(Class<? extends JtaPlatform> jtaPlatform, ControlledTimeService timeService, RegionFactory regionFactory) {
SessionMock session = mock(SessionMock.class);
when(session.isClosed()).thenReturn(false);
when(session.isOpen()).thenReturn(true);
when(session.getTransactionStartTimestamp()).thenReturn(timeService.wallClockTime());
TransactionCoordinator txCoord;
if (jtaPlatform == BatchModeJtaPlatform.class) {
BatchModeTransactionCoordinator batchModeTxCoord = new BatchModeTransactionCoordinator();
txCoord = batchModeTxCoord;
when(session.getTransactionCoordinator()).thenReturn(txCoord);
when(session.beginTransaction()).then(invocation -> {
Transaction tx = batchModeTxCoord.newTransaction();
tx.begin();
return tx;
});
} else if (jtaPlatform == null || jtaPlatform == NoJtaPlatform.class) {
Connection connection = mock(Connection.class);
JdbcConnectionAccess jdbcConnectionAccess = mock(JdbcConnectionAccess.class);
try {
when(jdbcConnectionAccess.obtainConnection()).thenReturn(connection);
} catch (SQLException e) {
// never thrown from mock
}
JdbcSessionOwner jdbcSessionOwner = mock(JdbcSessionOwner.class);
when(jdbcSessionOwner.getJdbcConnectionAccess()).thenReturn(jdbcConnectionAccess);
SqlExceptionHelper sqlExceptionHelper = mock(SqlExceptionHelper.class);
JdbcServices jdbcServices = mock(JdbcServices.class);
when(jdbcServices.getSqlExceptionHelper()).thenReturn(sqlExceptionHelper);
ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
when(serviceRegistry.getService(JdbcServices.class)).thenReturn(jdbcServices);
JdbcSessionContext jdbcSessionContext = mock(JdbcSessionContext.class);
when(jdbcSessionContext.getServiceRegistry()).thenReturn(serviceRegistry);
JpaCompliance jpaCompliance = mock(JpaCompliance.class);
when(jpaCompliance.isJpaTransactionComplianceEnabled()).thenReturn(true);
SessionFactoryImplementor sessionFactory = mock(SessionFactoryImplementor.class);
SessionFactoryOptions sessionFactoryOptions = mock(SessionFactoryOptions.class);
when(sessionFactoryOptions.getJpaCompliance()).thenReturn(jpaCompliance);
when(sessionFactory.getSessionFactoryOptions()).thenReturn(sessionFactoryOptions);
when(jdbcSessionContext.getSessionFactory()).thenReturn(sessionFactory);
when(jdbcSessionOwner.getJdbcSessionContext()).thenReturn(jdbcSessionContext);
when(session.getSessionFactory()).thenReturn(sessionFactory);
when(session.getFactory()).thenReturn(sessionFactory);
NonJtaTransactionCoordinator txOwner = mock(NonJtaTransactionCoordinator.class);
when(txOwner.getResourceLocalTransaction()).thenReturn(new JdbcResourceTransactionMock());
when(txOwner.getJdbcSessionOwner()).thenReturn(jdbcSessionOwner);
when(txOwner.isActive()).thenReturn(true);
txCoord = JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE.buildTransactionCoordinator(txOwner, null);
when(session.getTransactionCoordinator()).thenReturn(txCoord);
when(session.beginTransaction()).then(invocation -> {
Transaction tx = new TransactionImpl(txCoord, session.getExceptionConverter(), session);
tx.begin();
return tx;
});
} else {
throw new IllegalStateException("Unknown JtaPlatform: " + jtaPlatform);
}
Sync sync = new Sync(regionFactory);
TestSynchronization synchronization = new TestSynchronization(sync);
when(session.getCacheTransactionSynchronization()).thenAnswer(invocation -> {
if (!synchronization.registered) {
txCoord.getLocalSynchronizations().registerSynchronization(synchronization);
synchronization.registered = true;
}
return sync;
});
return session;
}
Aggregations