Skip to content

Commit

Permalink
HHH-9796 : Add test configuration for Infinispan 7.2; update tests to…
Browse files Browse the repository at this point in the history
… use configuration specifed by hibernate.cache.infinispan.cfg
  • Loading branch information
gbadner committed May 13, 2015
1 parent c5579a4 commit 46a2a7a
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 22 deletions.
Expand Up @@ -110,6 +110,7 @@ private void evictOrRemoveTest() throws Exception {
assertNull( "remote is clean", remoteRegion.get( KEY ) );

regionPut(localRegion);
sleep( 1000 );
assertEquals( VALUE1, localRegion.get( KEY ) );

// allow async propagation
Expand Down
Expand Up @@ -24,11 +24,14 @@
import java.util.Properties;
import javax.transaction.TransactionManager;

import org.hibernate.cfg.Environment;
import org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase;

import org.infinispan.AdvancedCache;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
Expand Down Expand Up @@ -65,7 +68,7 @@ public class InfinispanRegionFactoryTestCase {
public void testConfigurationProcessing() {
final String person = "com.acme.Person";
final String addresses = "com.acme.Person.addresses";
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg", "person-cache");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.wake_up_interval", "2000");
Expand Down Expand Up @@ -114,7 +117,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
final String car = "com.acme.Car";
final String addresses = "com.acme.Person.addresses";
final String parts = "com.acme.Car.parts";
Properties p = new Properties();
Properties p = createProperties();
// First option, cache defined for entity and overrides for generic entity data type and entity itself.
p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg", "person-cache");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
Expand Down Expand Up @@ -225,7 +228,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
@Test
public void testBuildEntityCollectionRegionOverridesOnly() {
AdvancedCache cache;
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "LIRS");
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "30000");
Expand Down Expand Up @@ -261,7 +264,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
@Test
public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
final String person = "com.acme.Person";
Properties p = new Properties();
Properties p = createProperties();
// Third option, no cache defined for entity and overrides for generic entity data type and entity itself.
p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
Expand Down Expand Up @@ -292,8 +295,8 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {

@Test
public void testTimestampValidation() {
Properties p = new Properties();
final DefaultCacheManager manager = new DefaultCacheManager();
Properties p = createProperties();
final DefaultCacheManager manager = new DefaultCacheManager( GlobalConfigurationBuilder.defaultClusteredBuilder().build());
InfinispanRegionFactory factory = createRegionFactory(manager, p);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
Expand All @@ -308,7 +311,7 @@ public void testTimestampValidation() {
@Test
public void testBuildDefaultTimestampsRegion() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = new Properties();
Properties p = createProperties();
InfinispanRegionFactory factory = createRegionFactory(p);
try {
assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
Expand All @@ -329,7 +332,7 @@ public void testBuildDefaultTimestampsRegion() {
@Test
public void testBuildDiffCacheNameTimestampsRegion() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
InfinispanRegionFactory factory = createRegionFactory(p);
try {
Expand All @@ -356,7 +359,7 @@ public void testBuildDiffCacheNameTimestampsRegion() {
@Test
public void testBuildTimestamRegionWithCacheNameOverride() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
InfinispanRegionFactory factory = createRegionFactory(p);
try {
Expand All @@ -370,7 +373,7 @@ public void testBuildTimestamRegionWithCacheNameOverride() {
@Test
public void testBuildTimestamRegionWithFifoEvictionOverride() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = new Properties();
Properties p = createProperties();
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.wake_up_interval", "3000");
Expand All @@ -390,7 +393,7 @@ public void testBuildTimestamRegionWithFifoEvictionOverride() {
@Test
public void testBuildTimestamRegionWithNoneEvictionOverride() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = new Properties();
Properties p = createProperties();
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.wake_up_interval", "3000");
Expand All @@ -407,7 +410,7 @@ public void testBuildTimestamRegionWithNoneEvictionOverride() {
@Test
public void testBuildQueryRegion() {
final String query = "org.hibernate.cache.internal.StandardQueryCache";
Properties p = new Properties();
Properties p = createProperties();
InfinispanRegionFactory factory = createRegionFactory(p);
try {
assertTrue(factory.getDefinedConfigurations().contains("local-query"));
Expand All @@ -424,7 +427,7 @@ public void testBuildQueryRegion() {
@Test
public void testBuildQueryRegionWithCustomRegionName() {
final String queryRegionName = "myquery";
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "LIRS");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
Expand All @@ -446,7 +449,7 @@ public void testBuildQueryRegionWithCustomRegionName() {
}
@Test
public void testEnableStatistics() {
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
Expand Down Expand Up @@ -497,7 +500,7 @@ public void testEnableStatistics() {

@Test
public void testDisableStatistics() {
Properties p = new Properties();
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.statistics", "false");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
Expand Down Expand Up @@ -576,4 +579,14 @@ protected EmbeddedCacheManager createCacheManager(Properties properties) throws
return factory;
}

private static Properties createProperties() {
final Properties properties = new Properties();
// If configured in the environment, add configuration file name to properties.
final String cfgFileName =
(String) Environment.getProperties().get( InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP );
if ( cfgFileName != null ) {
properties.put( InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP, cfgFileName );
}
return properties;
}
}
Expand Up @@ -98,7 +98,13 @@ public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
props.put( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
props.put( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );

manager = new DefaultCacheManager( InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE, false );
final String cfgFileName = (String) mappings.getConfigurationProperties().get(
InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP
);
manager = new DefaultCacheManager(
cfgFileName == null ? InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE : cfgFileName,
false
);
Context ctx = new InitialContext( props );
bind( JNDI_NAME, manager, EmbeddedCacheManager.class, ctx );
}
Expand Down
Expand Up @@ -82,9 +82,11 @@ public void commit() throws RollbackException, HeuristicMixedException, Heuristi
} else {
status = Status.STATUS_PREPARING;

for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.beforeCompletion();
if ( synchronizations != null ) {
for ( int i = 0; i < synchronizations.size(); i++ ) {
Synchronization s = (Synchronization) synchronizations.get( i );
s.beforeCompletion();
}
}

if (!runXaResourcePrepare()) {
Expand All @@ -109,9 +111,11 @@ public void commit() throws RollbackException, HeuristicMixedException, Heuristi

status = Status.STATUS_COMMITTED;

for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
if ( synchronizations != null ) {
for ( int i = 0; i < synchronizations.size(); i++ ) {
Synchronization s = (Synchronization) synchronizations.get( i );
s.afterCompletion( status );
}
}

// status = Status.STATUS_NO_TRANSACTION;
Expand Down
80 changes: 80 additions & 0 deletions hibernate-infinispan/src/test/resources/infinispan-7-configs.xml
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:infinispan:config:7.2"
xsi:schemaLocation="urn:infinispan:config:7.2 http://www.infinispan.org/schemas/infinispan-config-7.2.xsd">

<jgroups>
<stack-file name="hibernate-jgroups" path="${hibernate.cache.infinispan.jgroups_cfg:default-configs/default-jgroups-tcp.xml}"/>
</jgroups>

<cache-container name="SampleCacheManager" statistics="false" default-cache="the-default-cache" shutdown-hook="DEFAULT">
<transport stack="hibernate-jgroups" cluster="infinispan-hibernate-cluster"/>

<local-cache name="the-default-cache" statistics="false" />

<!-- Default configuration is appropriate for entity/collection caching. -->
<invalidation-cache name="entity" mode="SYNC" remote-timeout="20000">
<locking isolation="READ_COMMITTED" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<transaction mode="NON_XA" locking="OPTIMISTIC" auto-commit="false"/>
<eviction max-entries="10000" strategy="LRU"/>
<expiration max-idle="100000" interval="5000"/>
</invalidation-cache>

<!-- Default configuration is appropriate for entity/collection caching. -->
<invalidation-cache name="entity-repeatable" mode="SYNC" remote-timeout="20000">
<locking isolation="REPEATABLE_READ" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<transaction mode="NON_XA" locking="OPTIMISTIC" auto-commit="false"/>
<eviction max-entries="10000" strategy="LRU"/>
<expiration max-idle="100000" interval="5000"/>
</invalidation-cache>

<!-- An alternative configuration for entity/collection caching that uses replication instead of invalidation -->
<replicated-cache name="replicated-entity" mode="SYNC" remote-timeout="20000">
<locking isolation="READ_COMMITTED" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<transaction mode="NON_XA" locking="OPTIMISTIC" auto-commit="false"/>
<eviction max-entries="10000" strategy="LRU"/>
<expiration max-idle="100000" interval="5000"/>
<state-transfer enabled="false"/>
</replicated-cache>

<!-- A config appropriate for query caching. Does not replicate queries. -->
<local-cache name="local-query">
<locking isolation="READ_COMMITTED" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<transaction mode="NON_XA" locking="OPTIMISTIC" auto-commit="false"/>
<eviction max-entries="10000" strategy="LRU"/>
<expiration max-idle="100000" interval="5000"/>
</local-cache>

<!-- A query cache that replicates queries. Replication is asynchronous. -->
<replicated-cache name="replicated-query" mode="ASYNC">
<locking isolation="READ_COMMITTED" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<transaction mode="NON_XA" locking="OPTIMISTIC" auto-commit="false"/>
<eviction max-entries="10000" strategy="LRU"/>
<expiration max-idle="100000" interval="5000"/>
<persistence passivation="false">
<!-- State transfer forces all replication calls to be synchronous,
so for calls to remain async, use a cluster cache loader instead -->
<cluster-loader remote-timeout="20000"/>
</persistence>
</replicated-cache>

<!-- Optimized for timestamp caching. A clustered timestamp cache
is required if query caching is used, even if the query cache
itself is configured with CacheMode=LOCAL. -->
<replicated-cache name="timestamps" mode="ASYNC">
<locking isolation="READ_COMMITTED" concurrency-level="1000" acquire-timeout="15000" striping="false"/>
<!-- Explicitly non transactional -->
<transaction mode="NONE"/>
<!-- Don't ever evict modification timestamps -->
<eviction strategy="NONE"/>
<expiration interval="0"/>
<persistence passivation="false">
<!-- State transfer forces all replication calls to be synchronous,
so for calls to remain async, use a cluster cache loader instead -->
<cluster-loader remote-timeout="20000"/>
</persistence>
<state-transfer enabled="false"/>
</replicated-cache>
</cache-container>

</infinispan>

0 comments on commit 46a2a7a

Please sign in to comment.