@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();
    }
  }
  /** {@inheritDoc} */
  public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties)
      throws CacheException {
    if (log.isDebugEnabled()) log.debug("Building query results cache region [" + regionName + "]");
    String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
    // If region name is not default one, lookup a cache for that region name
    if (!regionName.equals("org.hibernate.cache.internal.StandardQueryCache"))
      cacheName = regionName;

    Cache cache = getCache(cacheName, QUERY_KEY, properties);
    CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
    QueryResultsRegionImpl region =
        new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
    region.start();
    return region;
  }
 @Test
 public void testBuildQueryRegion() {
   final String query = "org.hibernate.cache.internal.StandardQueryCache";
   Properties p = createProperties();
   InfinispanRegionFactory factory = createRegionFactory(p);
   try {
     assertTrue(factory.getDefinedConfigurations().contains("local-query"));
     QueryResultsRegionImpl region =
         (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
     AdvancedCache cache = region.getCache();
     Configuration cacheCfg = cache.getCacheConfiguration();
     assertEquals(CacheMode.LOCAL, cacheCfg.clustering().cacheMode());
     assertFalse(cacheCfg.jmxStatistics().enabled());
   } finally {
     factory.stop();
   }
 }
 @Test
 public void testBuildQueryRegionWithCustomRegionName() {
   final String queryRegionName = "myquery";
   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");
   p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
   InfinispanRegionFactory factory = createRegionFactory(p);
   try {
     assertTrue(factory.getDefinedConfigurations().contains("local-query"));
     QueryResultsRegionImpl region =
         (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
     assertNotNull(factory.getTypeOverrides().get(queryRegionName));
     assertTrue(factory.getDefinedConfigurations().contains(queryRegionName));
     AdvancedCache cache = region.getCache();
     Configuration cacheCfg = cache.getCacheConfiguration();
     assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
     assertEquals(2222, cacheCfg.expiration().wakeUpInterval());
     assertEquals(11111, cacheCfg.eviction().maxEntries());
   } finally {
     factory.stop();
   }
 }