use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testRetriedAcquireDoesNotCancelPendingAcquireRequestWhenAlreadyAcquired.
@Test(timeout = 300_000)
public void testRetriedAcquireDoesNotCancelPendingAcquireRequestWhenAlreadyAcquired() throws InterruptedException {
semaphore.init(1);
semaphore.acquire();
RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid, 1, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid, 1, -1));
assertTrueAllTheTime(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertEquals(1, registry.getWaitTimeouts().size());
}, 10);
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testNewAcquireCancelsPendingAcquireRequestWhenAlreadyAcquired.
@Test(timeout = 300_000)
public void testNewAcquireCancelsPendingAcquireRequestWhenAlreadyAcquired() throws InterruptedException {
semaphore.init(1);
semaphore.acquire();
RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid1 = newUnsecureUUID();
UUID invUid2 = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 1, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertEquals(1, registry.getWaitTimeouts().size());
});
invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid2, 1, -1));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testReleaseCancelsPendingAcquireRequestWhenNoPermitsAcquired.
@Test(timeout = 300_000)
public void testReleaseCancelsPendingAcquireRequestWhenNoPermitsAcquired() throws InterruptedException {
semaphore.init(1);
semaphore.acquire();
semaphore.release();
// if the session-aware semaphore is used, we guarantee that there is a session id now...
RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid, 2, MINUTES.toMillis(5)));
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
assertEquals(1, registry.getWaitTimeouts().size());
});
try {
semaphore.release();
} catch (IllegalStateException ignored) {
}
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class RaftGroupIdConstructorTest method test.
@Test
public void test() {
RaftGroupId original = new RaftGroupId(HazelcastTestSupport.randomString(), -13, 992);
RaftGroupIdConstructor constructor = new RaftGroupIdConstructor(RaftGroupId.class);
RaftGroupId clone = (RaftGroupId) constructor.createNew(original);
assertEquals(original, clone);
}
Aggregations