use of org.infinispan.util.concurrent.IsolationLevel 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.infinispan.util.concurrent.IsolationLevel in project wildfly by wildfly.
the class CacheConfigurationBuilder method configure.
@Override
public Builder<Configuration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
boolean enabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
this.statistics = new ConfigurationBuilder().jmxStatistics().enabled(enabled).available(enabled).create();
this.global = new InjectedValueDependency<>(InfinispanRequirement.CONFIGURATION.getServiceName(context, this.containerName), GlobalConfiguration.class);
this.builder = new org.wildfly.clustering.infinispan.spi.service.ConfigurationBuilder(CONFIGURATION.getServiceName(context.getCurrentAddress()), this.containerName, this.cacheName, this.andThen(builder -> {
CacheMode mode = builder.clustering().cacheMode();
if (mode.isSynchronous() && (this.transaction.getValue().lockingMode() == LockingMode.OPTIMISTIC) && (this.locking.getValue().isolationLevel() == IsolationLevel.REPEATABLE_READ)) {
builder.locking().writeSkewCheck(true);
builder.versioning().enable().scheme(VersioningScheme.SIMPLE);
}
GroupsConfigurationBuilder groupsBuilder = builder.clustering().hash().groups().enabled();
this.module.getValue().loadService(Grouper.class).forEach(grouper -> groupsBuilder.addGrouper(grouper));
})).configure(context);
return this;
}
Aggregations