Search in sources :

Example 1 with LockResource

use of com.hazelcast.internal.locksupport.LockResource in project hazelcast by hazelcast.

the class MapTransactionTest method testGetForUpdate_releasesBackupLock.

@Test
public void testGetForUpdate_releasesBackupLock() {
    Config config = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    instance1.executeTransaction(new TransactionalTask<Object>() {

        @Override
        public Object execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> map = context.getMap(randomString());
            map.getForUpdate(keyOwnedByInstance2);
            return null;
        }
    });
    NodeEngine nodeEngine = getNodeEngineImpl(instance1);
    Data keyData = nodeEngine.toData(keyOwnedByInstance2);
    LockSupportService lockService = nodeEngine.getService(LockSupportService.SERVICE_NAME);
    for (LockResource lockResource : lockService.getAllLocks()) {
        if (keyData.equals(lockResource.getKey())) {
            assertEquals(0, lockResource.getLockCount());
        }
    }
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Data(com.hazelcast.internal.serialization.Data) LockSupportService(com.hazelcast.internal.locksupport.LockSupportService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) LockResource(com.hazelcast.internal.locksupport.LockResource) Mockito.anyObject(org.mockito.Mockito.anyObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 2 with LockResource

use of com.hazelcast.internal.locksupport.LockResource in project hazelcast by hazelcast.

the class LocalLockCleanupOperation method run.

@Override
public void run() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    LockResource lock = lockStore.getLock(key);
    if (uuid.equals(lock.getOwner())) {
        ILogger logger = getLogger();
        if (logger.isFinestEnabled()) {
            logger.finest("Unlocking lock owned by UUID: " + uuid + ", thread ID: " + lock.getThreadId() + ", count: " + lock.getLockCount());
        }
        response = lockStore.forceUnlock(key);
    }
}
Also used : LockStoreImpl(com.hazelcast.internal.locksupport.LockStoreImpl) LockResource(com.hazelcast.internal.locksupport.LockResource) ILogger(com.hazelcast.logging.ILogger)

Aggregations

LockResource (com.hazelcast.internal.locksupport.LockResource)2 Config (com.hazelcast.config.Config)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LockStoreImpl (com.hazelcast.internal.locksupport.LockStoreImpl)1 LockSupportService (com.hazelcast.internal.locksupport.LockSupportService)1 Data (com.hazelcast.internal.serialization.Data)1 ILogger (com.hazelcast.logging.ILogger)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 TransactionException (com.hazelcast.transaction.TransactionException)1 TransactionalMap (com.hazelcast.transaction.TransactionalMap)1 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)1 Test (org.junit.Test)1 Mockito.anyObject (org.mockito.Mockito.anyObject)1