use of org.hibernate.cache.infinispan.access.PutFromLoadValidator in project hibernate-orm by hibernate.
the class PutFromLoadValidatorUnitTest method nakedPutAfterRemovalTest.
private void nakedPutAfterRemovalTest(final boolean transactional, final boolean removeRegion) throws Exception {
PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory(cm));
Invalidation invalidation = new Invalidation(testee, removeRegion);
// the naked put can succeed because it has txTimestamp after invalidation
NakedPut nakedPut = new NakedPut(testee, true);
exec(transactional, invalidation, nakedPut);
}
use of org.hibernate.cache.infinispan.access.PutFromLoadValidator in project hibernate-orm by hibernate.
the class PutFromLoadValidatorUnitTest method registeredPutAfterRemovalTest.
private void registeredPutAfterRemovalTest(final boolean transactional, final boolean removeRegion) throws Exception {
PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory(cm));
Invalidation invalidation = new Invalidation(testee, removeRegion);
RegularPut regularPut = new RegularPut(testee);
exec(transactional, invalidation, regularPut);
}
use of org.hibernate.cache.infinispan.access.PutFromLoadValidator in project hibernate-orm by hibernate.
the class PutFromLoadValidatorUnitTest method registeredPutWithInterveningRemovalTest.
private void registeredPutWithInterveningRemovalTest(final boolean transactional, final boolean removeRegion) throws Exception {
PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory(cm));
try {
long txTimestamp = TIME_SERVICE.wallClockTime();
if (transactional) {
tm.begin();
}
SharedSessionContractImplementor session1 = mock(SharedSessionContractImplementor.class);
SharedSessionContractImplementor session2 = mock(SharedSessionContractImplementor.class);
testee.registerPendingPut(session1, KEY1, txTimestamp);
if (removeRegion) {
testee.beginInvalidatingRegion();
} else {
testee.beginInvalidatingKey(session2, KEY1);
}
PutFromLoadValidator.Lock lock = testee.acquirePutFromLoadLock(session1, KEY1, txTimestamp);
try {
assertNull(lock);
} finally {
if (lock != null) {
testee.releasePutFromLoadLock(KEY1, lock);
}
if (removeRegion) {
testee.endInvalidatingRegion();
} else {
testee.endInvalidatingKey(session2, KEY1);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.hibernate.cache.infinispan.access.PutFromLoadValidator in project hibernate-orm by hibernate.
the class PutFromLoadValidatorUnitTest method multipleRegistrationtest.
private void multipleRegistrationtest(final boolean transactional) throws Exception {
final PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory(cm));
final CountDownLatch registeredLatch = new CountDownLatch(3);
final CountDownLatch finishedLatch = new CountDownLatch(3);
final AtomicInteger success = new AtomicInteger();
Runnable r = () -> {
try {
long txTimestamp = TIME_SERVICE.wallClockTime();
if (transactional) {
tm.begin();
}
SharedSessionContractImplementor session = mock(SharedSessionContractImplementor.class);
testee.registerPendingPut(session, KEY1, txTimestamp);
registeredLatch.countDown();
registeredLatch.await(5, TimeUnit.SECONDS);
PutFromLoadValidator.Lock lock = testee.acquirePutFromLoadLock(session, KEY1, txTimestamp);
if (lock != null) {
try {
log.trace("Put from load lock acquired for key = " + KEY1);
success.incrementAndGet();
} finally {
testee.releasePutFromLoadLock(KEY1, lock);
}
} else {
log.trace("Unable to acquired putFromLoad lock for key = " + KEY1);
}
finishedLatch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
};
ExecutorService executor = Executors.newFixedThreadPool(3);
cleanup.add(() -> executor.shutdownNow());
// Start with a removal so the "isPutValid" calls will fail if
// any of the concurrent activity isn't handled properly
testee.beginInvalidatingRegion();
testee.endInvalidatingRegion();
TIME_SERVICE.advance(1);
// Do the registration + isPutValid calls
executor.execute(r);
executor.execute(r);
executor.execute(r);
assertTrue(finishedLatch.await(5, TimeUnit.SECONDS));
assertEquals("All threads succeeded", 3, success.get());
}
Aggregations