use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class AbstractFencedLockFailureTest method testRetriedWaitKeysAreExpiredTogether.
@Test(timeout = 300_000)
public void testRetriedWaitKeysAreExpiredTogether() {
CountDownLatch releaseLatch = new CountDownLatch(1);
spawn(() -> {
lock.lock();
assertOpenEventually(releaseLatch);
lock.unlock();
});
assertTrueEventually(() -> assertTrue(lock.isLocked()));
// there is a session id now
RaftGroupId groupId = lock.getGroupId();
long sessionId = getSessionManager().getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
RaftInvocationManager invocationManager = getRaftInvocationManager();
UUID invUid = newUnsecureUUID();
BiTuple[] lockWaitTimeoutKeyRef = new BiTuple[1];
InternalCompletableFuture<Long> f1 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
LockService service = nodeEngine.getService(LockService.SERVICE_NAME);
assertTrueEventually(() -> {
LockRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
assertEquals(1, waitTimeouts.size());
lockWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
});
InternalCompletableFuture<Long> f2 = invocationManager.invoke(groupId, new TryLockOp(objectName, sessionId, getThreadId(), invUid, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
RaftService raftService = nodeEngine.getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
LockRegistry registry = service.getRegistryOrNull(groupId);
boolean[] verified = new boolean[1];
CountDownLatch latch = new CountDownLatch(1);
OperationServiceImpl operationService = nodeEngine.getOperationService();
operationService.execute(new PartitionSpecificRunnable() {
@Override
public int getPartitionId() {
return partitionId;
}
@Override
public void run() {
Lock lock = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<LockInvocationKey>> waitKeys = lock.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
assertOpenEventually(latch);
assertTrue(verified[0]);
});
RaftOp op = new ExpireWaitKeysOp(LockService.SERVICE_NAME, Collections.singletonList(lockWaitTimeoutKeyRef[0]));
invocationManager.invoke(groupId, op).joinInternal();
assertTrueEventually(() -> assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty()));
releaseLatch.countDown();
assertTrueEventually(() -> assertFalse(lock.isLocked()));
long fence1 = f1.joinInternal();
long fence2 = f2.joinInternal();
assertInvalidFence(fence1);
assertInvalidFence(fence2);
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class AbstractSemaphoreAdvancedTest method testRetriedWaitKeysAreExpiredTogether.
@Test
public void testRetriedWaitKeysAreExpiredTogether() {
semaphore.init(1);
CountDownLatch releaseLatch = new CountDownLatch(1);
spawn(() -> {
try {
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
assertOpenEventually(releaseLatch);
semaphore.release();
});
assertTrueEventually(() -> assertEquals(0, semaphore.availablePermits()));
// there is a session id now
RaftGroupId groupId = getGroupId();
AbstractProxySessionManager sessionManager = getSessionManager();
long sessionId = sessionManager.getSession(groupId);
assertNotEquals(NO_SESSION_ID, sessionId);
UUID invUid = newUnsecureUUID();
BiTuple[] acquireWaitTimeoutKeyRef = new BiTuple[1];
InternalCompletableFuture<Boolean> f1 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
assertNotNull(registry);
Map<BiTuple<String, UUID>, BiTuple<Long, Long>> waitTimeouts = registry.getWaitTimeouts();
assertEquals(1, waitTimeouts.size());
acquireWaitTimeoutKeyRef[0] = waitTimeouts.keySet().iterator().next();
});
InternalCompletableFuture<Boolean> f2 = invokeRaftOp(groupId, new AcquirePermitsOp(objectName, sessionId, getThreadId(), invUid, 1, SECONDS.toMillis(300)));
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
RaftService raftService = getNodeEngineImpl(primaryInstance).getService(RaftService.SERVICE_NAME);
int partitionId = raftService.getCPGroupPartitionId(groupId);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
boolean[] verified = new boolean[1];
CountDownLatch latch = new CountDownLatch(1);
OperationServiceImpl operationService = nodeEngine.getOperationService();
operationService.execute(new PartitionSpecificRunnable() {
@Override
public int getPartitionId() {
return partitionId;
}
@Override
public void run() {
Semaphore semaphore = registry.getResourceOrNull(objectName);
Map<Object, WaitKeyContainer<AcquireInvocationKey>> waitKeys = semaphore.getInternalWaitKeysMap();
verified[0] = (waitKeys.size() == 1 && waitKeys.values().iterator().next().retryCount() == 1);
latch.countDown();
}
});
assertOpenEventually(latch);
assertTrue(verified[0]);
});
RaftOp op = new ExpireWaitKeysOp(SemaphoreService.SERVICE_NAME, Collections.singletonList(acquireWaitTimeoutKeyRef[0]));
invokeRaftOp(groupId, op).joinInternal();
assertTrueEventually(() -> {
NodeEngineImpl nodeEngine = getNodeEngineImpl(primaryInstance);
SemaphoreService service = nodeEngine.getService(SemaphoreService.SERVICE_NAME);
assertTrue(service.getRegistryOrNull(groupId).getWaitTimeouts().isEmpty());
});
releaseLatch.countDown();
assertTrueEventually(() -> assertEquals(1, semaphore.availablePermits()));
assertFalse(f1.joinInternal());
assertFalse(f2.joinInternal());
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class FrozenPartitionTableTest method partitionTable_shouldBeFixed_whenMemberRestarts_usingNewUuid.
@Test
public void partitionTable_shouldBeFixed_whenMemberRestarts_usingNewUuid() {
ruleStaleJoinPreventionDuration.setOrClearProperty("5");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
HazelcastInstance hz3 = factory.newHazelcastInstance();
assertClusterSizeEventually(3, hz2, hz3);
warmUpPartitions(hz1, hz2, hz3);
changeClusterStateEventually(hz3, ClusterState.FROZEN);
int member3PartitionId = getPartitionId(hz3);
MemberImpl member3 = getNode(hz3).getLocalMember();
hz3.shutdown();
assertClusterSizeEventually(2, hz1, hz2);
hz3 = newHazelcastInstance(initOrCreateConfig(new Config()), randomName(), new StaticMemberNodeContext(factory, newUnsecureUUID(), member3.getAddress()));
assertClusterSizeEventually(3, hz1, hz2);
waitAllForSafeState(hz1, hz2, hz3);
OperationServiceImpl operationService = getOperationService(hz1);
operationService.invokeOnPartition(null, new NonRetryablePartitionOperation(), member3PartitionId).join();
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class PromoteLiteMemberTest method assertPromotionInvocationStarted.
private void assertPromotionInvocationStarted(HazelcastInstance instance) {
OperationServiceImpl operationService = getNode(instance).getNodeEngine().getOperationService();
InvocationRegistry invocationRegistry = operationService.getInvocationRegistry();
assertTrueEventually(() -> {
for (Map.Entry<Long, Invocation> entry : invocationRegistry.entrySet()) {
if (entry.getValue().op instanceof PromoteLiteMemberOp) {
return;
}
}
fail("Cannot find PromoteLiteMemberOp invocation!");
});
}
use of com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl in project hazelcast by hazelcast.
the class AdvancedClusterStateTest method invocationShouldComplete_whenMemberReJoins_inFrozenState.
@Test
public void invocationShouldComplete_whenMemberReJoins_inFrozenState() throws Exception {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance[] instances = factory.newInstances(config);
HazelcastInstance hz1 = instances[0];
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
warmUpPartitions(instances);
waitAllForSafeState(instances);
Address owner = getNode(hz1).getThisAddress();
String key = generateKeyOwnedBy(hz1);
int partitionId = hz1.getPartitionService().getPartition(key).getPartitionId();
changeClusterStateEventually(hz2, ClusterState.FROZEN);
terminateInstance(hz1);
OperationServiceImpl operationService = getNode(hz3).getNodeEngine().getOperationService();
Operation op = new AddAndGetOperation(key, 1);
Future<Long> future = operationService.invokeOnPartition(LongRegisterService.SERVICE_NAME, op, partitionId);
assertFalse(future.isDone());
factory.newHazelcastInstance(owner);
assertClusterSizeEventually(3, hz2);
assertTrueEventually(() -> assertTrue(future.isDone()));
// should not fail
future.get();
}
Aggregations