Search in sources :

Example 1 with LockContainer

use of org.infinispan.util.concurrent.locks.impl.LockContainer in project infinispan by infinispan.

the class PessimisticLockingTxClusterExtendedStatisticLogicTest method createCacheManagers.

@Override
protected void createCacheManagers() {
    for (int i = 0; i < NUM_NODES; ++i) {
        ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
        builder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0));
        // 
        builder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ).lockAcquisitionTimeout(// the timeout are triggered by the TimeService!
        60000);
        builder.transaction().recovery().disable();
        builder.transaction().lockingMode(LockingMode.PESSIMISTIC);
        // builder.versioning().enable().scheme(VersioningScheme.SIMPLE);
        extendedStatisticInterceptors[i] = new ExtendedStatisticInterceptor();
        builder.customInterceptors().addInterceptor().interceptor(extendedStatisticInterceptors[i]).after(TxInterceptor.class);
        addClusterEnabledCacheManager(builder);
    }
    waitForClusterToForm();
    for (int i = 0; i < NUM_NODES; ++i) {
        ExtendedStatisticInterceptor interceptor = extendedStatisticInterceptors[i];
        CacheStatisticManager manager = extractField(interceptor, "cacheStatisticManager");
        CacheStatisticCollector collector = extractField(manager, "cacheStatisticCollector");
        ConcurrentGlobalContainer globalContainer = extractField(collector, "globalContainer");
        ExtendedStatisticRpcManager rpcManager = (ExtendedStatisticRpcManager) extractComponent(cache(i), RpcManager.class);
        ExtendedStatisticLockManager lockManager = (ExtendedStatisticLockManager) extractLockManager(cache(i));
        lockManagers[i] = lockManager;
        replaceField(TEST_TIME_SERVICE, "timeService", manager, CacheStatisticManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", collector, CacheStatisticCollector.class);
        replaceField(TEST_TIME_SERVICE, "timeService", globalContainer, ConcurrentGlobalContainer.class);
        replaceField(TEST_TIME_SERVICE, "timeService", interceptor, ExtendedStatisticInterceptor.class);
        replaceField(TEST_TIME_SERVICE, "timeService", lockManager, ExtendedStatisticLockManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", rpcManager, ExtendedStatisticRpcManager.class);
        controlledRpcManager[i] = ControlledRpcManager.replaceRpcManager(cache(i));
        transactionTrackInterceptors[i] = TransactionTrackInterceptor.injectInCache(cache(i));
        if (i == 0) {
            LockManager actualLockManager = lockManager.getActual();
            LockContainer container = extractField(actualLockManager, "lockContainer");
            TestingUtil.inject(container, new WithinThreadExecutor(), lockManagerTimeService);
        }
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) RpcManager(org.infinispan.remoting.rpc.RpcManager) CacheStatisticCollector(org.infinispan.extendedstats.CacheStatisticCollector) ExtendedStatisticInterceptor(org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) ReplicatedControlledConsistentHashFactory(org.infinispan.util.ReplicatedControlledConsistentHashFactory) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer) CacheStatisticManager(org.infinispan.extendedstats.CacheStatisticManager) LockManager(org.infinispan.util.concurrent.locks.LockManager) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) TestingUtil.extractLockManager(org.infinispan.test.TestingUtil.extractLockManager) LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Example 2 with LockContainer

use of org.infinispan.util.concurrent.locks.impl.LockContainer in project infinispan by infinispan.

the class KeyLockTest method doTest.

private void doTest(CacheName cacheName) throws Exception {
    final LockContainer lockContainer = TestingUtil.extractComponent(cache(cacheName.name()), LockContainer.class);
    final Object lockOwner = new Object();
    try {
        lockContainer.acquire(byteArray(), lockOwner, 10, TimeUnit.MILLISECONDS).lock();
    } catch (InterruptedException | TimeoutException e) {
        AssertJUnit.fail();
    }
    AssertJUnit.assertTrue(lockContainer.isLocked(byteArray()));
    fork(() -> {
        for (int i = 0; i < RETRIES; ++i) {
            AssertJUnit.assertTrue(lockContainer.isLocked(byteArray()));
            try {
                lockContainer.acquire(byteArray(), new Object(), 10, TimeUnit.MILLISECONDS).lock();
                AssertJUnit.fail();
            } catch (InterruptedException | TimeoutException e) {
            // expected
            }
        }
        return null;
    }).get(10, TimeUnit.SECONDS);
}
Also used : LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer) TimeoutException(org.infinispan.util.concurrent.TimeoutException)

Example 3 with LockContainer

use of org.infinispan.util.concurrent.locks.impl.LockContainer in project infinispan by infinispan.

the class LockAssert method assertNoLocks.

public static void assertNoLocks(LockManager lockManager) {
    LockContainer lc = TestingUtil.extractField(lockManager, "lockContainer");
    assertEquals("Stale locks exist! NumLocksHeld is " + lc.getNumLocksHeld() + " and lock info is " + lockManager.printLockInfo(), 0, lc.getNumLocksHeld());
}
Also used : LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Example 4 with LockContainer

