use of com.hazelcast.internal.locksupport.operations.LockOperation in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_whenHeartbeatTimeout.
// ============================ heartbeat timeout =============================================================================
//
// ===========================================================================================================================
@Test
public void sync_whenHeartbeatTimeout() {
int callTimeout = 5000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance(config);
HazelcastInstance remote = factory.newHazelcastInstance(config);
warmUpPartitions(factory.getAllHazelcastInstances());
NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
String key = generateKeyOwnedBy(remote);
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
// first we execute an operation that stall the partition.
OperationServiceImpl opService = nodeEngine.getOperationService();
opService.invokeOnPartition(null, new SlowOperation(5 * callTimeout), partitionId);
// then we execute a lock operation that won't be executed because the partition is blocked.
LockOperation op = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), 1, -1, -1);
InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, op, partitionId).setCallTimeout(callTimeout).invoke();
try {
future.joinInternal();
fail("Invocation should failed with timeout!");
} catch (OperationTimeoutException expected) {
ignore(expected);
}
IsLockedOperation isLockedOperation = new IsLockedOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), 1);
Boolean isLocked = (Boolean) opService.createInvocationBuilder(null, isLockedOperation, partitionId).setCallTimeout(10 * callTimeout).invoke().join();
assertFalse(isLocked);
}
use of com.hazelcast.internal.locksupport.operations.LockOperation in project hazelcast by hazelcast.
the class Invocation_BlockingTest method async_whenOperationTimeout.
@Test
public void async_whenOperationTimeout() {
int callTimeout = 5000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance(config);
HazelcastInstance remote = factory.newHazelcastInstance(config);
warmUpPartitions(factory.getAllHazelcastInstances());
NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
String key = generateKeyOwnedBy(remote);
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
// first we lock the lock by another thread
OperationServiceImpl opService = nodeEngine.getOperationService();
int otherThreadId = 2;
opService.invokeOnPartition(new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
// then we execute a lock operation that won't be executed because lock is already acquired
// we are going to do some waiting (3x call timeout)
int threadId = 1;
Operation op = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
final BiConsumer<Object, Throwable> callback = getExecutionCallbackMock();
future.whenCompleteAsync(callback);
assertTrueEventually(() -> verify(callback).accept(Boolean.FALSE, null));
}
use of com.hazelcast.internal.locksupport.operations.LockOperation in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_whenOperationTimeout.
// ====================================================================
//
// ====================================================================
@Test
public void sync_whenOperationTimeout() {
int callTimeout = 5000;
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeout);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance local = factory.newHazelcastInstance(config);
HazelcastInstance remote = factory.newHazelcastInstance(config);
warmUpPartitions(factory.getAllHazelcastInstances());
NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
String key = generateKeyOwnedBy(remote);
ObjectNamespace namespace = new DistributedObjectNamespace(SERVICE_NAME, key);
int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
// first we lock the lock by another thread
OperationServiceImpl opService = nodeEngine.getOperationService();
int otherThreadId = 2;
opService.invokeOnPartition(new LockOperation(namespace, nodeEngine.toData(key), otherThreadId, -1, -1).setPartitionId(partitionId)).join();
// then we execute a lock operation that won't be executed because lock is already acquired
// we are going to do some waiting (3x call timeout)
int threadId = 1;
Operation op = new LockOperation(namespace, nodeEngine.toData(key), threadId, -1, 3 * callTimeout).setPartitionId(partitionId);
final InternalCompletableFuture<Object> future = opService.invokeOnPartition(op);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(future.isDone());
}
});
assertEquals(Boolean.FALSE, future.join());
}
use of com.hazelcast.internal.locksupport.operations.LockOperation in project hazelcast by hazelcast.
the class LockProxySupport method lock.
public void lock(NodeEngine nodeEngine, Data key, long leaseTime) {
leaseTime = getLeaseTime(leaseTime);
LockOperation operation = new LockOperation(namespace, key, getThreadId(), leaseTime, -1);
InternalCompletableFuture<Boolean> f = invoke(nodeEngine, operation, key);
if (!f.joinInternal()) {
throw new IllegalStateException();
}
}
use of com.hazelcast.internal.locksupport.operations.LockOperation in project hazelcast by hazelcast.
the class LockProxySupport method tryLock.
public boolean tryLock(NodeEngine nodeEngine, Data key, long timeout, @Nullable TimeUnit timeunit, long leaseTime, @Nullable TimeUnit leaseTimeunit) throws InterruptedException {
long timeoutInMillis = timeInMsOrTimeIfNullUnit(timeout, timeunit);
long leaseTimeInMillis = timeInMsOrTimeIfNullUnit(leaseTime, leaseTimeunit);
LockOperation operation = new LockOperation(namespace, key, getThreadId(), leaseTimeInMillis, timeoutInMillis);
InternalCompletableFuture<Boolean> f = invoke(nodeEngine, operation, key);
try {
return f.get();
} catch (Throwable t) {
throw rethrowAllowInterrupted(t);
}
}
Aggregations