use of com.hazelcast.internal.util.BiTuple in project hazelcast by hazelcast.
the class RaftNodeImpl method tryRunQueries.
public boolean tryRunQueries() {
QueryState queryState = state.leaderState().queryState();
if (queryState.queryCount() == 0) {
return false;
}
long commitIndex = state.commitIndex();
if (!queryState.isMajorityAcked(commitIndex, state.majority())) {
return true;
}
Collection<BiTuple<Object, InternalCompletableFuture>> operations = queryState.operations();
if (logger.isFineEnabled()) {
logger.fine("Running " + operations.size() + " queries at commit index: " + commitIndex + ", query round: " + queryState.queryRound());
}
for (BiTuple<Object, InternalCompletableFuture> t : operations) {
runQuery(t.element1, t.element2);
}
queryState.reset();
return false;
}
use of com.hazelcast.internal.util.BiTuple 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.internal.util.BiTuple 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.internal.util.BiTuple in project hazelcast by hazelcast.
the class HazelcastSqlOperatorTableTest method testNoOverride.
/**
* Make sure there are no overrides for operators defined in the operator table.
*/
@Test
public void testNoOverride() {
Map<BiTuple<String, SqlSyntax>, SqlOperator> map = new HashMap<>();
for (SqlOperator operator : HazelcastSqlOperatorTable.instance().getOperatorList()) {
BiTuple<String, SqlSyntax> key = BiTuple.of(operator.getName(), operator.getSyntax());
SqlOperator oldOperator = map.put(key, operator);
assertNull("Duplicate operator \"" + operator.getName(), oldOperator);
}
}
Aggregations