Merge branch 'master' of github.com:hibernate/hibernate-core
This commit is contained in:
commit
7899d34ca4
|
@ -29,6 +29,14 @@
|
||||||
on the entity.
|
on the entity.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<important>
|
||||||
|
<para>
|
||||||
|
Unlike in previous versions, you no longer need to specify listeners in the Hibernate configuration
|
||||||
|
file. Just putting the Envers jar on the classpath is enough - listeners will be registered
|
||||||
|
automatically.
|
||||||
|
</para>
|
||||||
|
</important>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
And that's all - you can create, modify and delete the entites as always. If you look at the generated
|
And that's all - you can create, modify and delete the entites as always. If you look at the generated
|
||||||
schema for your entities, or at the data persisted by Hibernate, you will notice that there are no changes.
|
schema for your entities, or at the data persisted by Hibernate, you will notice that there are no changes.
|
||||||
|
|
|
@ -282,9 +282,9 @@ public class OptimizerFactory {
|
||||||
* <p/>
|
* <p/>
|
||||||
* The general algorithms used to determine the bucket are:<ol>
|
* The general algorithms used to determine the bucket are:<ol>
|
||||||
* <li>{@code upperLimit = (databaseValue * incrementSize) + 1}</li>
|
* <li>{@code upperLimit = (databaseValue * incrementSize) + 1}</li>
|
||||||
* <li>{@code lowerLimit = upperLimit - 1}</li>
|
* <li>{@code lowerLimit = upperLimit - incrementSize}</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
* As an example, consider a case with incrementSize of 10. Initially the
|
* As an example, consider a case with incrementSize of 20. Initially the
|
||||||
* database holds 1:<ol>
|
* database holds 1:<ol>
|
||||||
* <li>{@code upperLimit = (1 * 20) + 1 = 21}</li>
|
* <li>{@code upperLimit = (1 * 20) + 1 = 21}</li>
|
||||||
* <li>{@code lowerLimit = 21 - 20 = 1}</li>
|
* <li>{@code lowerLimit = 21 - 20 = 1}</li>
|
||||||
|
@ -457,7 +457,9 @@ public class OptimizerFactory {
|
||||||
// we are using a sequence...
|
// we are using a sequence...
|
||||||
if (value.lt(1)) LOG.pooledOptimizerReportedInitialValue(value);
|
if (value.lt(1)) LOG.pooledOptimizerReportedInitialValue(value);
|
||||||
// the call to obtain next-value just gave us the initialValue
|
// the call to obtain next-value just gave us the initialValue
|
||||||
if ((initialValue == -1 && value.lt(incrementSize)) || value.eq(initialValue)) hiValue = callback.getNextValue();
|
if ( ( initialValue == -1 && value.lt( incrementSize ) ) || value.eq( initialValue ) ) {
|
||||||
|
hiValue = callback.getNextValue();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
hiValue = value;
|
hiValue = value;
|
||||||
value = hiValue.copy().subtract( incrementSize );
|
value = hiValue.copy().subtract( incrementSize );
|
||||||
|
|
|
@ -5,7 +5,7 @@ configurations {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
infinispanVersion = '5.1.0.CR1'
|
infinispanVersion = '5.1.0.CR3'
|
||||||
jnpVersion = '5.0.3.GA'
|
jnpVersion = '5.0.3.GA'
|
||||||
|
|
||||||
compile(project(':hibernate-core'))
|
compile(project(':hibernate-core'))
|
||||||
|
@ -35,6 +35,8 @@ test {
|
||||||
systemProperties['jgroups.ping.num_initial_members'] = 1
|
systemProperties['jgroups.ping.num_initial_members'] = 1
|
||||||
systemProperties['jgroups.udp.enable_bundling'] = false
|
systemProperties['jgroups.udp.enable_bundling'] = false
|
||||||
systemProperties['jgroups.bind_addr'] = 'localhost'
|
systemProperties['jgroups.bind_addr'] = 'localhost'
|
||||||
|
// Use Infinispan's test JGroups stack that uses TEST_PING
|
||||||
|
systemProperties['hibernate.cache.infinispan.jgroups_cfg'] = 'stacks/tcp.xml'
|
||||||
// systemProperties['log4j.configuration'] = 'file:/log4j/log4j-infinispan.xml'
|
// systemProperties['log4j.configuration'] = 'file:/log4j/log4j-infinispan.xml'
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package org.hibernate.cache.infinispan;
|
package org.hibernate.cache.infinispan;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -7,7 +8,13 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
|
import org.hibernate.cache.infinispan.util.CacheCommandFactory;
|
||||||
|
import org.hibernate.cache.infinispan.util.CacheCommandInitializer;
|
||||||
import org.hibernate.cache.spi.CacheDataDescription;
|
import org.hibernate.cache.spi.CacheDataDescription;
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.cache.spi.CollectionRegion;
|
import org.hibernate.cache.spi.CollectionRegion;
|
||||||
|
@ -28,8 +35,9 @@ import org.hibernate.cache.infinispan.util.CacheAdapterImpl;
|
||||||
import org.hibernate.cfg.Settings;
|
import org.hibernate.cfg.Settings;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.infinispan.AdvancedCache;
|
import org.infinispan.AdvancedCache;
|
||||||
import org.infinispan.Cache;
|
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
|
import org.infinispan.factories.ComponentRegistry;
|
||||||
|
import org.infinispan.factories.GlobalComponentRegistry;
|
||||||
import org.infinispan.manager.DefaultCacheManager;
|
import org.infinispan.manager.DefaultCacheManager;
|
||||||
import org.infinispan.manager.EmbeddedCacheManager;
|
import org.infinispan.manager.EmbeddedCacheManager;
|
||||||
import org.infinispan.util.logging.Log;
|
import org.infinispan.util.logging.Log;
|
||||||
|
@ -155,6 +163,9 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
|
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
|
||||||
|
|
||||||
private TransactionManager transactionManager;
|
private TransactionManager transactionManager;
|
||||||
|
|
||||||
|
private ConcurrentMap<String, BaseRegion> allRegions =
|
||||||
|
new ConcurrentHashMap<String, BaseRegion>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance using the default configuration.
|
* Create a new instance using the default configuration.
|
||||||
|
@ -174,20 +185,20 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
|
public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
|
||||||
if (log.isDebugEnabled()) log.debug("Building collection cache region [" + regionName + "]");
|
if (log.isDebugEnabled()) log.debug("Building collection cache region [" + regionName + "]");
|
||||||
Cache cache = getCache(regionName, COLLECTION_KEY, properties);
|
AdvancedCache cache = getCache(regionName, COLLECTION_KEY, properties);
|
||||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||||
CollectionRegionImpl region = new CollectionRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
CollectionRegionImpl region = new CollectionRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
||||||
region.start();
|
startRegion(region, regionName);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
|
public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException {
|
||||||
if (log.isDebugEnabled()) log.debug("Building entity cache region [" + regionName + "]");
|
if (log.isDebugEnabled()) log.debug("Building entity cache region [" + regionName + "]");
|
||||||
Cache cache = getCache(regionName, ENTITY_KEY, properties);
|
AdvancedCache cache = getCache(regionName, ENTITY_KEY, properties);
|
||||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||||
EntityRegionImpl region = new EntityRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
EntityRegionImpl region = new EntityRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
||||||
region.start();
|
startRegion(region, regionName);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,10 +213,10 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
if (!regionName.equals("org.hibernate.cache.internal.StandardQueryCache"))
|
if (!regionName.equals("org.hibernate.cache.internal.StandardQueryCache"))
|
||||||
cacheName = regionName;
|
cacheName = regionName;
|
||||||
|
|
||||||
Cache cache = getCache(cacheName, QUERY_KEY, properties);
|
AdvancedCache cache = getCache(cacheName, QUERY_KEY, properties);
|
||||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||||
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
|
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
|
||||||
region.start();
|
startRegion(region, regionName);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +226,10 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties)
|
public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties)
|
||||||
throws CacheException {
|
throws CacheException {
|
||||||
if (log.isDebugEnabled()) log.debug("Building timestamps cache region [" + regionName + "]");
|
if (log.isDebugEnabled()) log.debug("Building timestamps cache region [" + regionName + "]");
|
||||||
Cache cache = getCache(regionName, TIMESTAMPS_KEY, properties);
|
AdvancedCache cache = getCache(regionName, TIMESTAMPS_KEY, properties);
|
||||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||||
TimestampsRegionImpl region = createTimestampsRegion(cacheAdapter, regionName);
|
TimestampsRegionImpl region = createTimestampsRegion(cacheAdapter, regionName);
|
||||||
region.start();
|
startRegion(region, regionName);
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,10 +237,6 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
return new TimestampsRegionImpl(cacheAdapter, regionName, transactionManager, this);
|
return new TimestampsRegionImpl(cacheAdapter, regionName, transactionManager, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TransactionManager getTransactionManager() {
|
|
||||||
return transactionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -270,7 +277,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
Enumeration keys = properties.propertyNames();
|
Enumeration keys = properties.propertyNames();
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
String key = (String) keys.nextElement();
|
String key = (String) keys.nextElement();
|
||||||
int prefixLoc = -1;
|
int prefixLoc;
|
||||||
if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
|
if ((prefixLoc = key.indexOf(PREFIX)) != -1) {
|
||||||
dissectProperty(prefixLoc, key, properties);
|
dissectProperty(prefixLoc, key, properties);
|
||||||
}
|
}
|
||||||
|
@ -310,11 +317,15 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
return Collections.unmodifiableSet(definedConfigurations);
|
return Collections.unmodifiableSet(definedConfigurations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseRegion getRegion(String regionName) {
|
||||||
|
return allRegions.get(regionName);
|
||||||
|
}
|
||||||
|
|
||||||
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
|
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
|
||||||
try {
|
try {
|
||||||
String configLoc = ConfigurationHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
String configLoc = ConfigurationHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
||||||
EmbeddedCacheManager manager = new DefaultCacheManager(configLoc, false);
|
EmbeddedCacheManager manager = new DefaultCacheManager(configLoc, false);
|
||||||
String globalStats = ConfigurationHelper.extractPropertyValue(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
|
String globalStats = extractProperty(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
|
||||||
if (globalStats != null) {
|
if (globalStats != null) {
|
||||||
manager.getGlobalConfiguration().setExposeGlobalJmxStatistics(Boolean.parseBoolean(globalStats));
|
manager.getGlobalConfiguration().setExposeGlobalJmxStatistics(Boolean.parseBoolean(globalStats));
|
||||||
}
|
}
|
||||||
|
@ -325,6 +336,10 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startRegion(BaseRegion region, String regionName) {
|
||||||
|
allRegions.put(regionName, region);
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, TypeOverrides> initGenericDataTypeOverrides() {
|
private Map<String, TypeOverrides> initGenericDataTypeOverrides() {
|
||||||
TypeOverrides entityOverrides = new TypeOverrides();
|
TypeOverrides entityOverrides = new TypeOverrides();
|
||||||
entityOverrides.setCacheName(DEF_ENTITY_RESOURCE);
|
entityOverrides.setCacheName(DEF_ENTITY_RESOURCE);
|
||||||
|
@ -342,31 +357,33 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dissectProperty(int prefixLoc, String key, Properties properties) {
|
private void dissectProperty(int prefixLoc, String key, Properties properties) {
|
||||||
TypeOverrides cfgOverride = null;
|
TypeOverrides cfgOverride;
|
||||||
int suffixLoc = -1;
|
int suffixLoc;
|
||||||
if (!key.equals(INFINISPAN_CONFIG_RESOURCE_PROP) && (suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1) {
|
if (!key.equals(INFINISPAN_CONFIG_RESOURCE_PROP) && (suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setCacheName( ConfigurationHelper.extractPropertyValue(key, properties));
|
cfgOverride.setCacheName(extractProperty(key, properties));
|
||||||
} else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
|
} else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setEvictionStrategy( ConfigurationHelper.extractPropertyValue(key, properties));
|
cfgOverride.setEvictionStrategy(extractProperty(key, properties));
|
||||||
} else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
|
} else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setEvictionWakeUpInterval(Long.parseLong( ConfigurationHelper.extractPropertyValue(key, properties)));
|
cfgOverride.setEvictionWakeUpInterval(Long.parseLong(extractProperty(key, properties)));
|
||||||
} else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
|
} else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setEvictionMaxEntries( ConfigurationHelper.getInt(key, properties, -1));
|
cfgOverride.setEvictionMaxEntries(Integer.parseInt(extractProperty(key, properties)));
|
||||||
} else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
|
} else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setExpirationLifespan(Long.parseLong( ConfigurationHelper.extractPropertyValue(key, properties)));
|
cfgOverride.setExpirationLifespan(Long.parseLong(extractProperty(key, properties)));
|
||||||
} else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
|
} else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
|
||||||
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
||||||
cfgOverride.setExpirationMaxIdle(Long.parseLong( ConfigurationHelper.extractPropertyValue(key, properties)));
|
cfgOverride.setExpirationMaxIdle(Long.parseLong(extractProperty(key, properties)));
|
||||||
}
|
}
|
||||||
// else if ((suffixLoc = key.indexOf(STATISTICS_SUFFIX)) != -1) {
|
}
|
||||||
// cfgOverride = getOrCreateConfig(prefixLoc, key, suffixLoc);
|
|
||||||
// cfgOverride.setExposeStatistics(Boolean.parseBoolean(PropertiesHelper.extractPropertyValue(key, properties)));
|
private String extractProperty(String key, Properties properties) {
|
||||||
// }
|
String value = ConfigurationHelper.extractPropertyValue(key, properties);
|
||||||
|
log.debugf("Configuration override via property %s: %s", key, value);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeOverrides getOrCreateConfig(int prefixLoc, String key, int suffixLoc) {
|
private TypeOverrides getOrCreateConfig(int prefixLoc, String key, int suffixLoc) {
|
||||||
|
@ -395,7 +412,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache getCache(String regionName, String typeKey, Properties properties) {
|
private AdvancedCache getCache(String regionName, String typeKey, Properties properties) {
|
||||||
TypeOverrides regionOverride = typeOverrides.get(regionName);
|
TypeOverrides regionOverride = typeOverrides.get(regionName);
|
||||||
if (!definedConfigurations.contains(regionName)) {
|
if (!definedConfigurations.contains(regionName)) {
|
||||||
String templateCacheName = null;
|
String templateCacheName = null;
|
||||||
|
@ -420,38 +437,46 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
manager.defineConfiguration(regionName, templateCacheName, regionCacheCfg);
|
manager.defineConfiguration(regionName, templateCacheName, regionCacheCfg);
|
||||||
definedConfigurations.add(regionName);
|
definedConfigurations.add(regionName);
|
||||||
}
|
}
|
||||||
Cache cache = manager.getCache(regionName);
|
AdvancedCache cache = manager.getCache(regionName).getAdvancedCache();
|
||||||
if (!cache.getStatus().allowInvocations()) {
|
if (!cache.getStatus().allowInvocations()) {
|
||||||
cache.start();
|
cache.start();
|
||||||
}
|
}
|
||||||
return createCacheWrapper(cache.getAdvancedCache());
|
ComponentRegistry cr = cache.getComponentRegistry();
|
||||||
|
cr.getComponent(CacheCommandInitializer.class).setRegionFactory(this);
|
||||||
|
GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
|
||||||
|
// TODO: This is a hack, make it easier to retrieve in Infinispan!
|
||||||
|
((CacheCommandFactory) ((Map) globalCr.getComponent("org.infinispan.modules.command.factories"))
|
||||||
|
.values().iterator().next()).setRegionFactory(this);
|
||||||
|
return createCacheWrapper(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClassLoaderAwareCache createCacheWrapper(AdvancedCache cache) {
|
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
||||||
return new ClassLoaderAwareCache(cache, Thread.currentThread().getContextClassLoader());
|
return new ClassLoaderAwareCache(cache, Thread.currentThread().getContextClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Configuration configureTransactionManager(Configuration regionOverrides, String templateCacheName, Properties properties) {
|
private Configuration configureTransactionManager(Configuration regionOverrides, String templateCacheName, Properties properties) {
|
||||||
// Get existing configuration to verify whether a tm was configured or not.
|
// Get existing configuration to verify whether a tm was configured or not.
|
||||||
Configuration templateConfig = manager.defineConfiguration(templateCacheName, new Configuration());
|
Configuration templateConfig = manager.defineConfiguration(templateCacheName, new Configuration());
|
||||||
String ispnTmLookupClassName = templateConfig.getTransactionManagerLookupClass();
|
if (templateConfig.isTransactionalCache()) {
|
||||||
String hbTmLookupClassName = org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup.class.getName();
|
String ispnTmLookupClassName = templateConfig.getTransactionManagerLookupClass();
|
||||||
if (ispnTmLookupClassName != null && !ispnTmLookupClassName.equals(hbTmLookupClassName)) {
|
String hbTmLookupClassName = org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup.class.getName();
|
||||||
log.debug("Infinispan is configured [" + ispnTmLookupClassName + "] with a different transaction manager lookup " +
|
if (ispnTmLookupClassName != null && !ispnTmLookupClassName.equals(hbTmLookupClassName)) {
|
||||||
"class than Hibernate [" + hbTmLookupClassName + "]");
|
log.debug("Infinispan is configured [" + ispnTmLookupClassName + "] with a different transaction manager lookup " +
|
||||||
} else {
|
"class than Hibernate [" + hbTmLookupClassName + "]");
|
||||||
regionOverrides.setTransactionManagerLookup(transactionManagerlookup);
|
} else {
|
||||||
}
|
regionOverrides.setTransactionManagerLookup(transactionManagerlookup);
|
||||||
|
}
|
||||||
|
|
||||||
String useSyncProp = ConfigurationHelper.extractPropertyValue(INFINISPAN_USE_SYNCHRONIZATION_PROP, properties);
|
String useSyncProp = extractProperty(INFINISPAN_USE_SYNCHRONIZATION_PROP, properties);
|
||||||
boolean useSync = useSyncProp == null ? DEF_USE_SYNCHRONIZATION : Boolean.parseBoolean(useSyncProp);
|
boolean useSync = useSyncProp == null ? DEF_USE_SYNCHRONIZATION : Boolean.parseBoolean(useSyncProp);
|
||||||
regionOverrides.fluent().transaction().useSynchronization(useSync);
|
regionOverrides.fluent().transaction().useSynchronization(useSync);
|
||||||
|
}
|
||||||
|
|
||||||
return regionOverrides;
|
return regionOverrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeOverrides overrideStatisticsIfPresent(TypeOverrides override, Properties properties) {
|
private TypeOverrides overrideStatisticsIfPresent(TypeOverrides override, Properties properties) {
|
||||||
String globalStats = ConfigurationHelper.extractPropertyValue(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
|
String globalStats = extractProperty(INFINISPAN_GLOBAL_STATISTICS_PROP, properties);
|
||||||
if (globalStats != null) {
|
if (globalStats != null) {
|
||||||
override.setExposeStatistics(Boolean.parseBoolean(globalStats));
|
override.setExposeStatistics(Boolean.parseBoolean(globalStats));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.cache.infinispan.access;
|
package org.hibernate.cache.infinispan.access;
|
||||||
|
|
||||||
import javax.transaction.Transaction;
|
import javax.transaction.Transaction;
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
||||||
|
@ -29,7 +30,6 @@ import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
||||||
import org.hibernate.cache.spi.access.SoftLock;
|
import org.hibernate.cache.spi.access.SoftLock;
|
||||||
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
||||||
import org.infinispan.util.logging.Log;
|
import org.infinispan.util.logging.Log;
|
||||||
import org.infinispan.util.logging.LogFactory;
|
import org.infinispan.util.logging.LogFactory;
|
||||||
|
@ -162,7 +162,8 @@ public class TransactionalAccessDelegate {
|
||||||
}
|
}
|
||||||
Transaction tx = region.suspend();
|
Transaction tx = region.suspend();
|
||||||
try {
|
try {
|
||||||
CacheHelper.sendEvictAllNotification(cacheAdapter, region.getAddress());
|
region.invalidateRegion(); // Invalidate the local region and then go remote
|
||||||
|
cacheAdapter.broadcastEvictAll();
|
||||||
} finally {
|
} finally {
|
||||||
region.resume(tx);
|
region.resume(tx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package org.hibernate.cache.infinispan.impl;
|
package org.hibernate.cache.infinispan.impl;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import javax.transaction.SystemException;
|
import javax.transaction.SystemException;
|
||||||
import javax.transaction.Transaction;
|
import javax.transaction.Transaction;
|
||||||
|
@ -13,17 +11,9 @@ import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.cache.spi.Region;
|
import org.hibernate.cache.spi.Region;
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.infinispan.util.AddressAdapter;
|
import org.hibernate.cache.infinispan.util.AddressAdapter;
|
||||||
import org.hibernate.cache.infinispan.util.AddressAdapterImpl;
|
|
||||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
||||||
|
|
||||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated;
|
|
||||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
|
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent;
|
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
|
|
||||||
import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
|
|
||||||
import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
|
|
||||||
import org.infinispan.util.logging.Log;
|
import org.infinispan.util.logging.Log;
|
||||||
import org.infinispan.util.logging.LogFactory;
|
import org.infinispan.util.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -37,12 +27,12 @@ import org.infinispan.util.logging.LogFactory;
|
||||||
* @since 3.5
|
* @since 3.5
|
||||||
*/
|
*/
|
||||||
public abstract class BaseRegion implements Region {
|
public abstract class BaseRegion implements Region {
|
||||||
|
|
||||||
private enum InvalidateState { INVALID, CLEARING, VALID };
|
private enum InvalidateState { INVALID, CLEARING, VALID };
|
||||||
private static final Log log = LogFactory.getLog(BaseRegion.class);
|
private static final Log log = LogFactory.getLog(BaseRegion.class);
|
||||||
private final String name;
|
private final String name;
|
||||||
protected final CacheAdapter cacheAdapter;
|
protected final CacheAdapter cacheAdapter;
|
||||||
protected final AddressAdapter address;
|
protected final AddressAdapter address;
|
||||||
protected final Set<AddressAdapter> currentView = new HashSet<AddressAdapter>();
|
|
||||||
protected final TransactionManager transactionManager;
|
protected final TransactionManager transactionManager;
|
||||||
protected final boolean replication;
|
protected final boolean replication;
|
||||||
protected final Object invalidationMutex = new Object();
|
protected final Object invalidationMutex = new Object();
|
||||||
|
@ -59,32 +49,6 @@ public abstract class BaseRegion implements Region {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
|
||||||
if (address != null) {
|
|
||||||
synchronized (currentView) {
|
|
||||||
List<AddressAdapter> view = cacheAdapter.getMembers();
|
|
||||||
if (view != null) {
|
|
||||||
currentView.addAll(view);
|
|
||||||
establishInternalNodes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls to this method must be done from synchronized (currentView) blocks only!!
|
|
||||||
*/
|
|
||||||
private void establishInternalNodes() {
|
|
||||||
Transaction tx = suspend();
|
|
||||||
try {
|
|
||||||
for (AddressAdapter member : currentView) {
|
|
||||||
CacheHelper.initInternalEvict(cacheAdapter, member);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
resume(tx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -94,13 +58,9 @@ public abstract class BaseRegion implements Region {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getElementCountInMemory() {
|
public long getElementCountInMemory() {
|
||||||
if (checkValid()) {
|
if (checkValid())
|
||||||
Set keySet = cacheAdapter.keySet();
|
return cacheAdapter.size();
|
||||||
int size = cacheAdapter.size();
|
|
||||||
if (CacheHelper.containsEvictAllNotification(keySet, address))
|
|
||||||
size--;
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,25 +91,15 @@ public abstract class BaseRegion implements Region {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map toMap() {
|
public Map toMap() {
|
||||||
if (checkValid()) {
|
if (checkValid())
|
||||||
// If copying causes issues, provide a lazily loaded Map
|
return cacheAdapter.toMap();
|
||||||
Map map = new HashMap();
|
|
||||||
Set<Map.Entry> entries = cacheAdapter.toMap().entrySet();
|
|
||||||
for (Map.Entry entry : entries) {
|
|
||||||
Object key = entry.getKey();
|
|
||||||
if (!CacheHelper.isEvictAllNotification(key)) {
|
|
||||||
map.put(key, entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
return Collections.EMPTY_MAP;
|
return Collections.EMPTY_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() throws CacheException {
|
public void destroy() throws CacheException {
|
||||||
try {
|
try {
|
||||||
cacheAdapter.stop();
|
cacheAdapter.stop();
|
||||||
// cacheAdapter.clear();
|
|
||||||
} finally {
|
} finally {
|
||||||
cacheAdapter.removeListener(this);
|
cacheAdapter.removeListener(this);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +123,15 @@ public abstract class BaseRegion implements Region {
|
||||||
if (invalidateState.compareAndSet(InvalidateState.INVALID, InvalidateState.CLEARING)) {
|
if (invalidateState.compareAndSet(InvalidateState.INVALID, InvalidateState.CLEARING)) {
|
||||||
Transaction tx = suspend();
|
Transaction tx = suspend();
|
||||||
try {
|
try {
|
||||||
cacheAdapter.withFlags(FlagAdapter.CACHE_MODE_LOCAL, FlagAdapter.ZERO_LOCK_ACQUISITION_TIMEOUT).clear();
|
// Clear region in a separate transaction
|
||||||
|
cacheAdapter.withinTx(new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
cacheAdapter.withFlags(FlagAdapter.CACHE_MODE_LOCAL,
|
||||||
|
FlagAdapter.ZERO_LOCK_ACQUISITION_TIMEOUT).clear();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
invalidateState.compareAndSet(InvalidateState.CLEARING, InvalidateState.VALID);
|
invalidateState.compareAndSet(InvalidateState.CLEARING, InvalidateState.VALID);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -192,6 +150,8 @@ public abstract class BaseRegion implements Region {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected boolean isValid() {
|
protected boolean isValid() {
|
||||||
return invalidateState.get() == InvalidateState.VALID;
|
return invalidateState.get() == InvalidateState.VALID;
|
||||||
}
|
}
|
||||||
|
@ -261,44 +221,13 @@ public abstract class BaseRegion implements Region {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@CacheEntryModified
|
public void invalidateRegion() {
|
||||||
public void entryModified(CacheEntryModifiedEvent event) {
|
if (log.isTraceEnabled()) log.trace("Invalidate region: " + name);
|
||||||
handleEvictAllModification(event);
|
invalidateState.set(InvalidateState.INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean handleEvictAllModification(CacheEntryModifiedEvent event) {
|
public TransactionManager getTransactionManager() {
|
||||||
if (!event.isPre() && (replication || event.isOriginLocal()) && CacheHelper.isEvictAllNotification(event.getKey(), event.getValue())) {
|
return transactionManager;
|
||||||
if (log.isTraceEnabled()) log.tracef("Set invalid state because marker cache entry was put: {0}", event);
|
|
||||||
invalidateState.set(InvalidateState.INVALID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@CacheEntryInvalidated
|
|
||||||
public void entryInvalidated(CacheEntryInvalidatedEvent event) {
|
|
||||||
if (log.isTraceEnabled()) log.tracef("Cache entry invalidated: {0}", event);
|
|
||||||
handleEvictAllInvalidation(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean handleEvictAllInvalidation(CacheEntryInvalidatedEvent event) {
|
|
||||||
if (!event.isPre() && CacheHelper.isEvictAllNotification(event.getKey())) {
|
|
||||||
if (log.isTraceEnabled()) log.tracef("Set invalid state because marker cache entry was invalidated: {0}", event);
|
|
||||||
invalidateState.set(InvalidateState.INVALID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewChanged
|
|
||||||
public void viewChanged(ViewChangedEvent event) {
|
|
||||||
synchronized (currentView) {
|
|
||||||
List<AddressAdapter> view = AddressAdapterImpl.toAddressAdapter(event.getNewMembers());
|
|
||||||
if (view != null) {
|
|
||||||
currentView.addAll(view);
|
|
||||||
establishInternalNodes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package org.hibernate.cache.infinispan.impl;
|
package org.hibernate.cache.infinispan.impl;
|
||||||
|
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
import org.hibernate.cache.spi.CacheDataDescription;
|
import org.hibernate.cache.spi.CacheDataDescription;
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
|
@ -12,11 +13,14 @@ import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
* @author Galder Zamarreño
|
* @author Galder Zamarreño
|
||||||
* @since 3.5
|
* @since 3.5
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTransactionalDataRegion extends BaseRegion implements TransactionalDataRegion {
|
public abstract class BaseTransactionalDataRegion
|
||||||
|
extends BaseRegion implements TransactionalDataRegion {
|
||||||
|
|
||||||
private final CacheDataDescription metadata;
|
private final CacheDataDescription metadata;
|
||||||
|
|
||||||
public BaseTransactionalDataRegion(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata, TransactionManager transactionManager, RegionFactory factory) {
|
public BaseTransactionalDataRegion(CacheAdapter cacheAdapter, String name,
|
||||||
|
CacheDataDescription metadata, TransactionManager transactionManager,
|
||||||
|
RegionFactory factory) {
|
||||||
super(cacheAdapter, name, transactionManager, factory);
|
super(cacheAdapter, name, transactionManager, factory);
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.hibernate.cache.spi.QueryResultsRegion;
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
|
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
|
||||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
||||||
|
|
||||||
import org.infinispan.notifications.Listener;
|
import org.infinispan.notifications.Listener;
|
||||||
|
@ -38,7 +37,7 @@ public class QueryResultsRegionImpl extends BaseTransactionalDataRegion implemen
|
||||||
public void evictAll() throws CacheException {
|
public void evictAll() throws CacheException {
|
||||||
Transaction tx = suspend();
|
Transaction tx = suspend();
|
||||||
try {
|
try {
|
||||||
CacheHelper.sendEvictAllNotification(cacheAdapter, getAddress());
|
cacheAdapter.broadcastEvictAll();
|
||||||
} finally {
|
} finally {
|
||||||
resume(tx);
|
resume(tx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package org.hibernate.cache.infinispan.timestamp;
|
package org.hibernate.cache.infinispan.timestamp;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -9,12 +10,10 @@ import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.spi.TimestampsRegion;
|
import org.hibernate.cache.spi.TimestampsRegion;
|
||||||
import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
|
import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
|
||||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
import org.hibernate.cache.infinispan.util.FlagAdapter;
|
||||||
import org.infinispan.notifications.Listener;
|
import org.infinispan.notifications.Listener;
|
||||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
|
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
|
||||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
|
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryInvalidatedEvent;
|
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
|
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
|
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
|
||||||
|
|
||||||
|
@ -45,8 +44,8 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
||||||
public void evictAll() throws CacheException {
|
public void evictAll() throws CacheException {
|
||||||
// TODO Is this a valid operation on a timestamps cache?
|
// TODO Is this a valid operation on a timestamps cache?
|
||||||
Transaction tx = suspend();
|
Transaction tx = suspend();
|
||||||
try {
|
try {
|
||||||
CacheHelper.sendEvictAllNotification(cacheAdapter, getAddress());
|
cacheAdapter.broadcastEvictAll();
|
||||||
} finally {
|
} finally {
|
||||||
resume(tx);
|
resume(tx);
|
||||||
}
|
}
|
||||||
|
@ -74,18 +73,13 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(Object key, Object value) throws CacheException {
|
public void put(final Object key, final Object value) throws CacheException {
|
||||||
// Don't hold the JBC node lock throughout the tx, as that
|
|
||||||
// prevents reads and other updates
|
|
||||||
Transaction tx = suspend();
|
|
||||||
try {
|
try {
|
||||||
// We ensure ASYNC semantics (JBCACHE-1175) and make sure previous
|
// We ensure ASYNC semantics (JBCACHE-1175) and make sure previous
|
||||||
// value is not loaded from cache store cos it's not needed.
|
// value is not loaded from cache store cos it's not needed.
|
||||||
cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS).put(key, value);
|
cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS).put(key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
} finally {
|
|
||||||
resume(tx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,9 +97,8 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
||||||
*/
|
*/
|
||||||
@CacheEntryModified
|
@CacheEntryModified
|
||||||
public void nodeModified(CacheEntryModifiedEvent event) {
|
public void nodeModified(CacheEntryModifiedEvent event) {
|
||||||
if (!handleEvictAllModification(event) && !event.isPre()) {
|
if (!event.isPre())
|
||||||
localCache.put(event.getKey(), event.getValue());
|
localCache.put(event.getKey(), event.getValue());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,21 +113,9 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean handleEvictAllModification(CacheEntryModifiedEvent event) {
|
public void invalidateRegion() {
|
||||||
boolean result = super.handleEvictAllModification(event);
|
super.invalidateRegion(); // Invalidate first
|
||||||
if (result) {
|
localCache.clear();
|
||||||
localCache.clear();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean handleEvictAllInvalidation(CacheEntryInvalidatedEvent event) {
|
|
||||||
boolean result = super.handleEvictAllInvalidation(event);
|
|
||||||
if (result) {
|
|
||||||
localCache.clear();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,8 @@ package org.hibernate.cache.infinispan.util;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.infinispan.Cache;
|
import org.infinispan.Cache;
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
|
@ -204,4 +206,21 @@ public interface CacheAdapter {
|
||||||
* @return Configuration instance associated with this cache.
|
* @return Configuration instance associated with this cache.
|
||||||
*/
|
*/
|
||||||
Configuration getConfiguration();
|
Configuration getConfiguration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
void broadcastEvictAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
<T> T withinTx(Callable<T> c) throws Exception;
|
||||||
|
|
||||||
|
Cache getCache();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,14 @@
|
||||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
|
import org.infinispan.AdvancedCache;
|
||||||
import org.infinispan.Cache;
|
import org.infinispan.Cache;
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
import org.infinispan.context.Flag;
|
import org.infinispan.context.Flag;
|
||||||
|
@ -42,13 +46,18 @@ import org.infinispan.util.logging.LogFactory;
|
||||||
public class CacheAdapterImpl implements CacheAdapter {
|
public class CacheAdapterImpl implements CacheAdapter {
|
||||||
private static final Log log = LogFactory.getLog(CacheAdapterImpl.class);
|
private static final Log log = LogFactory.getLog(CacheAdapterImpl.class);
|
||||||
|
|
||||||
private final Cache cache;
|
private final AdvancedCache cache;
|
||||||
|
private final CacheCommandInitializer cacheCmdInitializer;
|
||||||
|
private final boolean isSync;
|
||||||
|
|
||||||
private CacheAdapterImpl(Cache cache) {
|
private CacheAdapterImpl(AdvancedCache cache) {
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
this.cacheCmdInitializer = cache.getComponentRegistry()
|
||||||
|
.getComponent(CacheCommandInitializer.class);
|
||||||
|
this.isSync = isSynchronous(cache.getConfiguration().getCacheMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CacheAdapter newInstance(Cache cache) {
|
public static CacheAdapter newInstance(AdvancedCache cache) {
|
||||||
return new CacheAdapterImpl(cache);
|
return new CacheAdapterImpl(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +70,7 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSynchronous() {
|
public boolean isSynchronous() {
|
||||||
return isSynchronous(cache.getConfiguration().getCacheMode());
|
return isSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set keySet() {
|
public Set keySet() {
|
||||||
|
@ -70,7 +79,7 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
|
|
||||||
public CacheAdapter withFlags(FlagAdapter... flagAdapters) {
|
public CacheAdapter withFlags(FlagAdapter... flagAdapters) {
|
||||||
Flag[] flags = FlagAdapter.toFlags(flagAdapters);
|
Flag[] flags = FlagAdapter.toFlags(flagAdapters);
|
||||||
return newInstance(cache.getAdvancedCache().withFlags(flags));
|
return newInstance(cache.withFlags(flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(Object key) throws CacheException {
|
public Object get(Object key) throws CacheException {
|
||||||
|
@ -173,7 +182,7 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddressAdapter getAddress() {
|
public AddressAdapter getAddress() {
|
||||||
RpcManager rpc = cache.getAdvancedCache().getRpcManager();
|
RpcManager rpc = cache.getRpcManager();
|
||||||
if (rpc != null) {
|
if (rpc != null) {
|
||||||
return AddressAdapterImpl.newInstance(rpc.getTransport().getAddress());
|
return AddressAdapterImpl.newInstance(rpc.getTransport().getAddress());
|
||||||
}
|
}
|
||||||
|
@ -181,17 +190,13 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AddressAdapter> getMembers() {
|
public List<AddressAdapter> getMembers() {
|
||||||
RpcManager rpc = cache.getAdvancedCache().getRpcManager();
|
RpcManager rpc = cache.getRpcManager();
|
||||||
if (rpc != null) {
|
if (rpc != null) {
|
||||||
return AddressAdapterImpl.toAddressAdapter(rpc.getTransport().getMembers());
|
return AddressAdapterImpl.toAddressAdapter(rpc.getTransport().getMembers());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RpcManager getRpcManager() {
|
|
||||||
return cache.getAdvancedCache().getRpcManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return cache.size();
|
return cache.size();
|
||||||
}
|
}
|
||||||
|
@ -212,17 +217,33 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
return cache.getConfiguration();
|
return cache.getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void broadcastEvictAll() {
|
||||||
|
EvictAllCommand cmd = cacheCmdInitializer.buildEvictAllCommand(cache.getName());
|
||||||
|
cache.getRpcManager().broadcastRpcCommand(cmd, isSync);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T withinTx(Callable<T> c) throws Exception {
|
||||||
|
return CacheHelper.withinTx(cache.getTransactionManager(), c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Cache getCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
private Cache getFailSilentCache() {
|
private Cache getFailSilentCache() {
|
||||||
return cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY);
|
return cache.withFlags(Flag.FAIL_SILENTLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache getSkipRemoteGetLoadCache() {
|
private Cache getSkipRemoteGetLoadCache() {
|
||||||
return cache.getAdvancedCache().withFlags(
|
return cache.withFlags(
|
||||||
Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
|
Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache getFailSilentCacheSkipRemotes() {
|
private Cache getFailSilentCacheSkipRemotes() {
|
||||||
return cache.getAdvancedCache().withFlags(
|
return cache.withFlags(
|
||||||
Flag.FAIL_SILENTLY, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
|
Flag.FAIL_SILENTLY, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
|
import org.infinispan.commands.module.ExtendedModuleCommandFactory;
|
||||||
|
import org.infinispan.commands.module.ModuleCommandExtensions;
|
||||||
|
import org.infinispan.commands.module.ModuleCommandInitializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command extensions for second-level cache use case
|
||||||
|
*
|
||||||
|
* @author Galder Zamarreño
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class CacheCommandExtensions implements ModuleCommandExtensions {
|
||||||
|
|
||||||
|
final CacheCommandFactory cacheCommandFactory = new CacheCommandFactory();
|
||||||
|
final CacheCommandInitializer cacheCommandInitializer = new CacheCommandInitializer();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedModuleCommandFactory getModuleCommandFactory() {
|
||||||
|
return cacheCommandFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModuleCommandInitializer getModuleCommandInitializer() {
|
||||||
|
return cacheCommandInitializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java
vendored
Normal file
53
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
|
import org.infinispan.commands.ReplicableCommand;
|
||||||
|
import org.infinispan.commands.module.ExtendedModuleCommandFactory;
|
||||||
|
import org.infinispan.commands.remote.CacheRpcCommand;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command factory
|
||||||
|
*
|
||||||
|
* @author Galder Zamarreño
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class CacheCommandFactory implements ExtendedModuleCommandFactory {
|
||||||
|
|
||||||
|
private InfinispanRegionFactory regionFactory;
|
||||||
|
|
||||||
|
public void setRegionFactory(InfinispanRegionFactory regionFactory) {
|
||||||
|
this.regionFactory = regionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Byte, Class<? extends ReplicableCommand>> getModuleCommands() {
|
||||||
|
Map<Byte, Class<? extends ReplicableCommand>> map = new HashMap<Byte, Class<? extends ReplicableCommand>>(3);
|
||||||
|
map.put(CacheCommandIds.EVICT_ALL, EvictAllCommand.class);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CacheRpcCommand fromStream(byte commandId, Object[] args, String cacheName) {
|
||||||
|
CacheRpcCommand c;
|
||||||
|
switch (commandId) {
|
||||||
|
case CacheCommandIds.EVICT_ALL:
|
||||||
|
c = new EvictAllCommand(cacheName, regionFactory);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Not registered to handle command id " + commandId);
|
||||||
|
}
|
||||||
|
c.setParameters(commandId, args);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReplicableCommand fromStream(byte commandId, Object[] args) {
|
||||||
|
// Should not be called while this factory only
|
||||||
|
// provides cache specific replicable commands.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandIds.java
vendored
Normal file
13
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandIds.java
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command id range assigned to Hibernate second level cache: 120 - 139
|
||||||
|
*
|
||||||
|
* @author Galder Zamarreño
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public interface CacheCommandIds {
|
||||||
|
|
||||||
|
byte EVICT_ALL = 120;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
|
import org.infinispan.commands.ReplicableCommand;
|
||||||
|
import org.infinispan.commands.module.ModuleCommandInitializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command initializer
|
||||||
|
*
|
||||||
|
* @author Galder Zamarreño
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class CacheCommandInitializer implements ModuleCommandInitializer {
|
||||||
|
|
||||||
|
private InfinispanRegionFactory regionFactory;
|
||||||
|
|
||||||
|
public void setRegionFactory(InfinispanRegionFactory regionFactory) {
|
||||||
|
this.regionFactory = regionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EvictAllCommand buildEvictAllCommand(String regionName) {
|
||||||
|
return new EvictAllCommand(regionName, regionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeReplicableCommand(ReplicableCommand c, boolean isRemote) {
|
||||||
|
// No need to initialize...
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,13 +22,10 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
import java.io.Externalizable;
|
import java.util.concurrent.Callable;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInput;
|
import javax.transaction.Status;
|
||||||
import java.io.ObjectOutput;
|
import javax.transaction.TransactionManager;
|
||||||
import java.util.Set;
|
|
||||||
import org.infinispan.util.logging.Log;
|
|
||||||
import org.infinispan.util.logging.LogFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for dealing with Infinisan cache instances.
|
* Helper for dealing with Infinisan cache instances.
|
||||||
|
@ -38,80 +35,23 @@ import org.infinispan.util.logging.LogFactory;
|
||||||
*/
|
*/
|
||||||
public class CacheHelper {
|
public class CacheHelper {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(CacheHelper.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disallow external instantiation of CacheHelper.
|
* Disallow external instantiation of CacheHelper.
|
||||||
*/
|
*/
|
||||||
private CacheHelper() {
|
private CacheHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initInternalEvict(CacheAdapter cache, AddressAdapter member) {
|
public static <T> T withinTx(TransactionManager tm, Callable<T> c) throws Exception {
|
||||||
EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member);
|
tm.begin();
|
||||||
cache.withFlags(FlagAdapter.CACHE_MODE_LOCAL).put(eKey, Internal.INIT);
|
try {
|
||||||
}
|
return c.call();
|
||||||
|
} catch (Exception e) {
|
||||||
public static void sendEvictAllNotification(CacheAdapter cache, AddressAdapter member) {
|
tm.setRollbackOnly();
|
||||||
EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member);
|
throw e;
|
||||||
cache.put(eKey, Internal.EVICT);
|
} finally {
|
||||||
}
|
if (tm.getStatus() == Status.STATUS_ACTIVE) tm.commit();
|
||||||
|
else tm.rollback();
|
||||||
public static boolean isEvictAllNotification(Object key) {
|
|
||||||
return key instanceof EvictAll;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean containsEvictAllNotification(Set keySet, AddressAdapter member) {
|
|
||||||
EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member);
|
|
||||||
return keySet.contains(eKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEvictAllNotification(Object key, Object value) {
|
|
||||||
return key instanceof EvictAll && value == Internal.EVICT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class EvictAll implements Externalizable {
|
|
||||||
AddressAdapter member;
|
|
||||||
|
|
||||||
// Required by Java Externalizable
|
|
||||||
public EvictAll() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EvictAll(AddressAdapter member) {
|
|
||||||
this.member = member;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this)
|
|
||||||
return true;
|
|
||||||
if (!(obj instanceof EvictAll))
|
|
||||||
return false;
|
|
||||||
EvictAll ek = (EvictAll) obj;
|
|
||||||
return ek.member.equals(member);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = 17;
|
|
||||||
result = 31 * result + member.hashCode();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
|
||||||
member = (AddressAdapter) in.readObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeExternal(ObjectOutput out) throws IOException {
|
|
||||||
out.writeObject(member);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum NoAddress implements AddressAdapter {
|
|
||||||
INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum Internal {
|
|
||||||
INIT, EVICT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
50
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/EvictAllCommand.java
vendored
Normal file
50
hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/EvictAllCommand.java
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
|
import org.infinispan.commands.remote.BaseRpcCommand;
|
||||||
|
import org.infinispan.context.InvocationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evict all command
|
||||||
|
*
|
||||||
|
* @author Galder Zamarreño
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class EvictAllCommand extends BaseRpcCommand {
|
||||||
|
|
||||||
|
private InfinispanRegionFactory regionFactory;
|
||||||
|
|
||||||
|
public EvictAllCommand(String regionName, InfinispanRegionFactory regionFactory) {
|
||||||
|
super(regionName); // region name and cache names are the same...
|
||||||
|
this.regionFactory = regionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object perform(InvocationContext ctx) throws Throwable {
|
||||||
|
BaseRegion region = regionFactory.getRegion(cacheName);
|
||||||
|
region.invalidateRegion();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getCommandId() {
|
||||||
|
return CacheCommandIds.EVICT_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getParameters() {
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setParameters(int commandId, Object[] parameters) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReturnValueExpected() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
org.hibernate.cache.infinispan.util.CacheCommandExtensions
|
|
@ -6,11 +6,13 @@
|
||||||
<transport
|
<transport
|
||||||
transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
|
transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
|
||||||
clusterName="infinispan-hibernate-cluster"
|
clusterName="infinispan-hibernate-cluster"
|
||||||
distributedSyncTimeout="50000">
|
distributedSyncTimeout="50000"
|
||||||
|
strictPeerToPeer="false">
|
||||||
<!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
|
<!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
|
||||||
<properties>
|
<properties>
|
||||||
<!-- TODO: Change to udp.xml once streaming transfer requirement has been removed. -->
|
<!--<property name="configurationFile" value="jgroups-tcp.xml"/>-->
|
||||||
<property name="configurationFile" value="flush-udp.xml"/>
|
<property name="configurationFile"
|
||||||
|
value="${hibernate.cache.infinispan.jgroups_cfg:tcp.xml}"/>
|
||||||
</properties>
|
</properties>
|
||||||
<!-- See the JGroupsTransport javadocs for more flags -->
|
<!-- See the JGroupsTransport javadocs for more flags -->
|
||||||
</transport>
|
</transport>
|
||||||
|
@ -19,11 +21,6 @@
|
||||||
<default>
|
<default>
|
||||||
<!-- Used to register JMX statistics in any available MBean server -->
|
<!-- Used to register JMX statistics in any available MBean server -->
|
||||||
<jmxStatistics enabled="false"/>
|
<jmxStatistics enabled="false"/>
|
||||||
<!-- autoCommit would be better configured to be false
|
|
||||||
but that would require redesigning evictAll handling -->
|
|
||||||
<transaction autoCommit="true" use1PcForAutoCommitTransactions="false"
|
|
||||||
transactionManagerLookupClass="org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup"
|
|
||||||
lockingMode="OPTIMISTIC"/>
|
|
||||||
</default>
|
</default>
|
||||||
|
|
||||||
<!-- Default configuration is appropriate for entity/collection caching. -->
|
<!-- Default configuration is appropriate for entity/collection caching. -->
|
||||||
|
@ -36,9 +33,11 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
||||||
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
||||||
<eviction wakeUpInterval="5000" maxEntries="10000" strategy="LRU"/>
|
<eviction maxEntries="10000" strategy="LRU"/>
|
||||||
<expiration maxIdle="100000"/>
|
<expiration maxIdle="100000" wakeUpInterval="5000"/>
|
||||||
<lazyDeserialization enabled="true"/>
|
<lazyDeserialization enabled="true"/>
|
||||||
|
<transaction transactionMode="TRANSACTIONAL" autoCommit="false"
|
||||||
|
lockingMode="OPTIMISTIC"/>
|
||||||
</namedCache>
|
</namedCache>
|
||||||
|
|
||||||
<!-- Default configuration is appropriate for entity/collection caching. -->
|
<!-- Default configuration is appropriate for entity/collection caching. -->
|
||||||
|
@ -57,9 +56,11 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
||||||
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
||||||
<eviction wakeUpInterval="5000" maxEntries="10000" strategy="LRU"/>
|
<eviction maxEntries="10000" strategy="LRU"/>
|
||||||
<expiration maxIdle="100000"/>
|
<expiration maxIdle="100000" wakeUpInterval="5000"/>
|
||||||
<lazyDeserialization enabled="true"/>
|
<lazyDeserialization enabled="true"/>
|
||||||
|
<transaction transactionMode="TRANSACTIONAL" autoCommit="false"
|
||||||
|
lockingMode="OPTIMISTIC"/>
|
||||||
</namedCache>
|
</namedCache>
|
||||||
|
|
||||||
<!-- An alternative configuration for entity/collection caching that uses replication instead of invalidation -->
|
<!-- An alternative configuration for entity/collection caching that uses replication instead of invalidation -->
|
||||||
|
@ -72,9 +73,11 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
<!-- Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds.
|
||||||
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
0 means the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
||||||
<eviction wakeUpInterval="5000" maxEntries="10000" strategy="LRU"/>
|
<eviction maxEntries="10000" strategy="LRU"/>
|
||||||
<expiration maxIdle="100000"/>
|
<expiration maxIdle="100000" wakeUpInterval="5000"/>
|
||||||
<lazyDeserialization enabled="true"/>
|
<lazyDeserialization enabled="true"/>
|
||||||
|
<transaction transactionMode="TRANSACTIONAL" autoCommit="false"
|
||||||
|
lockingMode="OPTIMISTIC"/>
|
||||||
</namedCache>
|
</namedCache>
|
||||||
|
|
||||||
<!-- A config appropriate for query caching. Does not replicate queries. -->
|
<!-- A config appropriate for query caching. Does not replicate queries. -->
|
||||||
|
@ -83,8 +86,10 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<!--Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds. 0 means
|
<!--Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds. 0 means
|
||||||
the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
||||||
<eviction wakeUpInterval="5000" maxEntries="10000" strategy="LRU"/>
|
<eviction maxEntries="10000" strategy="LRU"/>
|
||||||
<expiration maxIdle="100000"/>
|
<expiration maxIdle="100000" wakeUpInterval="5000"/>
|
||||||
|
<transaction transactionMode="TRANSACTIONAL" autoCommit="false"
|
||||||
|
lockingMode="OPTIMISTIC"/>
|
||||||
</namedCache>
|
</namedCache>
|
||||||
|
|
||||||
<!-- A query cache that replicates queries. Replication is asynchronous. -->
|
<!-- A query cache that replicates queries. Replication is asynchronous. -->
|
||||||
|
@ -96,8 +101,10 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<!--Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds. 0 means
|
<!--Eviction configuration. WakeupInterval defines how often the eviction thread runs, in milliseconds. 0 means
|
||||||
the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
the eviction thread will never run. A separate executor is used for eviction in each cache. -->
|
||||||
<eviction wakeUpInterval="5000" maxEntries="10000" strategy="LRU"/>
|
<eviction maxEntries="10000" strategy="LRU"/>
|
||||||
<expiration maxIdle="100000"/>
|
<expiration maxIdle="100000" wakeUpInterval="5000"/>
|
||||||
|
<transaction transactionMode="TRANSACTIONAL" autoCommit="false"
|
||||||
|
lockingMode="OPTIMISTIC"/>
|
||||||
<!-- State transfer forces all replication calls to be synchronous,
|
<!-- State transfer forces all replication calls to be synchronous,
|
||||||
so for calls to remain async, use a cluster cache loader instead -->
|
so for calls to remain async, use a cluster cache loader instead -->
|
||||||
<loaders passivation="false" shared="false" preload="false">
|
<loaders passivation="false" shared="false" preload="false">
|
||||||
|
@ -122,7 +129,10 @@
|
||||||
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
lockAcquisitionTimeout="15000" useLockStriping="false"/>
|
||||||
<lazyDeserialization enabled="true"/>
|
<lazyDeserialization enabled="true"/>
|
||||||
<!-- Don't ever evict modification timestamps -->
|
<!-- Don't ever evict modification timestamps -->
|
||||||
<eviction wakeUpInterval="0" strategy="NONE"/>
|
<eviction strategy="NONE"/>
|
||||||
|
<expiration wakeUpInterval="0"/>
|
||||||
|
<!-- Explicitly non transactional -->
|
||||||
|
<transaction transactionMode="NON_TRANSACTIONAL"/>
|
||||||
<!-- State transfer forces all replication calls to be synchronous,
|
<!-- State transfer forces all replication calls to be synchronous,
|
||||||
so for calls to remain async, use a cluster cache loader instead -->
|
so for calls to remain async, use a cluster cache loader instead -->
|
||||||
<loaders passivation="false" shared="false" preload="false">
|
<loaders passivation="false" shared="false" preload="false">
|
||||||
|
|
|
@ -110,23 +110,31 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
assertNull( "local is clean", localRegion.get( KEY ) );
|
assertNull( "local is clean", localRegion.get( KEY ) );
|
||||||
assertNull( "remote is clean", remoteRegion.get( KEY ) );
|
assertNull( "remote is clean", remoteRegion.get( KEY ) );
|
||||||
|
|
||||||
localRegion.put( KEY, VALUE1 );
|
regionPut(localRegion);
|
||||||
assertEquals( VALUE1, localRegion.get( KEY ) );
|
assertEquals( VALUE1, localRegion.get( KEY ) );
|
||||||
|
|
||||||
// allow async propagation
|
// allow async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
Object expected = invalidation ? null : VALUE1;
|
Object expected = invalidation ? null : VALUE1;
|
||||||
assertEquals( expected, remoteRegion.get( KEY ) );
|
assertEquals( expected, remoteRegion.get( KEY ) );
|
||||||
|
|
||||||
localRegion.evict( KEY );
|
regionEvict(localRegion);
|
||||||
|
|
||||||
// allow async propagation
|
// allow async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
assertEquals( null, localRegion.get( KEY ) );
|
assertEquals( null, localRegion.get( KEY ) );
|
||||||
assertEquals( null, remoteRegion.get( KEY ) );
|
assertEquals( null, remoteRegion.get( KEY ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getStandardRegionName(String regionPrefix);
|
protected void regionEvict(GeneralDataRegion region) throws Exception {
|
||||||
|
region.evict(KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void regionPut(GeneralDataRegion region) throws Exception {
|
||||||
|
region.put(KEY, VALUE1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getStandardRegionName(String regionPrefix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link QueryResultsRegion#evictAll()}.
|
* Test method for {@link QueryResultsRegion#evictAll()}.
|
||||||
|
@ -184,14 +192,14 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
assertNull( "local is clean", localRegion.get( KEY ) );
|
assertNull( "local is clean", localRegion.get( KEY ) );
|
||||||
assertNull( "remote is clean", remoteRegion.get( KEY ) );
|
assertNull( "remote is clean", remoteRegion.get( KEY ) );
|
||||||
|
|
||||||
localRegion.put( KEY, VALUE1 );
|
regionPut(localRegion);
|
||||||
assertEquals( VALUE1, localRegion.get( KEY ) );
|
assertEquals( VALUE1, localRegion.get( KEY ) );
|
||||||
|
|
||||||
// Allow async propagation
|
// Allow async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
|
|
||||||
remoteRegion.put( KEY, VALUE1 );
|
regionPut(remoteRegion);
|
||||||
assertEquals( VALUE1, remoteRegion.get( KEY ) );
|
assertEquals( VALUE1, remoteRegion.get( KEY ) );
|
||||||
|
|
||||||
// Allow async propagation
|
// Allow async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.infinispan.Cache;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -43,76 +42,77 @@ import org.hibernate.test.cache.infinispan.util.CacheTestSupport;
|
||||||
* @since 3.5
|
* @since 3.5
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNonFunctionalTestCase extends org.hibernate.testing.junit4.BaseUnitTestCase {
|
public abstract class AbstractNonFunctionalTestCase extends org.hibernate.testing.junit4.BaseUnitTestCase {
|
||||||
private static final Logger log = Logger.getLogger( AbstractNonFunctionalTestCase.class );
|
private static final Logger log = Logger.getLogger(AbstractNonFunctionalTestCase.class);
|
||||||
|
|
||||||
public static final String REGION_PREFIX = "test";
|
public static final String REGION_PREFIX = "test";
|
||||||
|
|
||||||
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
|
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
|
||||||
private String preferIPv4Stack;
|
private String preferIPv4Stack;
|
||||||
|
private static final String JGROUPS_CFG_FILE = "hibernate.cache.infinispan.jgroups_cfg";
|
||||||
|
private String jgroupsCfgFile;
|
||||||
|
|
||||||
private CacheTestSupport testSupport = new CacheTestSupport();
|
private CacheTestSupport testSupport = new CacheTestSupport();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareCacheSupport() throws Exception {
|
public void prepareCacheSupport() throws Exception {
|
||||||
preferIPv4Stack = System.getProperty( PREFER_IPV4STACK );
|
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
|
||||||
System.setProperty( PREFER_IPV4STACK, "true" );
|
System.setProperty(PREFER_IPV4STACK, "true");
|
||||||
|
jgroupsCfgFile = System.getProperty(JGROUPS_CFG_FILE);
|
||||||
|
System.setProperty(JGROUPS_CFG_FILE, "stacks/tcp.xml");
|
||||||
|
|
||||||
testSupport.setUp();
|
testSupport.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void releaseCachSupport() throws Exception {
|
public void releaseCachSupport() throws Exception {
|
||||||
testSupport.tearDown();
|
testSupport.tearDown();
|
||||||
|
|
||||||
if ( preferIPv4Stack == null ) {
|
if (preferIPv4Stack == null) {
|
||||||
System.clearProperty( PREFER_IPV4STACK );
|
System.clearProperty(PREFER_IPV4STACK);
|
||||||
}
|
} else {
|
||||||
else {
|
System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
|
||||||
System.setProperty( PREFER_IPV4STACK, preferIPv4Stack );
|
}
|
||||||
}
|
|
||||||
}
|
if (jgroupsCfgFile == null)
|
||||||
|
System.clearProperty(JGROUPS_CFG_FILE);
|
||||||
|
else
|
||||||
|
System.setProperty(JGROUPS_CFG_FILE, jgroupsCfgFile);
|
||||||
|
}
|
||||||
|
|
||||||
protected void registerCache(Cache cache) {
|
protected void registerCache(Cache cache) {
|
||||||
testSupport.registerCache(cache);
|
testSupport.registerCache(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unregisterCache(Cache cache) {
|
protected void unregisterCache(Cache cache) {
|
||||||
testSupport.unregisterCache(cache);
|
testSupport.unregisterCache(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerFactory(RegionFactory factory) {
|
protected void registerFactory(RegionFactory factory) {
|
||||||
testSupport.registerFactory(factory);
|
testSupport.registerFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unregisterFactory(RegionFactory factory) {
|
protected void unregisterFactory(RegionFactory factory) {
|
||||||
testSupport.unregisterFactory(factory);
|
testSupport.unregisterFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CacheTestSupport getCacheTestSupport() {
|
protected CacheTestSupport getCacheTestSupport() {
|
||||||
return testSupport;
|
return testSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sleep(long ms) {
|
protected void sleep(long ms) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(ms);
|
Thread.sleep(ms);
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch (InterruptedException e) {
|
log.warn("Interrupted during sleep", e);
|
||||||
log.warn("Interrupted during sleep", e);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected void avoidConcurrentFlush() {
|
protected void avoidConcurrentFlush() {
|
||||||
testSupport.avoidConcurrentFlush();
|
testSupport.avoidConcurrentFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getValidKeyCount(Set keys) {
|
protected int getValidKeyCount(Set keys) {
|
||||||
int result = 0;
|
return keys.size();
|
||||||
for (Object key : keys) {
|
|
||||||
if (!(CacheHelper.isEvictAllNotification(key))) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -31,10 +31,8 @@ import org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl;
|
||||||
import org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup;
|
import org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup;
|
||||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||||
import org.hibernate.cfg.Settings;
|
import org.hibernate.cfg.Settings;
|
||||||
import org.hibernate.cfg.SettingsFactory;
|
|
||||||
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
|
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;
|
||||||
import org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform;
|
import org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform;
|
||||||
import org.hibernate.service.jta.platform.spi.JtaPlatform;
|
|
||||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
import org.infinispan.config.Configuration.CacheMode;
|
import org.infinispan.config.Configuration.CacheMode;
|
||||||
|
@ -43,13 +41,6 @@ import org.infinispan.manager.DefaultCacheManager;
|
||||||
import org.infinispan.manager.EmbeddedCacheManager;
|
import org.infinispan.manager.EmbeddedCacheManager;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.transaction.HeuristicMixedException;
|
|
||||||
import javax.transaction.HeuristicRollbackException;
|
|
||||||
import javax.transaction.InvalidTransactionException;
|
|
||||||
import javax.transaction.NotSupportedException;
|
|
||||||
import javax.transaction.RollbackException;
|
|
||||||
import javax.transaction.SystemException;
|
|
||||||
import javax.transaction.Transaction;
|
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,8 +69,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.query.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.query.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries", "10000");
|
||||||
|
|
||||||
InfinispanRegionFactory factory = new InfinispanRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
|
|
||||||
assertEquals("entity", factory.getTypeOverrides().get("entity").getCacheName());
|
assertEquals("entity", factory.getTypeOverrides().get("entity").getCacheName());
|
||||||
assertEquals("entity", factory.getTypeOverrides().get("collection").getCacheName());
|
assertEquals("entity", factory.getTypeOverrides().get("collection").getCacheName());
|
||||||
|
@ -101,6 +91,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
assertEquals(3000, factory.getTypeOverrides().get("query").getEvictionWakeUpInterval());
|
assertEquals(3000, factory.getTypeOverrides().get("query").getEvictionWakeUpInterval());
|
||||||
assertEquals(10000, factory.getTypeOverrides().get("query").getEvictionMaxEntries());
|
assertEquals(10000, factory.getTypeOverrides().get("query").getEvictionMaxEntries());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides() {
|
public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides() {
|
||||||
final String person = "com.acme.Person";
|
final String person = "com.acme.Person";
|
||||||
|
@ -130,8 +121,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "25000");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "25000");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertFalse(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
assertFalse(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
||||||
|
@ -217,7 +207,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildEntityCollectionRegionOverridesOnly() {
|
public void testBuildEntityCollectionRegionOverridesOnly() {
|
||||||
CacheAdapter cache = null;
|
CacheAdapter cache;
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
||||||
|
@ -225,8 +215,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
|
||||||
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "35000");
|
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "35000");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
factory.getCacheManager();
|
factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, null);
|
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, null);
|
||||||
|
@ -262,8 +251,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertNotNull(factory.getTypeOverrides().get(person));
|
assertNotNull(factory.getTypeOverrides().get(person));
|
||||||
|
@ -286,7 +274,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testTimestampValidation() {
|
public void testTimestampValidation() {
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
final DefaultCacheManager manager = new DefaultCacheManager();
|
final DefaultCacheManager manager = new DefaultCacheManager();
|
||||||
InfinispanRegionFactory factory = createRegionFactory(manager);
|
InfinispanRegionFactory factory = createRegionFactory(manager, p);
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
config.setCacheMode(CacheMode.INVALIDATION_SYNC);
|
config.setCacheMode(CacheMode.INVALIDATION_SYNC);
|
||||||
manager.defineConfiguration("timestamps", config);
|
manager.defineConfiguration("timestamps", config);
|
||||||
|
@ -300,8 +288,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testBuildDefaultTimestampsRegion() {
|
public void testBuildDefaultTimestampsRegion() {
|
||||||
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
|
assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
|
||||||
|
@ -325,8 +312,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
|
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
|
assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
|
||||||
|
@ -351,9 +337,8 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testBuildTimestamRegionWithCacheNameOverride() {
|
public void testBuildTimestamRegionWithCacheNameOverride() {
|
||||||
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
|
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
|
||||||
factory.start(null, p);
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
try {
|
try {
|
||||||
factory.buildTimestampsRegion(timestamps, p);
|
factory.buildTimestampsRegion(timestamps, p);
|
||||||
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
|
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
|
||||||
|
@ -365,31 +350,30 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testBuildTimestamRegionWithFifoEvictionOverride() {
|
public void testBuildTimestamRegionWithFifoEvictionOverride() {
|
||||||
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
|
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
|
||||||
|
InfinispanRegionFactory factory = null;
|
||||||
try {
|
try {
|
||||||
factory.start(null, p);
|
factory = createRegionFactory(p);
|
||||||
factory.buildTimestampsRegion(timestamps, p);
|
factory.buildTimestampsRegion(timestamps, p);
|
||||||
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
|
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
|
||||||
fail("Should fail cos no eviction configurations are allowed for timestamp caches");
|
fail("Should fail cos no eviction configurations are allowed for timestamp caches");
|
||||||
} catch(CacheException ce) {
|
} catch(CacheException ce) {
|
||||||
} finally {
|
} finally {
|
||||||
factory.stop();
|
if (factory != null) factory.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTimestamRegionWithNoneEvictionOverride() {
|
public void testBuildTimestamRegionWithNoneEvictionOverride() {
|
||||||
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "timestamps-none-eviction");
|
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "timestamps-none-eviction");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "NONE");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "NONE");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
|
||||||
factory.start(null, p);
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
manager.getGlobalConfiguration().setTransportClass(null);
|
manager.getGlobalConfiguration().setTransportClass(null);
|
||||||
try {
|
try {
|
||||||
|
@ -403,8 +387,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testBuildQueryRegion() {
|
public void testBuildQueryRegion() {
|
||||||
final String query = "org.hibernate.cache.internal.StandardQueryCache";
|
final String query = "org.hibernate.cache.internal.StandardQueryCache";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
manager.getGlobalConfiguration().setTransportClass(null);
|
manager.getGlobalConfiguration().setTransportClass(null);
|
||||||
try {
|
try {
|
||||||
|
@ -422,12 +405,11 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
public void testBuildQueryRegionWithCustomRegionName() {
|
public void testBuildQueryRegionWithCustomRegionName() {
|
||||||
final String queryRegionName = "myquery";
|
final String queryRegionName = "myquery";
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
|
||||||
p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
|
p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
|
||||||
p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
|
p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
|
||||||
p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
|
p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
|
||||||
factory.start(null, p);
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
manager.getGlobalConfiguration().setTransportClass(null);
|
manager.getGlobalConfiguration().setTransportClass(null);
|
||||||
try {
|
try {
|
||||||
|
@ -454,8 +436,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertTrue(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
assertTrue(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
||||||
|
@ -502,8 +483,7 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
|
||||||
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
|
||||||
InfinispanRegionFactory factory = createRegionFactory();
|
InfinispanRegionFactory factory = createRegionFactory(p);
|
||||||
factory.start(null, p);
|
|
||||||
EmbeddedCacheManager manager = factory.getCacheManager();
|
EmbeddedCacheManager manager = factory.getCacheManager();
|
||||||
try {
|
try {
|
||||||
assertFalse(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
assertFalse(manager.getGlobalConfiguration().isExposeGlobalJmxStatistics());
|
||||||
|
@ -541,12 +521,12 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InfinispanRegionFactory createRegionFactory() {
|
private InfinispanRegionFactory createRegionFactory(Properties p) {
|
||||||
return createRegionFactory(null);
|
return createRegionFactory(null, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InfinispanRegionFactory createRegionFactory(final EmbeddedCacheManager manager) {
|
private InfinispanRegionFactory createRegionFactory(final EmbeddedCacheManager manager, Properties p) {
|
||||||
return new InfinispanRegionFactory() {
|
final InfinispanRegionFactory factory = new InfinispanRegionFactory() {
|
||||||
@Override
|
@Override
|
||||||
protected HibernateTransactionManagerLookup createTransactionManagerLookup(Settings settings, Properties properties) {
|
protected HibernateTransactionManagerLookup createTransactionManagerLookup(Settings settings, Properties properties) {
|
||||||
return new HibernateTransactionManagerLookup(null, null) {
|
return new HibernateTransactionManagerLookup(null, null) {
|
||||||
|
@ -567,6 +547,8 @@ public class InfinispanRegionFactoryTestCase {
|
||||||
return super.createCacheManager(properties);
|
return super.createCacheManager(properties);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
factory.start(null, p);
|
||||||
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.test.cache.infinispan;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.hibernate.cache.spi.CacheDataDescription;
|
import org.hibernate.cache.spi.CacheDataDescription;
|
||||||
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
|
@ -37,6 +38,8 @@ import org.hibernate.service.internal.StandardServiceRegistryImpl;
|
||||||
|
|
||||||
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
||||||
|
|
||||||
|
import static org.hibernate.cache.infinispan.util.CacheHelper.withinTx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the environment for a node.
|
* Defines the environment for a node.
|
||||||
*
|
*
|
||||||
|
@ -117,15 +120,27 @@ public class NodeEnvironment {
|
||||||
|
|
||||||
public void release() throws Exception {
|
public void release() throws Exception {
|
||||||
if ( entityRegionMap != null ) {
|
if ( entityRegionMap != null ) {
|
||||||
for ( EntityRegionImpl region : entityRegionMap.values() ) {
|
for ( final EntityRegionImpl region : entityRegionMap.values() ) {
|
||||||
region.getCacheAdapter().withFlags( FlagAdapter.CACHE_MODE_LOCAL ).clear();
|
withinTx(region.getTransactionManager(), new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
region.getCacheAdapter().withFlags(FlagAdapter.CACHE_MODE_LOCAL).clear();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
region.getCacheAdapter().stop();
|
region.getCacheAdapter().stop();
|
||||||
}
|
}
|
||||||
entityRegionMap.clear();
|
entityRegionMap.clear();
|
||||||
}
|
}
|
||||||
if ( collectionRegionMap != null ) {
|
if ( collectionRegionMap != null ) {
|
||||||
for ( CollectionRegionImpl collectionRegion : collectionRegionMap.values() ) {
|
for ( final CollectionRegionImpl collectionRegion : collectionRegionMap.values() ) {
|
||||||
collectionRegion.getCacheAdapter().withFlags( FlagAdapter.CACHE_MODE_LOCAL ).clear();
|
withinTx(collectionRegion.getTransactionManager(), new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
collectionRegion.getCacheAdapter().withFlags( FlagAdapter.CACHE_MODE_LOCAL ).clear();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
collectionRegion.getCacheAdapter().stop();
|
collectionRegion.getCacheAdapter().stop();
|
||||||
}
|
}
|
||||||
collectionRegionMap.clear();
|
collectionRegionMap.clear();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.util.CacheHelper;
|
||||||
import org.infinispan.transaction.tm.BatchModeTransactionManager;
|
import org.infinispan.transaction.tm.BatchModeTransactionManager;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
@ -52,7 +53,6 @@ import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
|
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
|
||||||
import org.hibernate.test.cache.infinispan.NodeEnvironment;
|
import org.hibernate.test.cache.infinispan.NodeEnvironment;
|
||||||
import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeJtaTransactionManagerImpl;
|
|
||||||
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -162,8 +162,8 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
public void testPutFromLoadRemoveDoesNotProduceStaleData() throws Exception {
|
public void testPutFromLoadRemoveDoesNotProduceStaleData() throws Exception {
|
||||||
final CountDownLatch pferLatch = new CountDownLatch( 1 );
|
final CountDownLatch pferLatch = new CountDownLatch( 1 );
|
||||||
final CountDownLatch removeLatch = new CountDownLatch( 1 );
|
final CountDownLatch removeLatch = new CountDownLatch( 1 );
|
||||||
TransactionManager tm = DualNodeJtaTransactionManagerImpl.getInstance( "test1234" );
|
final TransactionManager remoteTm = remoteCollectionRegion.getTransactionManager();
|
||||||
PutFromLoadValidator validator = new PutFromLoadValidator( tm ) {
|
PutFromLoadValidator validator = new PutFromLoadValidator(remoteTm) {
|
||||||
@Override
|
@Override
|
||||||
public boolean acquirePutFromLoadLock(Object key) {
|
public boolean acquirePutFromLoadLock(Object key) {
|
||||||
boolean acquired = super.acquirePutFromLoadLock( key );
|
boolean acquired = super.acquirePutFromLoadLock( key );
|
||||||
|
@ -182,9 +182,10 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
return acquired;
|
return acquired;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final TransactionalAccessDelegate delegate = new TransactionalAccessDelegate(
|
|
||||||
(CollectionRegionImpl) localCollectionRegion, validator
|
final TransactionalAccessDelegate delegate =
|
||||||
);
|
new TransactionalAccessDelegate(localCollectionRegion, validator);
|
||||||
|
final TransactionManager localTm = localCollectionRegion.getTransactionManager();
|
||||||
|
|
||||||
Callable<Void> pferCallable = new Callable<Void>() {
|
Callable<Void> pferCallable = new Callable<Void>() {
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
|
@ -196,7 +197,13 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
Callable<Void> removeCallable = new Callable<Void>() {
|
Callable<Void> removeCallable = new Callable<Void>() {
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
removeLatch.await();
|
removeLatch.await();
|
||||||
delegate.remove( "k1" );
|
CacheHelper.withinTx(localTm, new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
delegate.remove("k1");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
pferLatch.countDown();
|
pferLatch.countDown();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -355,26 +362,26 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemove() {
|
public void testRemove() throws Exception {
|
||||||
evictOrRemoveTest( false );
|
evictOrRemoveTest( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveAll() {
|
public void testRemoveAll() throws Exception {
|
||||||
evictOrRemoveAllTest( false );
|
evictOrRemoveAllTest( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvict() {
|
public void testEvict() throws Exception {
|
||||||
evictOrRemoveTest( true );
|
evictOrRemoveTest( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvictAll() {
|
public void testEvictAll() throws Exception {
|
||||||
evictOrRemoveAllTest( true );
|
evictOrRemoveAllTest( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evictOrRemoveTest(boolean evict) {
|
private void evictOrRemoveTest(final boolean evict) throws Exception {
|
||||||
|
|
||||||
final String KEY = KEY_BASE + testCount++;
|
final String KEY = KEY_BASE + testCount++;
|
||||||
|
|
||||||
|
@ -389,19 +396,23 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
// Wait for async propagation
|
// Wait for async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
|
|
||||||
if ( evict ) {
|
CacheHelper.withinTx(localCollectionRegion.getTransactionManager(), new Callable<Void>() {
|
||||||
localAccessStrategy.evict( KEY );
|
@Override
|
||||||
}
|
public Void call() throws Exception {
|
||||||
else {
|
if (evict)
|
||||||
localAccessStrategy.remove( KEY );
|
localAccessStrategy.evict(KEY);
|
||||||
}
|
else
|
||||||
|
localAccessStrategy.remove(KEY);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
assertEquals( null, localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertEquals( null, localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
||||||
|
|
||||||
assertEquals( null, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertEquals( null, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evictOrRemoveAllTest(boolean evict) {
|
private void evictOrRemoveAllTest(final boolean evict) throws Exception {
|
||||||
|
|
||||||
final String KEY = KEY_BASE + testCount++;
|
final String KEY = KEY_BASE + testCount++;
|
||||||
|
|
||||||
|
@ -420,12 +431,16 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
|
||||||
// Wait for async propagation
|
// Wait for async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
|
|
||||||
if ( evict ) {
|
CacheHelper.withinTx(localCollectionRegion.getTransactionManager(), new Callable<Void>() {
|
||||||
localAccessStrategy.evictAll();
|
@Override
|
||||||
}
|
public Void call() throws Exception {
|
||||||
else {
|
if (evict)
|
||||||
localAccessStrategy.removeAll();
|
localAccessStrategy.evictAll();
|
||||||
}
|
else
|
||||||
|
localAccessStrategy.removeAll();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// This should re-establish the region root node
|
// This should re-establish the region root node
|
||||||
assertNull( localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertNull( localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
||||||
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache(InfinispanRegionFactory.DEF_ENTITY_RESOURCE));
|
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache(InfinispanRegionFactory.DEF_ENTITY_RESOURCE).getAdvancedCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,9 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.cache.infinispan.entity;
|
package org.hibernate.test.cache.infinispan.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.util.CacheHelper;
|
||||||
|
import org.infinispan.Cache;
|
||||||
|
import org.infinispan.test.TestingUtil;
|
||||||
import org.infinispan.transaction.tm.BatchModeTransactionManager;
|
import org.infinispan.transaction.tm.BatchModeTransactionManager;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
@ -105,8 +112,15 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
|
||||||
|
|
||||||
remoteEntityRegion = remoteEnvironment.getEntityRegion( REGION_NAME, getCacheDataDescription() );
|
remoteEntityRegion = remoteEnvironment.getEntityRegion( REGION_NAME, getCacheDataDescription() );
|
||||||
remoteAccessStrategy = remoteEntityRegion.buildAccessStrategy( getAccessType() );
|
remoteAccessStrategy = remoteEntityRegion.buildAccessStrategy( getAccessType() );
|
||||||
|
|
||||||
|
waitForClusterToForm(localEntityRegion.getCacheAdapter().getCache(),
|
||||||
|
remoteEntityRegion.getCacheAdapter().getCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void waitForClusterToForm(Cache... caches) {
|
||||||
|
TestingUtil.blockUntilViewsReceived(10000, Arrays.asList(caches));
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract String getConfigurationName();
|
protected abstract String getConfigurationName();
|
||||||
|
|
||||||
protected static Configuration createConfiguration(String configName) {
|
protected static Configuration createConfiguration(String configName) {
|
||||||
|
@ -503,26 +517,26 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemove() {
|
public void testRemove() throws Exception {
|
||||||
evictOrRemoveTest( false );
|
evictOrRemoveTest( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveAll() {
|
public void testRemoveAll() throws Exception {
|
||||||
evictOrRemoveAllTest( false );
|
evictOrRemoveAllTest( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvict() {
|
public void testEvict() throws Exception {
|
||||||
evictOrRemoveTest( true );
|
evictOrRemoveTest( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvictAll() {
|
public void testEvictAll() throws Exception {
|
||||||
evictOrRemoveAllTest( true );
|
evictOrRemoveAllTest( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evictOrRemoveTest(boolean evict) {
|
private void evictOrRemoveTest(final boolean evict) throws Exception {
|
||||||
final String KEY = KEY_BASE + testCount++;
|
final String KEY = KEY_BASE + testCount++;
|
||||||
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
|
@ -535,20 +549,23 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
|
||||||
remoteAccessStrategy.putFromLoad( KEY, VALUE1, System.currentTimeMillis(), new Integer( 1 ) );
|
remoteAccessStrategy.putFromLoad( KEY, VALUE1, System.currentTimeMillis(), new Integer( 1 ) );
|
||||||
assertEquals( VALUE1, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertEquals( VALUE1, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
||||||
|
|
||||||
if ( evict ) {
|
CacheHelper.withinTx(localEntityRegion.getTransactionManager(), new Callable<Void>() {
|
||||||
localAccessStrategy.evict( KEY );
|
@Override
|
||||||
}
|
public Void call() throws Exception {
|
||||||
else {
|
if ( evict )
|
||||||
localAccessStrategy.remove( KEY );
|
localAccessStrategy.evict( KEY );
|
||||||
}
|
else
|
||||||
|
localAccessStrategy.remove( KEY );
|
||||||
assertEquals( null, localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertEquals(null, localAccessStrategy.get(KEY, System.currentTimeMillis()));
|
||||||
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
assertEquals( null, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertEquals( null, remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
||||||
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evictOrRemoveAllTest(boolean evict) {
|
private void evictOrRemoveAllTest(final boolean evict) throws Exception {
|
||||||
final String KEY = KEY_BASE + testCount++;
|
final String KEY = KEY_BASE + testCount++;
|
||||||
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( remoteEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
|
@ -567,16 +584,21 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
|
||||||
// Wait for async propagation
|
// Wait for async propagation
|
||||||
sleep( 250 );
|
sleep( 250 );
|
||||||
|
|
||||||
if ( evict ) {
|
CacheHelper.withinTx(localEntityRegion.getTransactionManager(), new Callable<Void>() {
|
||||||
log.debug("Call evict all locally");
|
@Override
|
||||||
localAccessStrategy.evictAll();
|
public Void call() throws Exception {
|
||||||
}
|
if (evict) {
|
||||||
else {
|
log.debug("Call evict all locally");
|
||||||
localAccessStrategy.removeAll();
|
localAccessStrategy.evictAll();
|
||||||
}
|
} else {
|
||||||
|
localAccessStrategy.removeAll();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// This should re-establish the region root node in the optimistic case
|
// This should re-establish the region root node in the optimistic case
|
||||||
assertNull( localAccessStrategy.get( KEY, System.currentTimeMillis() ) );
|
assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));
|
||||||
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
assertEquals( 0, getValidKeyCount( localEntityRegion.getCacheAdapter().keySet() ) );
|
||||||
|
|
||||||
// Re-establishing the region root on the local node doesn't
|
// Re-establishing the region root on the local node doesn't
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
||||||
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache(InfinispanRegionFactory.DEF_ENTITY_RESOURCE));
|
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache(InfinispanRegionFactory.DEF_ENTITY_RESOURCE).getAdvancedCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,132 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.test.cache.infinispan.functional;
|
|
||||||
|
|
||||||
import javax.transaction.TransactionManager;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.infinispan.util.logging.Log;
|
|
||||||
import org.infinispan.util.logging.LogFactory;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
|
|
||||||
import org.hibernate.engine.transaction.spi.TransactionFactory;
|
|
||||||
import org.hibernate.stat.SecondLevelCacheStatistics;
|
|
||||||
import org.hibernate.stat.Statistics;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BasicJdbcTransactionalTestCase.
|
|
||||||
*
|
|
||||||
* @author Galder Zamarreño
|
|
||||||
* @since 3.5
|
|
||||||
*/
|
|
||||||
public class BasicJdbcTransactionalTestCase extends SingleNodeTestCase {
|
|
||||||
private static final Log log = LogFactory.getLog( BasicJdbcTransactionalTestCase.class );
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends TransactionFactory> getTransactionFactoryClass() {
|
|
||||||
return JdbcTransactionFactory.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TransactionManager getTransactionManager() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCollectionCache() throws Exception {
|
|
||||||
Item item = new Item( "chris", "Chris's Item" );
|
|
||||||
Item another = new Item( "another", "Owned Item" );
|
|
||||||
item.addItem( another );
|
|
||||||
|
|
||||||
Session s = null;
|
|
||||||
try {
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
s.persist( item );
|
|
||||||
s.persist( another );
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.error( "Exception", e );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Item loaded = (Item) s.load( Item.class, item.getId() );
|
|
||||||
assertEquals( 1, loaded.getItems().size() );
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.error( "Exception", e );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
s = openSession();
|
|
||||||
s.beginTransaction();
|
|
||||||
Statistics stats = s.getSessionFactory().getStatistics();
|
|
||||||
SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );
|
|
||||||
Item loadedWithCachedCollection = (Item) s.load( Item.class, item.getId() );
|
|
||||||
stats.logSummary();
|
|
||||||
assertEquals( item.getName(), loadedWithCachedCollection.getName() );
|
|
||||||
assertEquals( item.getItems().size(), loadedWithCachedCollection.getItems().size() );
|
|
||||||
assertEquals( 1, cStats.getHitCount() );
|
|
||||||
Map cacheEntries = cStats.getEntries();
|
|
||||||
assertEquals( 1, cacheEntries.size() );
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.error( "Exception", e );
|
|
||||||
s.getTransaction().rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEmptySecondLevelCacheEntry() throws Exception {
|
|
||||||
sessionFactory().getCache().evictCollectionRegion( Item.class.getName() + ".items" );
|
|
||||||
Statistics stats = sessionFactory().getStatistics();
|
|
||||||
stats.clear();
|
|
||||||
SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() + ".items" );
|
|
||||||
Map cacheEntries = statistics.getEntries();
|
|
||||||
assertEquals( 0, cacheEntries.size() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -35,8 +35,6 @@ import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
|
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public class CacheAccessListener {
|
public class CacheAccessListener {
|
||||||
private static final Logger log = Logger.getLogger( CacheAccessListener.class );
|
private static final Logger log = Logger.getLogger( CacheAccessListener.class );
|
||||||
|
@ -51,7 +49,7 @@ public class CacheAccessListener {
|
||||||
|
|
||||||
@CacheEntryModified
|
@CacheEntryModified
|
||||||
public void nodeModified( CacheEntryModifiedEvent event ) {
|
public void nodeModified( CacheEntryModifiedEvent event ) {
|
||||||
if (!event.isPre() && !CacheHelper.isEvictAllNotification(event.getKey())) {
|
if (!event.isPre()) {
|
||||||
Object key = event.getKey();
|
Object key = event.getKey();
|
||||||
log.info("Modified node " + key);
|
log.info("Modified node " + key);
|
||||||
modified.add(key.toString());
|
modified.add(key.toString());
|
||||||
|
@ -60,7 +58,7 @@ public class CacheAccessListener {
|
||||||
|
|
||||||
@CacheEntryCreated
|
@CacheEntryCreated
|
||||||
public void nodeCreated( CacheEntryCreatedEvent event ) {
|
public void nodeCreated( CacheEntryCreatedEvent event ) {
|
||||||
if (!event.isPre() && !CacheHelper.isEvictAllNotification(event.getKey())) {
|
if (!event.isPre()) {
|
||||||
Object key = event.getKey();
|
Object key = event.getKey();
|
||||||
log.info("Created node " + key);
|
log.info("Created node " + key);
|
||||||
modified.add(key.toString());
|
modified.add(key.toString());
|
||||||
|
@ -69,7 +67,7 @@ public class CacheAccessListener {
|
||||||
|
|
||||||
@CacheEntryVisited
|
@CacheEntryVisited
|
||||||
public void nodeVisited( CacheEntryVisitedEvent event ) {
|
public void nodeVisited( CacheEntryVisitedEvent event ) {
|
||||||
if (!event.isPre() && !CacheHelper.isEvictAllNotification(event.getKey())) {
|
if (!event.isPre()) {
|
||||||
Object key = event.getKey();
|
Object key = event.getKey();
|
||||||
log.info("Visited node " + key);
|
log.info("Visited node " + key);
|
||||||
accessed.add(key.toString());
|
accessed.add(key.toString());
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.jboss.util.collection.ConcurrentSet;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cache.spi.CacheKey;
|
import org.hibernate.cache.spi.CacheKey;
|
||||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -340,13 +339,7 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getValidKeyCount(Set keys) {
|
protected int getValidKeyCount(Set keys) {
|
||||||
int result = 0;
|
return keys.size();
|
||||||
for ( Object key : keys ) {
|
|
||||||
if ( !(CacheHelper.isEvictAllNotification( key )) ) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
|
|
|
@ -24,9 +24,12 @@
|
||||||
package org.hibernate.test.cache.infinispan.query;
|
package org.hibernate.test.cache.infinispan.query;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.hibernate.cache.infinispan.util.CacheHelper;
|
||||||
|
import org.hibernate.cache.spi.GeneralDataRegion;
|
||||||
import org.infinispan.notifications.Listener;
|
import org.infinispan.notifications.Listener;
|
||||||
import org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited;
|
import org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited;
|
||||||
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
|
import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
|
||||||
|
@ -76,9 +79,31 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
||||||
return regionPrefix + "/" + StandardQueryCache.class.getName();
|
return regionPrefix + "/" + StandardQueryCache.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected void regionPut(final GeneralDataRegion region) throws Exception {
|
||||||
|
CacheHelper.withinTx(BatchModeTransactionManager.getInstance(), new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
region.put(KEY, VALUE1);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void regionEvict(final GeneralDataRegion region) throws Exception {
|
||||||
|
CacheHelper.withinTx(BatchModeTransactionManager.getInstance(), new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
region.evict(KEY);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
||||||
return CacheAdapterImpl.newInstance( regionFactory.getCacheManager().getCache( "local-query" ) );
|
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache( "local-query" ).getAdvancedCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
protected CacheAdapter getInfinispanCache(InfinispanRegionFactory regionFactory) {
|
||||||
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache("timestamps"));
|
return CacheAdapterImpl.newInstance(regionFactory.getCacheManager().getCache("timestamps").getAdvancedCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClearTimestampsRegionInIsolated() throws Exception {
|
public void testClearTimestampsRegionInIsolated() throws Exception {
|
||||||
|
@ -141,7 +141,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ClassLoaderAwareCache createCacheWrapper(AdvancedCache cache) {
|
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
||||||
return new ClassLoaderAwareCache(cache, Thread.currentThread().getContextClassLoader()) {
|
return new ClassLoaderAwareCache(cache, Thread.currentThread().getContextClassLoader()) {
|
||||||
@Override
|
@Override
|
||||||
public void addListener(Object listener) {
|
public void addListener(Object listener) {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
@ -35,6 +36,7 @@ import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.Settings;
|
import org.hibernate.cfg.Settings;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for cache testing.
|
* Utilities for cache testing.
|
||||||
|
@ -80,9 +82,7 @@ public class CacheTestUtil {
|
||||||
String factoryType = cfg.getProperty(Environment.CACHE_REGION_FACTORY);
|
String factoryType = cfg.getProperty(Environment.CACHE_REGION_FACTORY);
|
||||||
Class factoryClass = Thread.currentThread().getContextClassLoader().loadClass(factoryType);
|
Class factoryClass = Thread.currentThread().getContextClassLoader().loadClass(factoryType);
|
||||||
InfinispanRegionFactory regionFactory = (InfinispanRegionFactory) factoryClass.newInstance();
|
InfinispanRegionFactory regionFactory = (InfinispanRegionFactory) factoryClass.newInstance();
|
||||||
|
|
||||||
regionFactory.start(settings, properties);
|
regionFactory.start(settings, properties);
|
||||||
|
|
||||||
return regionFactory;
|
return regionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue