Search in sources :

Example 1 with InternalLockNamespace

use of com.hazelcast.concurrent.lock.InternalLockNamespace in project hazelcast by hazelcast.

the class ConditionAwaitMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    final Data key = serializationService.toData(parameters.lockName);
    final InternalLockNamespace namespace = new InternalLockNamespace(parameters.lockName);
    return new AwaitOperation(namespace, key, parameters.threadId, parameters.timeout, parameters.name, parameters.referenceId);
}
Also used : InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) AwaitOperation(com.hazelcast.concurrent.lock.operations.AwaitOperation) Data(com.hazelcast.nio.serialization.Data)

Example 2 with InternalLockNamespace

use of com.hazelcast.concurrent.lock.InternalLockNamespace in project hazelcast by hazelcast.

the class ConditionBeforeAwaitMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    final Data key = serializationService.toData(parameters.lockName);
    final InternalLockNamespace namespace = new InternalLockNamespace(parameters.lockName);
    return new BeforeAwaitOperation(namespace, key, parameters.threadId, parameters.name, parameters.referenceId);
}
Also used : InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) BeforeAwaitOperation(com.hazelcast.concurrent.lock.operations.BeforeAwaitOperation) Data(com.hazelcast.nio.serialization.Data)

Example 3 with InternalLockNamespace

use of com.hazelcast.concurrent.lock.InternalLockNamespace in project hazelcast by hazelcast.

the class ConditionSignalMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    final Data key = serializationService.toData(parameters.lockName);
    final InternalLockNamespace namespace = new InternalLockNamespace(parameters.lockName);
    return new SignalOperation(namespace, key, parameters.threadId, parameters.name, false);
}
Also used : InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) SignalOperation(com.hazelcast.concurrent.lock.operations.SignalOperation) Data(com.hazelcast.nio.serialization.Data)

Example 4 with InternalLockNamespace

use of com.hazelcast.concurrent.lock.InternalLockNamespace 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);
    InternalLockNamespace namespace = new InternalLockNamespace(key);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we lock the lock by another thread
    InternalOperationService 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());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with InternalLockNamespace

use of com.hazelcast.concurrent.lock.InternalLockNamespace 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.
    InternalOperationService 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 InternalLockNamespace(key), nodeEngine.toData(key), 1, -1, -1);
    InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, op, partitionId).setCallTimeout(callTimeout).invoke();
    try {
        future.join();
        fail("Invocation should failed with timeout!");
    } catch (OperationTimeoutException expected) {
        ignore(expected);
    }
    IsLockedOperation isLockedOperation = new IsLockedOperation(new InternalLockNamespace(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) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) InternalLockNamespace(com.hazelcast.concurrent.lock.InternalLockNamespace) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)12 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 LockOperation (com.hazelcast.concurrent.lock.operations.LockOperation)7 Config (com.hazelcast.config.Config)7 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 Data (com.hazelcast.nio.serialization.Data)5 UnlockOperation (com.hazelcast.concurrent.lock.operations.UnlockOperation)4 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)4 IsLockedOperation (com.hazelcast.concurrent.lock.operations.IsLockedOperation)3 TimeoutException (java.util.concurrent.TimeoutException)3 SignalOperation (com.hazelcast.concurrent.lock.operations.SignalOperation)2 Operation (com.hazelcast.spi.Operation)2 AssertTask (com.hazelcast.test.AssertTask)2 LockServiceImpl (com.hazelcast.concurrent.lock.LockServiceImpl)1 LockStore (com.hazelcast.concurrent.lock.LockStore)1