Search in sources :

Example 1 with ControlledTimeService

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);
}
Also used : ControlledTimeService(org.infinispan.util.ControlledTimeService) SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with ControlledTimeService

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);
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) CacheContainer(org.infinispan.manager.CacheContainer) TransportFlags(org.infinispan.test.fwk.TransportFlags) ControlledTimeService(org.infinispan.util.ControlledTimeService)

Example 3 with ControlledTimeService

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);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ControlledTimeService(org.infinispan.util.ControlledTimeService)

Example 4 with ControlledTimeService

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);
}
Also used : ControlledTimeService(org.infinispan.util.ControlledTimeService)

Example 5 with ControlledTimeService

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;
}
Also used : Connection(java.sql.Connection) TestSessionAccess(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess) Sync(org.infinispan.hibernate.cache.v53.impl.Sync) JdbcResourceTransactionMock(org.infinispan.test.hibernate.cache.commons.util.JdbcResourceTransactionMock) BatchModeJtaPlatform(org.infinispan.test.hibernate.cache.commons.util.BatchModeJtaPlatform) Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) AccessType(org.hibernate.cache.spi.access.AccessType) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Synchronization(javax.transaction.Synchronization) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) JdbcResourceTransactionAccess(org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) SoftLock(org.hibernate.cache.spi.access.SoftLock) JdbcSessionOwner(org.hibernate.resource.jdbc.spi.JdbcSessionOwner) ControlledTimeService(org.infinispan.util.ControlledTimeService) List(java.util.List) CacheException(org.hibernate.cache.CacheException) TransactionImpl(org.hibernate.engine.transaction.internal.TransactionImpl) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Mockito.mock(org.mockito.Mockito.mock) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DomainDataCachingConfig(org.hibernate.cache.cfg.spi.DomainDataCachingConfig) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator) Session(org.hibernate.Session) MetaInfServices(org.kohsuke.MetaInfServices) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) DirectAccessRegion(org.hibernate.cache.spi.DirectAccessRegion) CachedDomainDataAccess(org.hibernate.cache.spi.access.CachedDomainDataAccess) SQLException(java.sql.SQLException) RegionFactory(org.hibernate.cache.spi.RegionFactory) TransactionCoordinatorOwner(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) AbstractSharedSessionContract(org.hibernate.internal.AbstractSharedSessionContract) FlushMode(org.hibernate.FlushMode) CacheImplementor(org.hibernate.cache.spi.CacheImplementor) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) JdbcSessionContext(org.hibernate.resource.jdbc.spi.JdbcSessionContext) Mockito.when(org.mockito.Mockito.when) ServiceRegistry(org.hibernate.service.ServiceRegistry) InfinispanBaseRegion(org.infinispan.hibernate.cache.commons.InfinispanBaseRegion) Status(javax.transaction.Status) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) SqlExceptionHelper(org.hibernate.engine.jdbc.spi.SqlExceptionHelper) SessionCreationOptions(org.hibernate.internal.SessionCreationOptions) JpaCompliance(org.hibernate.jpa.spi.JpaCompliance) JdbcResourceTransactionMock(org.infinispan.test.hibernate.cache.commons.util.JdbcResourceTransactionMock) JdbcSessionContext(org.hibernate.resource.jdbc.spi.JdbcSessionContext) SQLException(java.sql.SQLException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator) Connection(java.sql.Connection) JpaCompliance(org.hibernate.jpa.spi.JpaCompliance) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) TransactionImpl(org.hibernate.engine.transaction.internal.TransactionImpl) SqlExceptionHelper(org.hibernate.engine.jdbc.spi.SqlExceptionHelper) JdbcSessionOwner(org.hibernate.resource.jdbc.spi.JdbcSessionOwner) Transaction(org.hibernate.Transaction) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) ServiceRegistry(org.hibernate.service.ServiceRegistry) Sync(org.infinispan.hibernate.cache.v53.impl.Sync)

Aggregations

ControlledTimeService (org.infinispan.util.ControlledTimeService)24 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)8 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 TimeService (org.infinispan.commons.time.TimeService)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Cache (javax.cache.Cache)1 Factory (javax.cache.configuration.Factory)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 Duration (javax.cache.expiry.Duration)1 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)1 Status (javax.transaction.Status)1 Synchronization (javax.transaction.Synchronization)1 FlushMode (org.hibernate.FlushMode)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1