Search in sources :

Example 1 with DummyInitializationContext

use of org.infinispan.persistence.DummyInitializationContext in project infinispan by infinispan.

the class TableManagerTest method createConnection.

@BeforeClass
public void createConnection() throws Exception {
    JdbcStringBasedStoreConfigurationBuilder storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
    UnitTestDatabaseManager.setDialect(storeBuilder);
    UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table());
    ConnectionFactoryConfiguration factoryConfiguration = UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
    if (factoryConfiguration instanceof SimpleConnectionFactoryConfiguration) {
        SimpleConnectionFactoryConfiguration simpleConfiguration = (SimpleConnectionFactoryConfiguration) factoryConfiguration;
        connectionFactory = ConnectionFactory.getConnectionFactory(SimpleConnectionFactory.class);
        connectionFactory.start(simpleConfiguration, connectionFactory.getClass().getClassLoader());
        connection = connectionFactory.getConnection();
    } else if (factoryConfiguration instanceof PooledConnectionFactoryConfiguration) {
        PooledConnectionFactoryConfiguration pooledConfiguration = (PooledConnectionFactoryConfiguration) factoryConfiguration;
        connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
        connectionFactory.start(pooledConfiguration, connectionFactory.getClass().getClassLoader());
        connection = connectionFactory.getConnection();
    }
    Cache<?, ?> cache = mock(Cache.class);
    when(cache.getCacheConfiguration()).thenReturn(new ConfigurationBuilder().build());
    JdbcStringBasedStoreConfiguration config = storeBuilder.create();
    GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class);
    when(globalConfiguration.classLoader()).thenReturn(getClass().getClassLoader());
    ctx = new DummyInitializationContext(config, cache, new TestObjectStreamMarshaller(), null, null, null, globalConfiguration, null, null, null);
    tableManager = TableManagerFactory.getManager(ctx, connectionFactory, config, "aName");
}
Also used : SimpleConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory) DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with DummyInitializationContext

use of org.infinispan.persistence.DummyInitializationContext in project infinispan by infinispan.

the class AsyncStoreStressTest method createAsyncStore.

