use of org.hibernate.cache.infinispan.query.QueryResultsRegionImpl in project hibernate-orm by hibernate.
the class QueryRegionImplTest method testGetDoesNotBlockPut.
@Test
public void testGetDoesNotBlockPut() throws Exception {
withQueryRegion((sessionFactory, region) -> {
withSession(sessionFactory, session -> region.put(session, KEY, VALUE1));
assertEquals(VALUE1, callWithSession(sessionFactory, session -> region.get(session, KEY)));
final AdvancedCache cache = ((QueryResultsRegionImpl) region).getCache();
final CountDownLatch blockerLatch = new CountDownLatch(1);
final CountDownLatch writerLatch = new CountDownLatch(1);
final CountDownLatch completionLatch = new CountDownLatch(1);
final ExceptionHolder holder = new ExceptionHolder();
Thread reader = new Thread() {
@Override
public void run() {
GetBlocker blocker = new GetBlocker(blockerLatch, KEY);
try {
cache.addListener(blocker);
withSession(sessionFactory, session -> region.get(session, KEY));
} catch (Exception e) {
holder.addException(e);
} finally {
cache.removeListener(blocker);
}
}
};
Thread writer = new Thread() {
@Override
public void run() {
try {
writerLatch.await();
withSession(sessionFactory, session -> region.put(session, KEY, VALUE2));
} catch (Exception e) {
holder.addException(e);
} finally {
completionLatch.countDown();
}
}
};
reader.setDaemon(true);
writer.setDaemon(true);
boolean unblocked = false;
try {
reader.start();
writer.start();
assertFalse("Reader is blocking", completionLatch.await(100, TimeUnit.MILLISECONDS));
// Start the writer
writerLatch.countDown();
assertTrue("Writer finished promptly", completionLatch.await(100, TimeUnit.MILLISECONDS));
blockerLatch.countDown();
unblocked = true;
if (IsolationLevel.REPEATABLE_READ.equals(cache.getCacheConfiguration().locking().isolationLevel())) {
assertEquals(VALUE1, callWithSession(sessionFactory, session -> region.get(session, KEY)));
} else {
assertEquals(VALUE2, callWithSession(sessionFactory, session -> region.get(session, KEY)));
}
holder.checkExceptions();
} finally {
if (!unblocked) {
blockerLatch.countDown();
}
}
});
}
use of org.hibernate.cache.infinispan.query.QueryResultsRegionImpl in project hibernate-orm by hibernate.
the class QueryRegionImplTest method testPutDuringPut.
@Test
@TestForIssue(jiraKey = "HHH-7898")
public void testPutDuringPut() throws Exception {
withQueryRegion((sessionFactory, region) -> {
withSession(sessionFactory, session -> region.put(session, KEY, VALUE1));
assertEquals(VALUE1, callWithSession(sessionFactory, session -> region.get(session, KEY)));
final AdvancedCache cache = ((QueryResultsRegionImpl) region).getCache();
CountDownLatch blockerLatch = new CountDownLatch(1);
CountDownLatch triggerLatch = new CountDownLatch(1);
ExceptionHolder holder = new ExceptionHolder();
Thread blocking = new Thread() {
@Override
public void run() {
PutBlocker blocker = null;
try {
blocker = new PutBlocker(blockerLatch, triggerLatch, KEY);
cache.addListener(blocker);
withSession(sessionFactory, session -> region.put(session, KEY, VALUE2));
} catch (Exception e) {
holder.addException(e);
} finally {
if (blocker != null) {
cache.removeListener(blocker);
}
if (triggerLatch.getCount() > 0) {
triggerLatch.countDown();
}
}
}
};
Thread blocked = new Thread() {
@Override
public void run() {
try {
triggerLatch.await();
// this should silently fail
withSession(sessionFactory, session -> region.put(session, KEY, VALUE3));
} catch (Exception e) {
holder.addException(e);
}
}
};
blocking.setName("blocking-thread");
blocking.start();
blocked.setName("blocked-thread");
blocked.start();
blocked.join();
blockerLatch.countDown();
blocking.join();
holder.checkExceptions();
assertEquals(VALUE2, callWithSession(sessionFactory, session -> region.get(session, KEY)));
});
}
use of org.hibernate.cache.infinispan.query.QueryResultsRegionImpl in project hibernate-orm by hibernate.
the class InfinispanRegionFactory method buildQueryResultsRegion.
@Override
public QueryResultsRegion buildQueryResultsRegion(String regionName, Map<String, Object> configValues) {
if (log.isDebugEnabled()) {
log.debug("Building query results cache region [" + regionName + "]");
}
final AdvancedCache cache = getCache(regionName, DataType.QUERY, null);
final QueryResultsRegionImpl region = new QueryResultsRegionImpl(cache, regionName, transactionManager, this);
startRegion(region);
return region;
}
use of org.hibernate.cache.infinispan.query.QueryResultsRegionImpl in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testBuildQueryRegionWithCustomRegionName.
@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.expiration.wake_up_interval", "2222");
p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
TestInfinispanRegionFactory factory = createRegionFactory(p);
try {
assertTrue(isDefinedCache(factory, "local-query"));
QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
assertNotNull(factory.getBaseConfiguration(queryRegionName));
assertTrue(isDefinedCache(factory, 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();
}
}
use of org.hibernate.cache.infinispan.query.QueryResultsRegionImpl in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testEnableStatistics.
@Test
public void testEnableStatistics() {
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
p.setProperty("hibernate.cache.infinispan.entity.cfg", "myentity-cache");
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
InfinispanRegionFactory factory = createRegionFactory(p);
try {
EmbeddedCacheManager manager = factory.getCacheManager();
assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
AdvancedCache cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String query = "org.hibernate.cache.internal.StandardQueryCache";
QueryResultsRegionImpl queryRegion = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
cache = queryRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().stateTransfer().fetchInMemoryState(true);
manager.defineConfiguration("timestamps", builder.build());
TimestampsRegionImpl timestampsRegion = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
cache = timestampsRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
cache = collectionRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
} finally {
factory.stop();
}
}
Aggregations