Search in sources :

Example 6 with AdvancedCache

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

the class InfinispanRegionFactoryTestCase method testBuildEntityCollectionRegionOverridesOnly.

@Test
public void testBuildEntityCollectionRegionOverridesOnly() {
    final String address = "com.acme.Address";
    final String personAddressses = "com.acme.Person.addresses";
    AdvancedCache cache;
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "30000");
    p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "35000");
    p.setProperty("hibernate.cache.infinispan.collection.expiration.wake_up_interval", "3500");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        factory.getCacheManager();
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion(address, p, MUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration(address));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(30000, cacheCfg.eviction().maxEntries());
        // Max idle value comes from base XML configuration
        assertEquals(100000, cacheCfg.expiration().maxIdle());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(personAddressses, p, MUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration(personAddressses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(35000, cacheCfg.eviction().maxEntries());
        assertEquals(100000, cacheCfg.expiration().maxIdle());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) CollectionRegionImpl(org.hibernate.cache.infinispan.collection.CollectionRegionImpl) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with AdvancedCache

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

the class InfinispanRegionFactoryTestCase method testBuildImmutableEntityRegion.

@Test
public void testBuildImmutableEntityRegion() {
    AdvancedCache cache;
    Properties p = new Properties();
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        factory.getCacheManager();
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, IMMUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration("com.acme.Address"));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals("Immutable entity should get non-transactional cache", TransactionMode.NON_TRANSACTIONAL, cacheCfg.transaction().transactionMode());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with AdvancedCache

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

the class InfinispanRegionFactoryTestCase method testBuildDefaultTimestampsRegion.

@Test
public void testBuildDefaultTimestampsRegion() {
    final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
    Properties p = createProperties();
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
        assertTrue(isDefinedCache(factory, DEF_TIMESTAMPS_RESOURCE));
        TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
        AdvancedCache cache = region.getCache();
        assertEquals(timestamps, cache.getName());
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
        assertEquals(CacheMode.REPL_ASYNC, cacheCfg.clustering().cacheMode());
        assertFalse(cacheCfg.jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with AdvancedCache

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

the class InvalidationTest method testFailedUpdate.

@TestForIssue(jiraKey = "HHH-11304")
@Test
public void testFailedUpdate() throws Exception {
    AdvancedCache pendingPutsCache = getPendingPutsCache(Item.class);
    assertNoInvalidators(pendingPutsCache);
    final Item item = new Item("before-update", "bar");
    withTxSession(s -> s.persist(item));
    withTxSession(s -> {
        Item item2 = s.load(Item.class, item.getId());
        assertEquals("before-update", item2.getName());
        item2.setName("after-update");
        s.persist(item2);
        s.flush();
        s.flush();
        s.getTransaction().setRollbackOnly();
    });
    assertNoInvalidators(pendingPutsCache);
    withTxSession(s -> {
        Item item3 = s.load(Item.class, item.getId());
        assertEquals("before-update", item3.getName());
        s.remove(item3);
    });
    assertNoInvalidators(pendingPutsCache);
}
Also used : Item(org.hibernate.test.cache.infinispan.functional.entities.Item) AdvancedCache(org.infinispan.AdvancedCache) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 10 with AdvancedCache

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

the class VersionedTest method testCollectionUpdate.

@Test
public void testCollectionUpdate() throws Exception {
    // the first insert puts VersionedEntry(null, null, timestamp), so we have to wait a while to cache the entry
    TIME_SERVICE.advance(1);
    withTxSession(s -> {
        Item item = s.load(Item.class, itemId);
        OtherItem otherItem = new OtherItem();
        otherItem.setName("Other 1");
        s.persist(otherItem);
        item.addOtherItem(otherItem);
    });
    withTxSession(s -> {
        Item item = s.load(Item.class, itemId);
        Set<OtherItem> otherItems = item.getOtherItems();
        assertFalse(otherItems.isEmpty());
        otherItems.remove(otherItems.iterator().next());
    });
    AdvancedCache collectionCache = ((BaseTransactionalDataRegion) sessionFactory().getSecondLevelCacheRegion(Item.class.getName() + ".otherItems")).getCache();
    CountDownLatch putFromLoadLatch = new CountDownLatch(1);
    AtomicBoolean committing = new AtomicBoolean(false);
    CollectionUpdateTestInterceptor collectionUpdateTestInterceptor = new CollectionUpdateTestInterceptor(putFromLoadLatch);
    AnotherCollectionUpdateTestInterceptor anotherInterceptor = new AnotherCollectionUpdateTestInterceptor(putFromLoadLatch, committing);
    collectionCache.addInterceptor(collectionUpdateTestInterceptor, collectionCache.getInterceptorChain().size() - 1);
    collectionCache.addInterceptor(anotherInterceptor, 0);
    TIME_SERVICE.advance(1);
    Future<Boolean> addFuture = executor.submit(() -> withTxSessionApply(s -> {
        collectionUpdateTestInterceptor.updateLatch.await();
        Item item = s.load(Item.class, itemId);
        OtherItem otherItem = new OtherItem();
        otherItem.setName("Other 2");
        s.persist(otherItem);
        item.addOtherItem(otherItem);
        committing.set(true);
        return true;
    }));
    Future<Boolean> readFuture = executor.submit(() -> withTxSessionApply(s -> {
        Item item = s.load(Item.class, itemId);
        assertTrue(item.getOtherItems().isEmpty());
        return true;
    }));
    addFuture.get();
    readFuture.get();
    collectionCache.removeInterceptor(CollectionUpdateTestInterceptor.class);
    collectionCache.removeInterceptor(AnotherCollectionUpdateTestInterceptor.class);
    withTxSession(s -> assertFalse(s.load(Item.class, itemId).getOtherItems().isEmpty()));
}
Also used : BaseTransactionalDataRegion(org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion) Arrays(java.util.Arrays) VersionedEntry(org.hibernate.cache.infinispan.util.VersionedEntry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Session(org.hibernate.Session) Caches(org.hibernate.cache.infinispan.util.Caches) AtomicReference(java.util.concurrent.atomic.AtomicReference) Future(java.util.concurrent.Future) PessimisticLockException(org.hibernate.PessimisticLockException) InvocationContext(org.infinispan.context.InvocationContext) AdvancedCache(org.infinispan.AdvancedCache) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Item(org.hibernate.test.cache.infinispan.functional.entities.Item) OtherItem(org.hibernate.test.cache.infinispan.functional.entities.OtherItem) Synchronization(javax.transaction.Synchronization) StaleStateException(org.hibernate.StaleStateException) CyclicBarrier(java.util.concurrent.CyclicBarrier) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) BaseCustomInterceptor(org.infinispan.interceptors.base.BaseCustomInterceptor) Assert.assertNull(org.junit.Assert.assertNull) Flag(org.infinispan.context.Flag) Assert.assertFalse(org.junit.Assert.assertFalse) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Item(org.hibernate.test.cache.infinispan.functional.entities.Item) OtherItem(org.hibernate.test.cache.infinispan.functional.entities.OtherItem) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OtherItem(org.hibernate.test.cache.infinispan.functional.entities.OtherItem) BaseTransactionalDataRegion(org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion) AdvancedCache(org.infinispan.AdvancedCache) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

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