Search in sources :

Example 1 with IsolationLevel

use of org.infinispan.util.concurrent.IsolationLevel in project hibernate-orm by hibernate.

the class QueryRegionImplTest method testGetDoesNotBlockPut.

@Test
public void testGetDoesNotBlockPut() throws Exception {
    withQueryRegion((sessionFactory, region) -> {
        withSession(sessionFactory, session -> region.put(session, KEY, VALUE1));
        assertEquals(VALUE1, callWithSession(sessionFactory, session -> region.get(session, KEY)));
        final AdvancedCache cache = ((QueryResultsRegionImpl) region).getCache();
        final CountDownLatch blockerLatch = new CountDownLatch(1);
        final CountDownLatch writerLatch = new CountDownLatch(1);
        final CountDownLatch completionLatch = new CountDownLatch(1);
        final ExceptionHolder holder = new ExceptionHolder();
        Thread reader = new Thread() {

            @Override
            public void run() {
                GetBlocker blocker = new GetBlocker(blockerLatch, KEY);
                try {
                    cache.addListener(blocker);
                    withSession(sessionFactory, session -> region.get(session, KEY));
                } catch (Exception e) {
                    holder.addException(e);
                } finally {
                    cache.removeListener(blocker);
                }
            }
        };
        Thread writer = new Thread() {

            @Override
            public void run() {
                try {
                    writerLatch.await();
                    withSession(sessionFactory, session -> region.put(session, KEY, VALUE2));
                } catch (Exception e) {
                    holder.addException(e);
                } finally {
                    completionLatch.countDown();
                }
            }
        };
        reader.setDaemon(true);
        writer.setDaemon(true);
        boolean unblocked = false;
        try {
            reader.start();
            writer.start();
            assertFalse("Reader is blocking", completionLatch.await(100, TimeUnit.MILLISECONDS));
            // Start the writer
            writerLatch.countDown();
            assertTrue("Writer finished promptly", completionLatch.await(100, TimeUnit.MILLISECONDS));
            blockerLatch.countDown();
            unblocked = true;
            if (IsolationLevel.REPEATABLE_READ.equals(cache.getCacheConfiguration().locking().isolationLevel())) {
                assertEquals(VALUE1, callWithSession(sessionFactory, session -> region.get(session, KEY)));
            } else {
                assertEquals(VALUE2, callWithSession(sessionFactory, session -> region.get(session, KEY)));
            }
            holder.checkExceptions();
        } finally {
            if (!unblocked) {
                blockerLatch.countDown();
            }
        }
    });
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) Logger(org.jboss.logging.Logger) CacheEntryModifiedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent) CacheEntryVisitedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent) Session(org.hibernate.Session) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) QueryResultsRegion(org.hibernate.cache.spi.QueryResultsRegion) ArrayList(java.util.ArrayList) Transaction(org.hibernate.Transaction) TestForIssue(org.hibernate.testing.TestForIssue) CacheEntryVisited(org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited) AdvancedCache(org.infinispan.AdvancedCache) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) CyclicBarrier(java.util.concurrent.CyclicBarrier) Properties(java.util.Properties) Listener(org.infinispan.notifications.Listener) SessionFactory(org.hibernate.SessionFactory) CacheTestUtil(org.hibernate.test.cache.infinispan.util.CacheTestUtil) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) StandardQueryCache(org.hibernate.cache.internal.StandardQueryCache) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheDataDescription(org.hibernate.cache.spi.CacheDataDescription) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Region(org.hibernate.cache.spi.Region) AbstractGeneralDataRegionTest(org.hibernate.test.cache.infinispan.AbstractGeneralDataRegionTest) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) AdvancedCache(org.infinispan.AdvancedCache) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) AbstractGeneralDataRegionTest(org.hibernate.test.cache.infinispan.AbstractGeneralDataRegionTest)

Example 2 with IsolationLevel

use of org.infinispan.util.concurrent.IsolationLevel in project wildfly by wildfly.

the class CacheConfigurationBuilder method configure.

@Override
public Builder<Configuration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    boolean enabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    this.statistics = new ConfigurationBuilder().jmxStatistics().enabled(enabled).available(enabled).create();
    this.global = new InjectedValueDependency<>(InfinispanRequirement.CONFIGURATION.getServiceName(context, this.containerName), GlobalConfiguration.class);
    this.builder = new org.wildfly.clustering.infinispan.spi.service.ConfigurationBuilder(CONFIGURATION.getServiceName(context.getCurrentAddress()), this.containerName, this.cacheName, this.andThen(builder -> {
        CacheMode mode = builder.clustering().cacheMode();
        if (mode.isSynchronous() && (this.transaction.getValue().lockingMode() == LockingMode.OPTIMISTIC) && (this.locking.getValue().isolationLevel() == IsolationLevel.REPEATABLE_READ)) {
            builder.locking().writeSkewCheck(true);
            builder.versioning().enable().scheme(VersioningScheme.SIMPLE);
        }
        GroupsConfigurationBuilder groupsBuilder = builder.clustering().hash().groups().enabled();
        this.module.getValue().loadService(Grouper.class).forEach(grouper -> groupsBuilder.addGrouper(grouper));
    })).configure(context);
    return this;
}
Also used : ValueDependency(org.wildfly.clustering.service.ValueDependency) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExpirationConfiguration(org.infinispan.configuration.cache.ExpirationConfiguration) PersistenceConfiguration(org.infinispan.configuration.cache.PersistenceConfiguration) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) OperationContext(org.jboss.as.controller.OperationContext) EvictionConfiguration(org.infinispan.configuration.cache.EvictionConfiguration) GroupsConfigurationBuilder(org.infinispan.configuration.cache.GroupsConfigurationBuilder) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) Capability(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Capability) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) VersioningScheme(org.infinispan.configuration.cache.VersioningScheme) PathAddress(org.jboss.as.controller.PathAddress) Attribute(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Attribute) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) LockingMode(org.infinispan.transaction.LockingMode) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) Consumer(java.util.function.Consumer) ServiceController(org.jboss.msc.service.ServiceController) CacheMode(org.infinispan.configuration.cache.CacheMode) Grouper(org.infinispan.distribution.group.Grouper) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) Configuration(org.infinispan.configuration.cache.Configuration) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) LockingConfiguration(org.infinispan.configuration.cache.LockingConfiguration) JMXStatisticsConfiguration(org.infinispan.configuration.cache.JMXStatisticsConfiguration) Builder(org.wildfly.clustering.service.Builder) InjectedValue(org.jboss.msc.value.InjectedValue) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GroupsConfigurationBuilder(org.infinispan.configuration.cache.GroupsConfigurationBuilder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) GroupsConfigurationBuilder(org.infinispan.configuration.cache.GroupsConfigurationBuilder) CacheMode(org.infinispan.configuration.cache.CacheMode)

Aggregations

IsolationLevel (org.infinispan.util.concurrent.IsolationLevel)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 Transaction (org.hibernate.Transaction)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)1 StandardQueryCache (org.hibernate.cache.internal.StandardQueryCache)1 CacheDataDescription (org.hibernate.cache.spi.CacheDataDescription)1 QueryResultsRegion (org.hibernate.cache.spi.QueryResultsRegion)1 Region (org.hibernate.cache.spi.Region)1