use of org.infinispan.util.concurrent.locks.impl.LockContainer in project infinispan by infinispan.

the class LockPerEntryTest method assertNoLocks.

private void assertNoLocks() {
    LockManager lm = TestingUtil.extractLockManager(cache);
    LockAssert.assertNoLocks(lm);
    LockContainer lc = TestingUtil.extractField(lm, "lockContainer");
    assert lc.size() == 0;
}
Also used : LockManager(org.infinispan.util.concurrent.locks.LockManager) LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Example 5 with LockContainer

use of org.infinispan.util.concurrent.locks.impl.LockContainer in project infinispan by infinispan.

the class OptimisticLockingTxClusterExtendedStatisticLogicTest method createCacheManagers.

@Override
protected void createCacheManagers() {
    for (int i = 0; i < NUM_NODES; ++i) {
        ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
        builder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0));
        builder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ).lockAcquisitionTimeout(TestingUtil.shortTimeoutMillis());
        builder.transaction().recovery().disable();
        builder.transaction().lockingMode(LockingMode.OPTIMISTIC);
        extendedStatisticInterceptors[i] = new ExtendedStatisticInterceptor();
        builder.customInterceptors().addInterceptor().interceptor(extendedStatisticInterceptors[i]).after(TxInterceptor.class);
        addClusterEnabledCacheManager(builder);
    }
    waitForClusterToForm();
    for (int i = 0; i < NUM_NODES; ++i) {
        ExtendedStatisticInterceptor interceptor = extendedStatisticInterceptors[i];
        CacheStatisticManager manager = extractField(interceptor, "cacheStatisticManager");
        CacheStatisticCollector collector = extractField(manager, "cacheStatisticCollector");
        ConcurrentGlobalContainer globalContainer = extractField(collector, "globalContainer");
        ExtendedStatisticRpcManager rpcManager = (ExtendedStatisticRpcManager) extractComponent(cache(i), RpcManager.class);
        ExtendedStatisticLockManager lockManager = (ExtendedStatisticLockManager) extractLockManager(cache(i));
        lockManagers[i] = lockManager;
        replaceField(TEST_TIME_SERVICE, "timeService", manager, CacheStatisticManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", collector, CacheStatisticCollector.class);
        replaceField(TEST_TIME_SERVICE, "timeService", globalContainer, ConcurrentGlobalContainer.class);
        replaceField(TEST_TIME_SERVICE, "timeService", interceptor, ExtendedStatisticInterceptor.class);
        replaceField(TEST_TIME_SERVICE, "timeService", lockManager, ExtendedStatisticLockManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", rpcManager, ExtendedStatisticRpcManager.class);
        controlledRpcManager[i] = ControlledRpcManager.replaceRpcManager(cache(i));
        transactionTrackInterceptors[i] = TransactionTrackInterceptor.injectInCache(cache(i));
        if (i == 0) {
            LockManager actualLockManager = lockManager.getActual();
            LockContainer container = extractField(actualLockManager, "lockContainer");
            TestingUtil.inject(container, new WithinThreadExecutor(), lockManagerTimeService);
        }
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) RpcManager(org.infinispan.remoting.rpc.RpcManager) CacheStatisticCollector(org.infinispan.extendedstats.CacheStatisticCollector) ExtendedStatisticInterceptor(org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) ReplicatedControlledConsistentHashFactory(org.infinispan.util.ReplicatedControlledConsistentHashFactory) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer) CacheStatisticManager(org.infinispan.extendedstats.CacheStatisticManager) LockManager(org.infinispan.util.concurrent.locks.LockManager) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) TestingUtil.extractLockManager(org.infinispan.test.TestingUtil.extractLockManager) LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Aggregations

LockContainer (org.infinispan.util.concurrent.locks.impl.LockContainer)5 LockManager (org.infinispan.util.concurrent.locks.LockManager)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 CacheStatisticCollector (org.infinispan.extendedstats.CacheStatisticCollector)2 CacheStatisticManager (org.infinispan.extendedstats.CacheStatisticManager)2 ConcurrentGlobalContainer (org.infinispan.extendedstats.container.ConcurrentGlobalContainer)2 ExtendedStatisticInterceptor (org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor)2 ExtendedStatisticLockManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager)2 ExtendedStatisticRpcManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager)2 RpcManager (org.infinispan.remoting.rpc.RpcManager)2 TestingUtil.extractLockManager (org.infinispan.test.TestingUtil.extractLockManager)2 ControlledRpcManager (org.infinispan.util.ControlledRpcManager)2 ReplicatedControlledConsistentHashFactory (org.infinispan.util.ReplicatedControlledConsistentHashFactory)2 WithinThreadExecutor (org.infinispan.util.concurrent.WithinThreadExecutor)2 TimeoutException (org.infinispan.util.concurrent.TimeoutException)1