use of org.infinispan.configuration.cache.ConfigurationBuilder in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method getCache.
protected AdvancedCache getCache(String regionName, DataType type, CacheDataDescription metadata) {
if (!manager.cacheExists(regionName)) {
String templateCacheName = baseConfigurations.get(regionName);
Configuration configuration = null;
ConfigurationBuilder builder = new ConfigurationBuilder();
if (templateCacheName != null) {
configuration = manager.getCacheConfiguration(templateCacheName);
if (configuration == null) {
log.customConfigForRegionNotFound(templateCacheName, regionName, type.key);
} else {
log.debugf("Region '%s' will use cache template '%s'", regionName, templateCacheName);
builder.read(configuration);
configureTransactionManager(builder);
// do not apply data type overrides to regions that set special cache configuration
}
}
if (configuration == null) {
configuration = dataTypeConfigurations.get(type);
if (configuration == null) {
throw new IllegalStateException("Configuration not defined for type " + type.key);
}
builder.read(configuration);
// overrides for data types are already applied, but we should check custom ones
}
ConfigurationBuilder override = configOverrides.get(regionName);
if (override != null) {
log.debugf("Region '%s' has additional configuration set through properties.", regionName);
builder.read(override.build(false));
}
if (getCacheKeysFactory() instanceof SimpleCacheKeysFactory) {
// the keys may not define hashCode/equals correctly (e.g. arrays)
if (metadata != null && metadata.getKeyType() != null) {
builder.dataContainer().keyEquivalence(new TypeEquivalance(metadata.getKeyType()));
}
}
if (globalStats != null) {
builder.jmxStatistics().enabled(globalStats).available(globalStats);
}
configuration = builder.build();
type.validate(configuration);
manager.defineConfiguration(regionName, configuration);
}
final AdvancedCache cache = manager.getCache(regionName).getAdvancedCache();
// TODO: not sure if this is needed in recent Infinispan
if (!cache.getStatus().allowInvocations()) {
cache.start();
}
return createCacheWrapper(cache);
}
use of org.infinispan.configuration.cache.ConfigurationBuilder in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method getOrCreateConfig.
private ConfigurationBuilder getOrCreateConfig(int prefixLoc, String key, int suffixLoc) {
final String name = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
ConfigurationBuilder builder = configOverrides.get(name);
if (builder == null) {
builder = new ConfigurationBuilder();
configOverrides.put(name, builder);
}
return builder;
}
use of org.infinispan.configuration.cache.ConfigurationBuilder in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testEnableStatistics.
@Test
public void testEnableStatistics() {
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
p.setProperty("hibernate.cache.infinispan.entity.cfg", "myentity-cache");
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
InfinispanRegionFactory factory = createRegionFactory(p);
try {
EmbeddedCacheManager manager = factory.getCacheManager();
assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
AdvancedCache cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String query = "org.hibernate.cache.internal.StandardQueryCache";
QueryResultsRegionImpl queryRegion = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
cache = queryRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().stateTransfer().fetchInMemoryState(true);
manager.defineConfiguration("timestamps", builder.build());
TimestampsRegionImpl timestampsRegion = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
cache = timestampsRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
cache = collectionRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
} finally {
factory.stop();
}
}
use of org.infinispan.configuration.cache.ConfigurationBuilder in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testTimestampValidation.
@Test(expected = CacheException.class)
public void testTimestampValidation() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = createProperties();
InputStream configStream = FileLookupFactory.newInstance().lookupFile(InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE, getClass().getClassLoader());
ConfigurationBuilderHolder cbh = new ParserRegistry().parse(configStream);
DefaultCacheManager manager = new DefaultCacheManager(cbh, true);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
manager.defineConfiguration(DEF_TIMESTAMPS_RESOURCE, builder.build());
try {
InfinispanRegionFactory factory = createRegionFactory(manager, p, null);
factory.start(CacheTestUtil.sfOptionsForStart(), p);
TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
} finally {
TestingUtil.killCacheManagers(manager);
}
}
use of org.infinispan.configuration.cache.ConfigurationBuilder in project hibernate-orm by hibernate.
the class PutFromLoadValidatorUnitTest method testGetForNullReleasePuts.
@Test
@TestForIssue(jiraKey = "HHH-9928")
public void testGetForNullReleasePuts() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.simpleCache(true).expiration().maxIdle(500);
Configuration ppCfg = cb.build();
InfinispanRegionFactory regionFactory = mock(InfinispanRegionFactory.class);
doReturn(ppCfg).when(regionFactory).getPendingPutsCacheConfiguration();
doAnswer(invocation -> TIME_SERVICE.wallClockTime()).when(regionFactory).nextTimestamp();
PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory, cm);
for (int i = 0; i < 100; ++i) {
try {
withTx(tm, () -> {
SharedSessionContractImplementor session = mock(SharedSessionContractImplementor.class);
testee.registerPendingPut(session, KEY1, 0);
return null;
});
TIME_SERVICE.advance(10);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
String ppName = cm.getCache().getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE;
Map ppCache = cm.getCache(ppName, false);
assertNotNull(ppCache);
Object pendingPutMap = ppCache.get(KEY1);
assertNotNull(pendingPutMap);
int size;
try {
Method sizeMethod = pendingPutMap.getClass().getMethod("size");
sizeMethod.setAccessible(true);
size = (Integer) sizeMethod.invoke(pendingPutMap);
} catch (Exception e) {
throw new RuntimeException(e);
}
// some of the pending puts need to be expired by now
assertTrue(size < 100);
// but some are still registered
assertTrue(size > 0);
}
Aggregations