use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testNewAcquireCancelsPendingAcquireRequestWhenNotAcquired.
@Test(timeout = 300_000)
public void testNewAcquireCancelsPendingAcquireRequestWhenNotAcquired() 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 invUid1 = newUnsecureUUID();
UUID invUid2 = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Object> f = invocationManager.invoke(groupId, new AcquirePermitsOp(objectName, sessionId, threadId, invUid1, 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());
});
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 testReleaseCancelsPendingAcquireRequestWhenPermitsAcquired.
@Test(timeout = 300_000)
public void testReleaseCancelsPendingAcquireRequestWhenPermitsAcquired() 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);
InternalCompletableFuture<Object> f = 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());
});
try {
semaphore.release();
} catch (IllegalArgumentException ignored) {
}
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class UnsafeSessionMigrationTest method whenPartitionIsMigrated_thenSessionInformationShouldMigrate.
@Test
public void whenPartitionIsMigrated_thenSessionInformationShouldMigrate() {
Config config = new Config();
config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "2");
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
RaftGroupId group1 = getRaftService(hz1).createRaftGroupForProxy(generateName(hz1, 0));
RaftGroupId group2 = getRaftService(hz1).createRaftGroupForProxy(generateName(hz1, 1));
ProxySessionManagerService sessionManager = getSessionManager(hz1);
long session1 = sessionManager.acquireSession(group1);
long session2 = sessionManager.acquireSession(group2);
// Start new instance to trigger migration
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
waitAllForSafeState(hz1, hz2);
// Unlock after lock is migrated
sessionManager.heartbeat(group1, session1).joinInternal();
sessionManager.heartbeat(group2, session2).joinInternal();
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testNewTryAcquireWithoutTimeoutCancelsPendingAcquireRequestWhenAlreadyAcquired.
@Test(timeout = 300_000)
public void testNewTryAcquireWithoutTimeoutCancelsPendingAcquireRequestWhenAlreadyAcquired() 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, 0));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testTryAcquireWithTimeoutCancelsPendingAcquireRequestWhenAlreadyAcquired.
@Test(timeout = 300_000)
public void testTryAcquireWithTimeoutCancelsPendingAcquireRequestWhenAlreadyAcquired() 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, 100));
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
Aggregations