private AsyncNonBlockingStore<Object, Object> createAsyncStore(NonBlockingStore backendStore, StoreConfiguration storeConfiguration) throws PersistenceException {
    AsyncNonBlockingStore<Object, Object> store = new AsyncNonBlockingStore<>(backendStore);
    BlockingManager blockingManager = new BlockingManagerImpl();
    TestingUtil.inject(blockingManager, new TestComponentAccessors.NamedComponent(KnownComponentNames.NON_BLOCKING_EXECUTOR, nonBlockingExecutor), new TestComponentAccessors.NamedComponent(KnownComponentNames.BLOCKING_EXECUTOR, blockingExecutor));
    TestingUtil.startComponent(blockingManager);
    Cache cacheMock = Mockito.mock(Cache.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(cacheMock.getAdvancedCache().getComponentRegistry().getComponent(KeyPartitioner.class)).thenReturn(SingleSegmentKeyPartitioner.getInstance());
    CompletionStages.join(store.start(new DummyInitializationContext(storeConfiguration, cacheMock, marshaller, new ByteBufferFactoryImpl(), new MarshalledEntryFactoryImpl(marshaller), nonBlockingExecutor, new GlobalConfigurationBuilder().globalState().persistentLocation(location).build(), blockingManager, null, new DefaultTimeService())));
    return store;
}
Also used : BlockingManagerImpl(org.infinispan.util.concurrent.BlockingManagerImpl) DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ByteBufferFactoryImpl(org.infinispan.commons.io.ByteBufferFactoryImpl) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TestComponentAccessors(org.infinispan.factories.impl.TestComponentAccessors) DefaultTimeService(org.infinispan.commons.time.DefaultTimeService) MarshalledEntryFactoryImpl(org.infinispan.marshall.persistence.impl.MarshalledEntryFactoryImpl) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Cache(org.infinispan.Cache)

Example 3 with DummyInitializationContext

use of org.infinispan.persistence.DummyInitializationContext in project infinispan by infinispan.

the class JCacheLoaderAdapterTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    TimeService timeService = new EmbeddedTimeService();
    marshaller = new TestObjectStreamMarshaller();
    MarshallableEntryFactory marshalledEntryFactory = new MarshalledEntryFactoryImpl(marshaller);
    ctx = new DummyInitializationContext() {

        @Override
        public TimeService getTimeService() {
            return timeService;
        }

        @Override
        public MarshallableEntryFactory getMarshallableEntryFactory() {
            return marshalledEntryFactory;
        }
    };
}
Also used : DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) EmbeddedTimeService(org.infinispan.util.EmbeddedTimeService) EmbeddedTimeService(org.infinispan.util.EmbeddedTimeService) TimeService(org.infinispan.commons.time.TimeService) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) MarshalledEntryFactoryImpl(org.infinispan.marshall.persistence.impl.MarshalledEntryFactoryImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with DummyInitializationContext

use of org.infinispan.persistence.DummyInitializationContext in project infinispan by infinispan.

the class AbstractStringBasedCacheStore method configureCacheManager.

public EmbeddedCacheManager configureCacheManager(boolean passivation, boolean preload, boolean eviction) {
    GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder().nonClusteredDefault().defaultCacheName("StringBasedCache");
    ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
    JdbcStringBasedStoreConfigurationBuilder storeBuilder = builder.persistence().passivation(passivation).addStore(JdbcStringBasedStoreConfigurationBuilder.class).preload(preload);
    connectionFactory = getConnectionFactory(storeBuilder);
    setTableManipulation(storeBuilder);
    if (eviction) {
        builder.memory().evictionType(EvictionType.COUNT).size(2);
    } else {
        builder.memory().evictionType(EvictionType.COUNT).size(-1);
    }
    tableConfiguration = storeBuilder.create().table();
    EmbeddedCacheManager defaultCacheManager = TestCacheManagerFactory.newDefaultCacheManager(true, gcb, builder);
    String cacheName = defaultCacheManager.getCache().getName();
    PersistenceMarshaller marshaller = defaultCacheManager.getCache().getAdvancedCache().getComponentRegistry().getPersistenceMarshaller();
    InitializationContext ctx = new DummyInitializationContext(null, null, marshaller, null, null, null, null, null, null, null);
    tableManager = TableManagerFactory.getManager(ctx, connectionFactory, storeBuilder.create(), cacheName);
    return defaultCacheManager;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) InitializationContext(org.infinispan.persistence.spi.InitializationContext) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 5 with DummyInitializationContext

use of org.infinispan.persistence.DummyInitializationContext in project infinispan by infinispan.

the class AbstractJpaStoreTest method createCacheStore.

protected JpaStore createCacheStore(GlobalConfiguration gc) {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.persistence().addStore(JpaStoreConfigurationBuilder.class).persistenceUnitName(PERSISTENCE_UNIT_NAME).entityClass(getEntityClass()).segmented(false);
    JpaStore store = new JpaStore();
    store.init(new DummyInitializationContext(builder.persistence().stores().get(0).create(), cm.getCache(), marshaller, null, entryFactory, new WithinThreadExecutor(), gc, blockingManager, null, cm.getGlobalComponentRegistry().getTimeService()));
    store.start();
    assertNotNull(store.getEntityManagerFactory());
    return store;
}
Also used : DummyInitializationContext(org.infinispan.persistence.DummyInitializationContext) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JpaStoreConfigurationBuilder(org.infinispan.persistence.jpa.configuration.JpaStoreConfigurationBuilder) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) JpaStoreConfigurationBuilder(org.infinispan.persistence.jpa.configuration.JpaStoreConfigurationBuilder)

Aggregations

DummyInitializationContext (org.infinispan.persistence.DummyInitializationContext)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)2 MarshalledEntryFactoryImpl (org.infinispan.marshall.persistence.impl.MarshalledEntryFactoryImpl)2 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)2 BeforeClass (org.testng.annotations.BeforeClass)2 Cache (org.infinispan.Cache)1 ByteBufferFactoryImpl (org.infinispan.commons.io.ByteBufferFactoryImpl)1 DefaultTimeService (org.infinispan.commons.time.DefaultTimeService)1 TimeService (org.infinispan.commons.time.TimeService)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 TestComponentAccessors (org.infinispan.factories.impl.TestComponentAccessors)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)1 AsyncNonBlockingStore (org.infinispan.persistence.async.AsyncNonBlockingStore)1 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 SimpleConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)1 SimpleConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory)1