use of org.hibernate.cache.infinispan.access.AccessDelegate in project hibernate-orm by hibernate.
the class EntityRegionImpl method buildAccessStrategy.
@Override
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
checkAccessType(accessType);
AccessDelegate accessDelegate = createAccessDelegate(accessType);
if (accessType == AccessType.READ_ONLY || !getCacheDataDescription().isMutable()) {
return new ReadOnlyAccess(this, accessDelegate);
} else {
return new ReadWriteAccess(this, accessDelegate);
}
}
use of org.hibernate.cache.infinispan.access.AccessDelegate in project hibernate-orm by hibernate.
the class NaturalIdRegionImpl method buildAccessStrategy.
@Override
public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
checkAccessType(accessType);
AccessDelegate accessDelegate = createAccessDelegate(accessType);
if (accessType == AccessType.READ_ONLY || !getCacheDataDescription().isMutable()) {
return new ReadOnlyAccess(this, accessDelegate);
} else {
return new ReadWriteAccess(this, accessDelegate);
}
}
use of org.hibernate.cache.infinispan.access.AccessDelegate in project hibernate-orm by hibernate.
the class CollectionRegionAccessStrategyTest method testPutFromLoadRemoveDoesNotProduceStaleData.
@Test
public void testPutFromLoadRemoveDoesNotProduceStaleData() throws Exception {
if (!cacheMode.isInvalidation()) {
return;
}
final CountDownLatch pferLatch = new CountDownLatch(1);
final CountDownLatch removeLatch = new CountDownLatch(1);
// remove the interceptor inserted by default PutFromLoadValidator, we're using different one
PutFromLoadValidator originalValidator = PutFromLoadValidator.removeFromCache(localRegion.getCache());
PutFromLoadValidator mockValidator = spy(originalValidator);
doAnswer(invocation -> {
try {
return invocation.callRealMethod();
} finally {
try {
removeLatch.countDown();
assertFalse(pferLatch.await(2, TimeUnit.SECONDS));
} catch (InterruptedException e) {
log.debug("Interrupted");
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error("Error", e);
throw new RuntimeException("Error", e);
}
}
}).when(mockValidator).acquirePutFromLoadLock(any(), any(), anyLong());
PutFromLoadValidator.addToCache(localRegion.getCache(), mockValidator);
cleanup.add(() -> {
PutFromLoadValidator.removeFromCache(localRegion.getCache());
PutFromLoadValidator.addToCache(localRegion.getCache(), originalValidator);
});
final AccessDelegate delegate = localRegion.getCache().getCacheConfiguration().transaction().transactionMode().isTransactional() ? new TxInvalidationCacheAccessDelegate(localRegion, mockValidator) : new NonTxInvalidationCacheAccessDelegate(localRegion, mockValidator);
ExecutorService executorService = Executors.newCachedThreadPool();
cleanup.add(() -> executorService.shutdownNow());
final String KEY = "k1";
Future<Void> pferFuture = executorService.submit(() -> {
SharedSessionContractImplementor session = mockedSession();
delegate.putFromLoad(session, KEY, "v1", session.getTimestamp(), null);
return null;
});
Future<Void> removeFuture = executorService.submit(() -> {
removeLatch.await();
SharedSessionContractImplementor session = mockedSession();
withTx(localEnvironment, session, () -> {
delegate.remove(session, KEY);
return null;
});
pferLatch.countDown();
return null;
});
pferFuture.get();
removeFuture.get();
assertFalse(localRegion.getCache().containsKey(KEY));
assertFalse(remoteRegion.getCache().containsKey(KEY));
}
use of org.hibernate.cache.infinispan.access.AccessDelegate in project hibernate-orm by hibernate.
the class CollectionRegionImpl method buildAccessStrategy.
@Override
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
checkAccessType(accessType);
AccessDelegate accessDelegate = createAccessDelegate(accessType);
return new CollectionAccess(this, accessDelegate);
}
Aggregations