Search in sources :

Example 1 with TryLockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testPendingLockAcquireRetry.

@Test(timeout = 300_000)
public void testPendingLockAcquireRetry() {
    CountDownLatch unlockLatch = new CountDownLatch(1);
    spawn(() -> {
        lock.lock();
        assertOpenEventually(unlockLatch);
        lock.unlock();
    });
    assertTrueEventually(() -> assertTrue(lock.isLocked()));
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    assertNotEquals(NO_SESSION_ID, sessionId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertFalse(registry.getWaitTimeouts().isEmpty());
    });
    unlockLatch.countDown();
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
        assertTrue(lock.isLocked());
    });
    InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    long fence1 = f1.joinInternal();
    long fence2 = f2.joinInternal();
    assertEquals(fence1, lock.getFence());
    assertEquals(fence1, fence2);
    assertEquals(1, lock.getLockCount());
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) CountDownLatch(java.util.concurrent.CountDownLatch) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with TryLockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testRetriedTryLockWithoutTimeoutDoesNotCancelPendingLockRequest.

@Test(timeout = 300_000)
public void testRetriedTryLockWithoutTimeoutDoesNotCancelPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, 0));
    assertTrueAllTheTime(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertEquals(1, registry.getWaitTimeouts().size());
    }, 10);
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with TryLockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testNewLockCancelsPendingLockRequest.

@Test(timeout = 300_000)
public void testNewLockCancelsPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid1 = newUnsecureUUID();
    UUID invUid2 = newUnsecureUUID();
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid1, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    invocationManager.invoke(groupId, new LockOp(objectName, sessionId, getThreadId(), invUid2));
    try {
        f.joinInternal();
        fail();
    } catch (WaitKeyCancelledException ignored) {
    }
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) LockOp(com.hazelcast.cp.internal.datastructures.lock.operation.LockOp) TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with TryLockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.

the class AbstractFencedLockFailureTest method testNewUnlockCancelsPendingLockRequest.

@Test(timeout = 300_000)
public void testNewUnlockCancelsPendingLockRequest() {
    lockByOtherThread();
    // there is a session id now
    RaftGroupId groupId = lock.getGroupId();
    long sessionId = getSessionManager().getSession(groupId);
    RaftInvocationManager invocationManager = getRaftInvocationManager();
    UUID invUid = newUnsecureUUID();
    InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, MINUTES.toMillis(5)));
    assertTrueEventually(() -> {
        LockService service = getNodeEngineImpl(primaryInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertEquals(1, registry.getWaitTimeouts().size());
    });
    try {
        lock.unlock();
        fail();
    } catch (IllegalMonitorStateException ignored) {
    }
    try {
        f.joinInternal();
        fail();
    } catch (WaitKeyCancelledException ignored) {
    }
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) WaitKeyCancelledException(com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with TryLockOp

use of com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp in project hazelcast by hazelcast.

the class TryLockMessageTask method processMessage.

@Override
protected void processMessage() {
    RaftOp op = new TryLockOp(parameters.name, parameters.sessionId, parameters.threadId, parameters.invocationUid, parameters.timeoutMs);
    invoke(parameters.groupId, op);
}
Also used : TryLockOp(com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp) RaftOp(com.hazelcast.cp.internal.RaftOp)

Aggregations

TryLockOp (com.hazelcast.cp.internal.datastructures.lock.operation.TryLockOp)10 RaftGroupId (com.hazelcast.cp.internal.RaftGroupId)9 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)9 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)9 UUID (java.util.UUID)9 Test (org.junit.Test)9 CountDownLatch (java.util.concurrent.CountDownLatch)4 WaitKeyCancelledException (com.hazelcast.cp.internal.datastructures.exception.WaitKeyCancelledException)3 RaftOp (com.hazelcast.cp.internal.RaftOp)2 RaftService (com.hazelcast.cp.internal.RaftService)2 LockOp (com.hazelcast.cp.internal.datastructures.lock.operation.LockOp)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 PartitionSpecificRunnable (com.hazelcast.spi.impl.PartitionSpecificRunnable)2 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2 Map (java.util.Map)2 ExpireWaitKeysOp (com.hazelcast.cp.internal.datastructures.spi.blocking.operation.ExpireWaitKeysOp)1 BiTuple (com.hazelcast.internal.util.BiTuple)1