Search in sources :

Example 16 with AdvancedCache

use of org.infinispan.AdvancedCache 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;
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Example 17 with AdvancedCache

use of org.infinispan.AdvancedCache in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method buildEntityRegion.

@Override
public EntityRegion buildEntityRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
    if (log.isDebugEnabled()) {
        log.debugf("Building entity cache region [%s] (mutable=%s, versioned=%s)", regionName, metadata.isMutable(), metadata.isVersioned());
    }
    final AdvancedCache cache = getCache(regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata);
    final EntityRegionImpl region = new EntityRegionImpl(cache, regionName, transactionManager, metadata, this, getCacheKeysFactory());
    startRegion(region);
    return region;
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Example 18 with AdvancedCache

use of org.infinispan.AdvancedCache in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method buildNaturalIdRegion.

@Override
public NaturalIdRegion buildNaturalIdRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
    if (log.isDebugEnabled()) {
        log.debug("Building natural id cache region [" + regionName + "]");
    }
    final AdvancedCache cache = getCache(regionName, DataType.NATURAL_ID, metadata);
    final NaturalIdRegionImpl region = new NaturalIdRegionImpl(cache, regionName, transactionManager, metadata, this, getCacheKeysFactory());
    startRegion(region);
    return region;
}
Also used : NaturalIdRegionImpl(org.hibernate.cache.infinispan.naturalid.NaturalIdRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Example 19 with AdvancedCache

use of org.infinispan.AdvancedCache in project hibernate-orm by hibernate.

the class EntityCollectionInvalidationTest method testConcurrentLoadAndRemoval.

@TestForIssue(jiraKey = "HHH-9881")
@Test
public void testConcurrentLoadAndRemoval() throws Exception {
    if (!remoteCustomerCache.getCacheConfiguration().clustering().cacheMode().isInvalidation()) {
        // This test is tailored for invalidation-based strategies, using pending puts cache
        return;
    }
    AtomicReference<Exception> getException = new AtomicReference<>();
    AtomicReference<Exception> deleteException = new AtomicReference<>();
    Phaser getPhaser = new Phaser(2);
    HookInterceptor hookInterceptor = new HookInterceptor(getException);
    AdvancedCache remotePPCache = remoteCustomerCache.getCacheManager().getCache(remoteCustomerCache.getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE).getAdvancedCache();
    remotePPCache.getAdvancedCache().addInterceptor(hookInterceptor, 0);
    IdContainer idContainer = new IdContainer();
    withTxSession(localFactory, s -> {
        Customer customer = new Customer();
        customer.setName("JBoss");
        s.persist(customer);
        idContainer.customerId = customer.getId();
    });
    // start loading
    Thread getThread = new Thread(() -> {
        try {
            withTxSession(remoteFactory, s -> {
                s.get(Customer.class, idContainer.customerId);
            });
        } catch (Exception e) {
            log.error("Failure to get customer", e);
            getException.set(e);
        }
    }, "get-thread");
    Thread deleteThread = new Thread(() -> {
        try {
            withTxSession(localFactory, s -> {
                Customer customer = s.get(Customer.class, idContainer.customerId);
                s.delete(customer);
            });
        } catch (Exception e) {
            log.error("Failure to delete customer", e);
            deleteException.set(e);
        }
    }, "delete-thread");
    // get thread should block on the beginning of PutFromLoadValidator#acquirePutFromLoadLock
    hookInterceptor.block(getPhaser, getThread);
    getThread.start();
    arriveAndAwait(getPhaser);
    deleteThread.start();
    deleteThread.join();
    hookInterceptor.unblock();
    arriveAndAwait(getPhaser);
    getThread.join();
    if (getException.get() != null) {
        throw new IllegalStateException("get-thread failed", getException.get());
    }
    if (deleteException.get() != null) {
        throw new IllegalStateException("delete-thread failed", deleteException.get());
    }
    Customer localCustomer = getCustomer(idContainer.customerId, localFactory);
    assertNull(localCustomer);
    Customer remoteCustomer = getCustomer(idContainer.customerId, remoteFactory);
    assertNull(remoteCustomer);
    assertTrue(remoteCustomerCache.isEmpty());
}
Also used : Customer(org.hibernate.test.cache.infinispan.functional.entities.Customer) AtomicReference(java.util.concurrent.atomic.AtomicReference) AdvancedCache(org.infinispan.AdvancedCache) Phaser(java.util.concurrent.Phaser) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 20 with AdvancedCache

use of org.infinispan.AdvancedCache in project hibernate-orm by hibernate.

the class InvalidationTest method getPendingPutsCache.

protected AdvancedCache getPendingPutsCache(Class<Item> entityClazz) {
    EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getCache().getEntityRegionAccess(entityClazz.getName()).getRegion();
    AdvancedCache entityCache = region.getCache();
    return (AdvancedCache) entityCache.getCacheManager().getCache(entityCache.getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE).getAdvancedCache();
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Aggregations

AdvancedCache (org.infinispan.AdvancedCache)32 Test (org.junit.Test)20 Properties (java.util.Properties)12 EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)10 Configuration (org.infinispan.configuration.cache.Configuration)9 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)7 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)7 TestForIssue (org.hibernate.testing.TestForIssue)7 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)6 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)5 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)5 List (java.util.List)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Session (org.hibernate.Session)4 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 TimeUnit (java.util.concurrent.TimeUnit)3