@Test
 public void testBuildDiffCacheNameTimestampsRegion() {
   final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
   Properties p = createProperties();
   p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
   InfinispanRegionFactory factory = createRegionFactory(p);
   try {
     EmbeddedCacheManager manager = factory.getCacheManager();
     assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
     assertTrue(factory.getDefinedConfigurations().contains("unrecommended-timestamps"));
     assertTrue(
         factory
             .getTypeOverrides()
             .get("timestamps")
             .getCacheName()
             .equals("unrecommended-timestamps"));
     ConfigurationBuilder builder = new ConfigurationBuilder();
     builder.clustering().stateTransfer().fetchInMemoryState(true);
     builder.clustering().cacheMode(CacheMode.REPL_SYNC);
     manager.defineConfiguration("unrecommended-timestamps", builder.build());
     TimestampsRegionImpl region =
         (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
     AdvancedCache cache = region.getCache();
     Configuration cacheCfg = cache.getCacheConfiguration();
     assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
     assertEquals(CacheMode.REPL_SYNC, cacheCfg.clustering().cacheMode());
     assertFalse(cacheCfg.storeAsBinary().enabled());
     assertFalse(cacheCfg.jmxStatistics().enabled());
   } finally {
     factory.stop();
   }
 }
 /** {@inheritDoc} */
 public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties)
     throws CacheException {
   if (log.isDebugEnabled()) log.debug("Building timestamps cache region [" + regionName + "]");
   Cache cache = getCache(regionName, TIMESTAMPS_KEY, properties);
   CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
   TimestampsRegionImpl region = createTimestampsRegion(cacheAdapter, regionName);
   region.start();
   return region;
 }
  @Test
  public void testEnableStatistics() {
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.statistics", "true");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
    p.setProperty("hibernate.cache.infinispan.entity.cfg", "myentity-cache");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
      EmbeddedCacheManager manager = factory.getCacheManager();
      assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
      EntityRegionImpl region =
          (EntityRegionImpl)
              factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
      AdvancedCache cache = region.getCache();
      assertTrue(factory.getTypeOverrides().get("entity").isExposeStatistics());
      assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());

      region =
          (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
      cache = region.getCache();
      assertTrue(factory.getTypeOverrides().get("com.acme.Person").isExposeStatistics());
      assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());

      final String query = "org.hibernate.cache.internal.StandardQueryCache";
      QueryResultsRegionImpl queryRegion =
          (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
      cache = queryRegion.getCache();
      assertTrue(factory.getTypeOverrides().get("query").isExposeStatistics());
      assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());

      final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
      ConfigurationBuilder builder = new ConfigurationBuilder();
      builder.clustering().stateTransfer().fetchInMemoryState(true);
      manager.defineConfiguration("timestamps", builder.build());
      TimestampsRegionImpl timestampsRegion =
          (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
      cache = timestampsRegion.getCache();
      assertTrue(factory.getTypeOverrides().get("timestamps").isExposeStatistics());
      assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());

      CollectionRegionImpl collectionRegion =
          (CollectionRegionImpl)
              factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
      cache = collectionRegion.getCache();
      assertTrue(factory.getTypeOverrides().get("collection").isExposeStatistics());
      assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
    } finally {
      factory.stop();
    }
  }
 @Test
 public void testBuildDefaultTimestampsRegion() {
   final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
   Properties p = createProperties();
   InfinispanRegionFactory factory = createRegionFactory(p);
   try {
     assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
     assertTrue(factory.getTypeOverrides().get("timestamps").getCacheName().equals("timestamps"));
     TimestampsRegionImpl region =
         (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
     AdvancedCache cache = region.getCache();
     Configuration cacheCfg = cache.getCacheConfiguration();
     assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
     assertEquals(CacheMode.REPL_ASYNC, cacheCfg.clustering().cacheMode());
     assertFalse(cacheCfg.jmxStatistics().enabled());
   } finally {
     factory.stop();
   }
 }