Search in sources :

Example 1 with LockResource

use of com.hazelcast.concurrent.lock.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;
        }
    });
    Node node = TestUtil.getNode(instance1);
    Data keyData = node.nodeEngine.toData(keyOwnedByInstance2);
    LockService lockService = node.nodeEngine.getService(LockService.SERVICE_NAME);
    for (LockResource lockResource : lockService.getAllLocks()) {
        if (keyData.equals(lockResource.getKey())) {
            assertEquals(0, lockResource.getLockCount());
        }
    }
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) LockService(com.hazelcast.concurrent.lock.LockService) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) LockResource(com.hazelcast.concurrent.lock.LockResource) Mockito.anyObject(org.mockito.Mockito.anyObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with LockResource

use of com.hazelcast.concurrent.lock.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.concurrent.lock.LockStoreImpl) LockResource(com.hazelcast.concurrent.lock.LockResource) ILogger(com.hazelcast.logging.ILogger)

Aggregations

LockResource (com.hazelcast.concurrent.lock.LockResource)2 LockService (com.hazelcast.concurrent.lock.LockService)1 LockStoreImpl (com.hazelcast.concurrent.lock.LockStoreImpl)1 Config (com.hazelcast.config.Config)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 TransactionalMap (com.hazelcast.core.TransactionalMap)1 Node (com.hazelcast.instance.Node)1 ILogger (com.hazelcast.logging.ILogger)1 Data (com.hazelcast.nio.serialization.Data)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 TransactionException (com.hazelcast.transaction.TransactionException)1 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)1 Test (org.junit.Test)1 Mockito.anyObject (org.mockito.Mockito.anyObject)1