use of org.infinispan.marshall.TestObjectStreamMarshaller 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");
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class BoundedSingleFileStoreTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
clearTempDir();
store = new SingleFileStore<>();
ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
builder.persistence().addStore(SingleFileStoreConfigurationBuilder.class).location(this.tmpDirectory).segmented(false).maxEntries(1);
marshaller = new TestObjectStreamMarshaller();
CompletionStages.join(store.start(PersistenceMockUtil.createContext(getClass(), builder.build(), marshaller)));
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class DistributedStreamIteratorWithPassivationTest method testConcurrentActivation.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivation() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<MagicKey, String> cache0 = cache(0, CACHE_NAME);
Cache<MagicKey, String> cache1 = cache(1, CACHE_NAME);
Cache<MagicKey, String> cache2 = cache(2, CACHE_NAME);
Map<MagicKey, String> originalValues = new HashMap<>();
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
final MagicKey loaderKey = new MagicKey(cache0);
final String loaderValue = "loader0";
cache0.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache0, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache0, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache0.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<Map.Entry<MagicKey, String>> iterator = cache0.entrySet().stream().iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<MagicKey, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<MagicKey, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
assertEquals(count, 4);
assertEquals(originalValues, results);
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache0, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class DistributedStreamIteratorWithPassivationTest method testConcurrentActivationWithConverter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithConverter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<MagicKey, String> cache0 = cache(0, CACHE_NAME);
Cache<MagicKey, String> cache1 = cache(1, CACHE_NAME);
Cache<MagicKey, String> cache2 = cache(2, CACHE_NAME);
Map<MagicKey, String> originalValues = new HashMap<>();
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
final MagicKey loaderKey = new MagicKey(cache0);
final String loaderValue = "loader0";
cache0.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache0, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache0, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache0.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<CacheEntry<MagicKey, String>> iterator = cache0.getAdvancedCache().cacheEntrySet().stream().map(CacheFilters.function(new StringTruncator(1, 3))).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<MagicKey, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<MagicKey, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(count, 4);
for (Map.Entry<MagicKey, String> entry : originalValues.entrySet()) {
assertEquals(entry.getValue().substring(1, 4), results.get(entry.getKey()));
}
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache0, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class XmlFileParsingTest method assertNamedCacheFile.
private void assertNamedCacheFile(ConfigurationBuilderHolder holder, boolean deprecated) {
GlobalConfiguration gc = holder.getGlobalConfigurationBuilder().build();
EnhancedQueueExecutorFactory listenerThreadPool = gc.listenerThreadPool().threadPoolFactory();
assertEquals(5, listenerThreadPool.maxThreads());
assertEquals(10000, listenerThreadPool.queueLength());
DefaultThreadFactory listenerThreadFactory = gc.listenerThreadPool().threadFactory();
assertEquals("AsyncListenerThread", listenerThreadFactory.threadNamePattern());
AbstractThreadPoolExecutorFactory persistenceThreadPool = gc.persistenceThreadPool().threadPoolFactory();
assertNull(persistenceThreadPool);
AbstractThreadPoolExecutorFactory blockingThreadPool = gc.blockingThreadPool().threadPoolFactory();
assertEquals(6, blockingThreadPool.maxThreads());
assertEquals(10001, blockingThreadPool.queueLength());
DefaultThreadFactory persistenceThreadFactory = gc.blockingThreadPool().threadFactory();
assertEquals("BlockingThread", persistenceThreadFactory.threadNamePattern());
AbstractThreadPoolExecutorFactory asyncThreadPool = gc.asyncThreadPool().threadPoolFactory();
assertNull(asyncThreadPool);
AbstractThreadPoolExecutorFactory nonBlockingThreadPool = gc.nonBlockingThreadPool().threadPoolFactory();
assertEquals(5, nonBlockingThreadPool.coreThreads());
assertEquals(5, nonBlockingThreadPool.maxThreads());
assertEquals(10000, nonBlockingThreadPool.queueLength());
assertEquals(0, nonBlockingThreadPool.keepAlive());
DefaultThreadFactory asyncThreadFactory = gc.nonBlockingThreadPool().threadFactory();
assertEquals("NonBlockingThread", asyncThreadFactory.threadNamePattern());
AbstractThreadPoolExecutorFactory transportThreadPool = gc.transport().transportThreadPool().threadPoolFactory();
assertNull(transportThreadPool);
AbstractThreadPoolExecutorFactory remoteCommandThreadPool = gc.transport().remoteCommandThreadPool().threadPoolFactory();
assertNull(remoteCommandThreadPool);
AbstractThreadPoolExecutorFactory stateTransferThreadPool = gc.stateTransferThreadPool().threadPoolFactory();
assertNull(stateTransferThreadPool);
DefaultThreadFactory evictionThreadFactory = gc.expirationThreadPool().threadFactory();
assertEquals("ExpirationThread", evictionThreadFactory.threadNamePattern());
assertTrue(gc.transport().transport() instanceof JGroupsTransport);
assertEquals("infinispan-cluster", gc.transport().clusterName());
assertEquals("Jalapeno", gc.transport().nodeName());
assertEquals(50000, gc.transport().distributedSyncTimeout());
assertEquals(ShutdownHookBehavior.REGISTER, gc.shutdown().hookBehavior());
assertTrue(gc.serialization().marshaller() instanceof TestObjectStreamMarshaller);
final Map<Integer, AdvancedExternalizer<?>> externalizers = gc.serialization().advancedExternalizers();
assertEquals(3, externalizers.size());
assertTrue(externalizers.get(1234) instanceof AdvancedExternalizerTest.IdViaConfigObj.Externalizer);
assertTrue(externalizers.get(5678) instanceof AdvancedExternalizerTest.IdViaAnnotationObj.Externalizer);
assertTrue(externalizers.get(3456) instanceof AdvancedExternalizerTest.IdViaBothObj.Externalizer);
Configuration defaultCfg = holder.getDefaultConfigurationBuilder().build();
assertEquals(1000, defaultCfg.locking().lockAcquisitionTimeout());
assertEquals(100, defaultCfg.locking().concurrencyLevel());
assertEquals(IsolationLevel.REPEATABLE_READ, defaultCfg.locking().isolationLevel());
if (!deprecated) {
assertReaperAndTimeoutInfo(defaultCfg);
}
Configuration c = getCacheConfiguration(holder, "transactional");
assertFalse(c.clustering().cacheMode().isClustered());
assertTrue(c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup);
if (!deprecated) {
assertReaperAndTimeoutInfo(defaultCfg);
}
c = getCacheConfiguration(holder, "transactional2");
assertTrue(c.transaction().transactionManagerLookup() instanceof TestLookup);
assertEquals(10000, c.transaction().cacheStopTimeout());
assertEquals(LockingMode.PESSIMISTIC, c.transaction().lockingMode());
assertFalse(c.transaction().autoCommit());
c = getCacheConfiguration(holder, "syncInval");
assertEquals(CacheMode.INVALIDATION_SYNC, c.clustering().cacheMode());
assertTrue(c.clustering().stateTransfer().awaitInitialTransfer());
assertEquals(15000, c.clustering().remoteTimeout());
c = getCacheConfiguration(holder, "asyncInval");
assertEquals(CacheMode.INVALIDATION_ASYNC, c.clustering().cacheMode());
assertEquals(15000, c.clustering().remoteTimeout());
c = getCacheConfiguration(holder, "syncRepl");
assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode());
assertFalse(c.clustering().stateTransfer().fetchInMemoryState());
assertTrue(c.clustering().stateTransfer().awaitInitialTransfer());
assertEquals(15000, c.clustering().remoteTimeout());
c = getCacheConfiguration(holder, "asyncRepl");
assertEquals(CacheMode.REPL_ASYNC, c.clustering().cacheMode());
assertFalse(c.clustering().stateTransfer().fetchInMemoryState());
assertTrue(c.clustering().stateTransfer().awaitInitialTransfer());
c = getCacheConfiguration(holder, "txSyncRepl");
assertTrue(c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup);
assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode());
assertFalse(c.clustering().stateTransfer().fetchInMemoryState());
assertTrue(c.clustering().stateTransfer().awaitInitialTransfer());
assertEquals(15000, c.clustering().remoteTimeout());
c = getCacheConfiguration(holder, "overriding");
assertEquals(CacheMode.LOCAL, c.clustering().cacheMode());
assertEquals(20000, c.locking().lockAcquisitionTimeout());
assertEquals(1000, c.locking().concurrencyLevel());
assertEquals(IsolationLevel.REPEATABLE_READ, c.locking().isolationLevel());
assertEquals(StorageType.HEAP, c.memory().storageType());
c = getCacheConfiguration(holder, "storeAsBinary");
assertEquals(StorageType.BINARY, c.memory().storageType());
c = getCacheConfiguration(holder, "withFileStore");
assertTrue(c.persistence().preload());
assertFalse(c.persistence().passivation());
assertEquals(1, c.persistence().stores().size());
SoftIndexFileStoreConfiguration loaderCfg = (SoftIndexFileStoreConfiguration) c.persistence().stores().get(0);
assertTrue(loaderCfg.fetchPersistentState());
assertFalse(loaderCfg.ignoreModifications());
assertFalse(loaderCfg.purgeOnStartup());
assertEquals("/tmp/FileCacheStore-Location", loaderCfg.dataLocation());
assertTrue(loaderCfg.async().enabled());
assertEquals(700, loaderCfg.async().modificationQueueSize());
c = getCacheConfiguration(holder, "withClusterLoader");
assertEquals(1, c.persistence().stores().size());
ClusterLoaderConfiguration clusterLoaderCfg = (ClusterLoaderConfiguration) c.persistence().stores().get(0);
assertEquals(15000, clusterLoaderCfg.remoteCallTimeout());
c = getCacheConfiguration(holder, "withLoaderDefaults");
loaderCfg = (SoftIndexFileStoreConfiguration) c.persistence().stores().get(0);
assertEquals("/tmp/Another-FileCacheStore-Location", loaderCfg.dataLocation());
c = getCacheConfiguration(holder, "withouthJmxEnabled");
assertFalse(c.statistics().enabled());
assertTrue(gc.statistics());
assertTrue(gc.jmx().enabled());
assertEquals("funky_domain", gc.jmx().domain());
assertTrue(gc.jmx().mbeanServerLookup() instanceof TestMBeanServerLookup);
c = getCacheConfiguration(holder, "dist");
assertEquals(CacheMode.DIST_SYNC, c.clustering().cacheMode());
assertEquals(600000, c.clustering().l1().lifespan());
assertEquals(120000, c.clustering().stateTransfer().timeout());
assertEquals(1200, c.clustering().l1().cleanupTaskFrequency());
assertTrue(c.clustering().hash().consistentHashFactory() instanceof DefaultConsistentHashFactory);
assertEquals(3, c.clustering().hash().numOwners());
assertTrue(c.clustering().l1().enabled());
c = getCacheConfiguration(holder, "dist_with_capacity_factors");
assertEquals(CacheMode.DIST_SYNC, c.clustering().cacheMode());
assertEquals(600000, c.clustering().l1().lifespan());
assertEquals(120000, c.clustering().stateTransfer().timeout());
assertNull(c.clustering().hash().consistentHashFactory());
assertEquals(3, c.clustering().hash().numOwners());
assertTrue(c.clustering().l1().enabled());
assertEquals(0.0f, c.clustering().hash().capacityFactor());
if (!deprecated)
assertEquals(1000, c.clustering().hash().numSegments());
c = getCacheConfiguration(holder, "groups");
assertTrue(c.clustering().hash().groups().enabled());
assertEquals(1, c.clustering().hash().groups().groupers().size());
assertEquals(String.class, c.clustering().hash().groups().groupers().get(0).getKeyType());
c = getCacheConfiguration(holder, "chunkSize");
assertTrue(c.clustering().stateTransfer().fetchInMemoryState());
assertEquals(120000, c.clustering().stateTransfer().timeout());
assertEquals(1000, c.clustering().stateTransfer().chunkSize());
c = getCacheConfiguration(holder, "cacheWithCustomInterceptors");
assertFalse(c.customInterceptors().interceptors().isEmpty());
assertEquals(6, c.customInterceptors().interceptors().size());
for (InterceptorConfiguration i : c.customInterceptors().interceptors()) {
if (i.asyncInterceptor() instanceof FooInterceptor) {
assertEquals(i.properties().getProperty("foo"), "bar");
}
}
c = getCacheConfiguration(holder, "evictionCache");
assertEquals(5000, c.memory().size());
assertEquals(EvictionStrategy.REMOVE, c.memory().evictionStrategy());
assertEquals(EvictionType.COUNT, c.memory().evictionType());
assertEquals(StorageType.OBJECT, c.memory().storageType());
assertEquals(60000, c.expiration().lifespan());
assertEquals(1000, c.expiration().maxIdle());
assertEquals(500, c.expiration().wakeUpInterval());
c = getCacheConfiguration(holder, "evictionMemoryExceptionCache");
assertEquals(5000, c.memory().size());
assertEquals(EvictionStrategy.EXCEPTION, c.memory().evictionStrategy());
assertEquals(EvictionType.MEMORY, c.memory().evictionType());
assertEquals(StorageType.BINARY, c.memory().storageType());
c = getCacheConfiguration(holder, "storeKeyValueBinary");
assertEquals(StorageType.BINARY, c.memory().storageType());
}
Aggregations