Search in sources :

Example 1 with IsLockedOperation

use of com.hazelcast.internal.locksupport.operations.IsLockedOperation 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);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) IsLockedOperation(com.hazelcast.internal.locksupport.operations.IsLockedOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with IsLockedOperation

use of com.hazelcast.internal.locksupport.operations.IsLockedOperation in project hazelcast by hazelcast.

the class LockProxySupport method isLocked.

public boolean isLocked(NodeEngine nodeEngine, Data key) {
    IsLockedOperation operation = new IsLockedOperation(namespace, key);
    InternalCompletableFuture<Boolean> f = invoke(nodeEngine, operation, key);
    return f.joinInternal();
}
Also used : IsLockedOperation(com.hazelcast.internal.locksupport.operations.IsLockedOperation)

Aggregations

IsLockedOperation (com.hazelcast.internal.locksupport.operations.IsLockedOperation)2 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)1 LockOperation (com.hazelcast.internal.locksupport.operations.LockOperation)1 DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1