use of com.hazelcast.cp.internal.RaftGroupId 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) {
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class CountDownLatchService method createProxy.
@Override
public ICountDownLatch createProxy(String proxyName) {
try {
proxyName = withoutDefaultGroupName(proxyName);
RaftService service = nodeEngine.getService(RaftService.SERVICE_NAME);
RaftGroupId groupId = service.createRaftGroupForProxy(proxyName);
return new CountDownLatchProxy(nodeEngine, groupId, proxyName, getObjectNameForProxy(proxyName));
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class SemaphoreService method createProxy.
@Override
public ISemaphore createProxy(String proxyName) {
try {
proxyName = withoutDefaultGroupName(proxyName);
RaftGroupId groupId = raftService.createRaftGroupForProxy(proxyName);
String objectName = getObjectNameForProxy(proxyName);
SemaphoreConfig config = getConfig(proxyName);
return config != null && config.isJDKCompatible() ? new SessionlessSemaphoreProxy(nodeEngine, groupId, proxyName, objectName) : new SessionAwareSemaphoreProxy(nodeEngine, groupId, proxyName, objectName);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class ClientProxySessionManager method shutdownAndAwait.
public void shutdownAndAwait() {
Map<RaftGroupId, InternalCompletableFuture<Object>> futures = super.shutdown();
ILogger logger = client.getLoggingService().getLogger(getClass());
long remainingTimeNanos = TimeUnit.SECONDS.toNanos(SHUTDOWN_TIMEOUT_SECONDS);
while (remainingTimeNanos > 0) {
int closed = 0;
for (Entry<RaftGroupId, InternalCompletableFuture<Object>> entry : futures.entrySet()) {
CPGroupId groupId = entry.getKey();
InternalCompletableFuture<Object> f = entry.getValue();
if (f.isDone()) {
closed++;
try {
f.get();
logger.fine("Session closed for " + groupId);
} catch (Exception e) {
logger.warning("Close session failed for " + groupId, e);
}
}
}
if (closed == futures.size()) {
break;
}
try {
Thread.sleep(SHUTDOWN_WAIT_SLEEP_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
remainingTimeNanos -= MILLISECONDS.toNanos(SHUTDOWN_WAIT_SLEEP_MILLIS);
}
}
use of com.hazelcast.cp.internal.RaftGroupId in project hazelcast by hazelcast.
the class RaftInvocationManagerAnswer method answer.
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String methodName = invocation.getMethod().getName();
Object[] arguments = invocation.getArguments();
Class[] argumentClasses = new Class[arguments.length];
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof RaftOp) {
// transfer the operation to the delegateClassloader via (de)serialization
Object dataOperation = serializationService.toData(arguments[i]);
Object delegateDataOperation = proxyObjectForStarter(delegateClassloader, dataOperation);
Object delegateOperation = delegateToObjectMethod.invoke(delegateSerializationService, delegateDataOperation);
arguments[i] = delegateOperationClass.cast(delegateOperation);
argumentClasses[i] = delegateOperationClass;
} else if (arguments[i] instanceof Integer) {
argumentClasses[i] = Integer.TYPE;
} else if (arguments[i] instanceof RaftGroupId) {
argumentClasses[i] = delegateCPGroupIdClass;
} else if (arguments[i] instanceof QueryPolicy) {
argumentClasses[i] = delegateQueryPolicyClass;
} else {
argumentClasses[i] = arguments[i].getClass();
}
}
Method delegateMethod = getDelegateMethod(methodName, argumentClasses);
Object[] proxiedArguments = proxyArgumentsIfNeeded(arguments, delegateClassloader);
Object result = invoke(false, delegateMethod, proxiedArguments);
if (invocation.getMethod().getName().equals("invoke")) {
return mock(invocation.getMethod().getReturnType(), new DelegatingAnswer(result));
} else {
return proxyObjectForStarter(targetClassloader, result);
}
}
Aggregations