Search in sources :

Example 11 with PutFromLoadValidator

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);
}
Also used : PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator)

Example 12 with PutFromLoadValidator

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);
}
Also used : PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator)

Example 13 with PutFromLoadValidator

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);
    }
}
Also used : PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) TimeoutException(java.util.concurrent.TimeoutException) Exceptions.expectException(org.infinispan.test.Exceptions.expectException)

Example 14 with PutFromLoadValidator

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());
}
Also used : PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) Exceptions.expectException(org.infinispan.test.Exceptions.expectException)

Aggregations

PutFromLoadValidator (org.hibernate.cache.infinispan.access.PutFromLoadValidator)14 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExecutorService (java.util.concurrent.ExecutorService)3 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 RegionAccessStrategy (org.hibernate.cache.spi.access.RegionAccessStrategy)2 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)2 Exceptions.expectException (org.infinispan.test.Exceptions.expectException)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NavigableMap (java.util.NavigableMap)1