use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testRetriedDrainRequestIsNotProcessedAgain.
@Test(timeout = 300_000)
public void testRetriedDrainRequestIsNotProcessedAgain() throws InterruptedException, ExecutionException {
assumeFalse(isJDKCompatible());
semaphore.init(1);
semaphore.acquire();
final RaftGroupId groupId = getGroupId(semaphore);
long sessionId = getSessionId(proxyInstance, groupId);
long threadId = getThreadId(groupId);
UUID invUid = newUnsecureUUID();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Integer> f1 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
assertEquals(0, (int) f1.joinInternal());
spawn(() -> semaphore.release()).get();
InternalCompletableFuture<Integer> f2 = invocationManager.invoke(groupId, new DrainPermitsOp(objectName, sessionId, threadId, invUid));
assertEquals(0, (int) f2.joinInternal());
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testDrainCancelsPendingAcquireRequestWhenNotAcquired.
@Test(timeout = 300_000)
public void testDrainCancelsPendingAcquireRequestWhenNotAcquired() 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());
});
semaphore.drainPermits();
try {
f.joinInternal();
fail();
} catch (WaitKeyCancelledException ignored) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class AbstractSemaphoreFailureTest method testRetriedAcquireReceivesPermitsOnlyOnce.
@Test(timeout = 300_000)
public void testRetriedAcquireReceivesPermitsOnlyOnce() throws InterruptedException, ExecutionException {
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();
RaftInvocationManager invocationManager = getRaftInvocationManager(proxyInstance);
InternalCompletableFuture<Object> f1 = 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());
});
spawn(() -> {
try {
semaphore.tryAcquire(20, 5, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
assertTrueEventually(() -> {
SemaphoreService service = getNodeEngineImpl(primaryInstance).getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertEquals(2, registry.getWaitTimeouts().size());
});
InternalCompletableFuture<Object> f2 = 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);
Semaphore semaphore = registry.getResourceOrNull(objectName);
assertEquals(2, semaphore.getInternalWaitKeysMap().size());
});
spawn(() -> semaphore.increasePermits(3)).get();
f1.joinInternal();
f2.joinInternal();
assertEquals(2, semaphore.availablePermits());
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class RestCPSubsystemTest method test_reset.
@Test
public void test_reset() throws ExecutionException, InterruptedException, IOException {
HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
Hazelcast.newHazelcastInstance(config);
instance1.getCPSubsystem().getAtomicLong("long1").set(5);
CPGroup cpGroup1 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
sleepAtLeastMillis(10);
ConnectionResponse response = new HTTPCommunicator(instance1).restart(clusterName, null);
assertEquals(200, response.responseCode);
instance1.getCPSubsystem().getAtomicLong("long1").set(5);
CPGroup cpGroup2 = instance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(DEFAULT_GROUP_NAME).toCompletableFuture().get();
RaftGroupId id1 = (RaftGroupId) cpGroup1.id();
RaftGroupId id2 = (RaftGroupId) cpGroup2.id();
assertTrue(id2.getSeed() > id1.getSeed());
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class ClientSessionManagerTest method testClientSessionManagerShutdown.
@Test
public void testClientSessionManagerShutdown() throws ExecutionException, InterruptedException {
AbstractProxySessionManager sessionManager = getSessionManager();
SessionProxyImpl proxy = new SessionProxyImpl(sessionManager, groupId);
proxy.createSession();
Map<RaftGroupId, InternalCompletableFuture<Object>> futures = sessionManager.shutdown();
assertEquals(1, futures.size());
Entry<RaftGroupId, InternalCompletableFuture<Object>> e = futures.entrySet().iterator().next();
assertEquals(groupId, e.getKey());
e.getValue().get();
exception.expect(IllegalStateException.class);
proxy.createSession();
}
Aggregations