Search in sources :

Example 21 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class PartitionLostListenerTest method test_partitionLostListenerInvoked.

@Test
public void test_partitionLostListenerInvoked() {
    HazelcastInstance instance = instances[0];
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    instance.getPartitionService().addPartitionLostListener(listener);
    final IPartitionLostEvent internalEvent = new IPartitionLostEvent(1, 0, null);
    NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
    InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
    partitionService.onPartitionLost(internalEvent);
    assertEventEventually(listener, internalEvent);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitNotifyService_whenNodeSplitFromCluster.

private void testWaitNotifyService_whenNodeSplitFromCluster(SplitAction action) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    final Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz3);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    OperationService operationService1 = nodeEngine1.getOperationService();
    operationService1.invokeOnPartition("", new AlwaysBlockingOperation(), partitionId);
    final OperationParkerImpl waitNotifyService3 = (OperationParkerImpl) node3.getNodeEngine().getOperationParker();
    assertEqualsEventually(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return waitNotifyService3.getTotalParkedOperationCount();
        }
    }, 1);
    action.run(node1, node2, node3);
    // create a new node to prevent same partition assignments
    // after node3 rejoins
    factory.newHazelcastInstance(config);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Assert.assertEquals(0, node1.partitionService.getMigrationQueueSize());
        }
    });
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertEquals(4, node1.getClusterService().getSize());
    assertEquals(4, node2.getClusterService().getSize());
    assertEquals(4, node3.getClusterService().getSize());
    assertEquals(0, waitNotifyService3.getTotalParkedOperationCount());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) OperationParkerImpl(com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 23 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl in project hazelcast by hazelcast.

the class Invocation_RetryTest method testNoStuckInvocationsWhenRetriedMultipleTimes.

@Test
public void testNoStuckInvocationsWhenRetriedMultipleTimes() throws Exception {
    Config config = new Config();
    config.setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    NodeEngineImpl localNodeEngine = getNodeEngineImpl(local);
    NodeEngineImpl remoteNodeEngine = getNodeEngineImpl(remote);
    final OperationServiceImpl operationService = (OperationServiceImpl) localNodeEngine.getOperationService();
    NonResponsiveOperation op = new NonResponsiveOperation();
    op.setValidateTarget(false);
    op.setPartitionId(1);
    InvocationFuture future = (InvocationFuture) operationService.invokeOnTarget(null, op, remoteNodeEngine.getThisAddress());
    Field invocationField = InvocationFuture.class.getDeclaredField("invocation");
    invocationField.setAccessible(true);
    Invocation invocation = (Invocation) invocationField.get(future);
    invocation.notifyError(new RetryableHazelcastException());
    invocation.notifyError(new RetryableHazelcastException());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Iterator<Invocation> invocations = operationService.invocationRegistry.iterator();
            assertFalse(invocations.hasNext());
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) TimeoutException(java.util.concurrent.TimeoutException) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Iterator(java.util.Iterator) 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 24 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl 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 25 with NodeEngineImpl

use of com.hazelcast.spi.impl.NodeEngineImpl 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

NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)112 HazelcastInstance (com.hazelcast.core.HazelcastInstance)39 Test (org.junit.Test)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)31 QuickTest (com.hazelcast.test.annotation.QuickTest)31 Node (com.hazelcast.instance.Node)21 MapService (com.hazelcast.map.impl.MapService)20 Config (com.hazelcast.config.Config)19 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)16 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)14 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)14 ILogger (com.hazelcast.logging.ILogger)11 AssertTask (com.hazelcast.test.AssertTask)11 Invalidator (com.hazelcast.internal.nearcache.impl.invalidation.Invalidator)10 MapNearCacheManager (com.hazelcast.map.impl.nearcache.MapNearCacheManager)10 Address (com.hazelcast.nio.Address)10 Data (com.hazelcast.nio.serialization.Data)10 Before (org.junit.Before)10 Operation (com.hazelcast.spi.Operation)9