Search in sources :

Example 16 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.

private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction action) {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    final HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    final HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz2);
    Operation op = new AlwaysBlockingOperation();
    Future<Object> future = getNodeEngineImpl(hz3).getOperationService().invokeOnPartition("", op, partitionId);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            final OperationParkerImpl waitNotifyService3 = (OperationParkerImpl) getNodeEngineImpl(hz2).getOperationParker();
            assertEquals(1, waitNotifyService3.getTotalParkedOperationCount());
        }
    });
    // execute the given split action
    action.run(hz1, hz2, hz3);
    unblock(hz1, hz2, hz3);
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = (ClusterServiceImpl) getClusterService(hz3);
    clusterService3.merge(getAddress(hz1));
    assertClusterSizeEventually(3, hz1, hz2, hz3);
    try {
        future.get(1, TimeUnit.MINUTES);
        fail("Future.get() should fail with a MemberLeftException!");
    } catch (MemberLeftException expected) {
        ignore(expected);
    } catch (Exception e) {
        fail(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : Config(com.hazelcast.config.Config) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) BlockingOperation(com.hazelcast.spi.impl.operationservice.BlockingOperation) 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 17 with MemberLeftException

use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.

the class Invocation_OnMemberLeftTest method whenMemberRestarts.

private void whenMemberRestarts(Runnable restartAction) throws Exception {
    Future<Object> futureBeforeShutdown = localOperationService.invokeOnTarget(null, new UnresponsiveTargetOperation(), remoteMember.getAddress());
    final CountDownLatch blockMonitorLatch = new CountDownLatch(1);
    final CountDownLatch resumeMonitorLatch = new CountDownLatch(1);
    localInvocationMonitor.execute(() -> {
        blockMonitorLatch.countDown();
        assertOpenEventually(resumeMonitorLatch);
    });
    assertOpenEventually(blockMonitorLatch);
    // Unresponsive operation should be executed before shutting down the node
    assertUnresponsiveOperationStarted();
    remote.getLifecycleService().terminate();
    restartAction.run();
    assertTrue(remote.getLifecycleService().isRunning());
    Future<Object> futureAfterRestart = localOperationService.invokeOnTarget(null, new UnresponsiveTargetOperation(), remoteMember.getAddress());
    resumeMonitorLatch.countDown();
    try {
        futureBeforeShutdown.get();
        fail("Invocation should have failed with MemberLeftException!");
    } catch (MemberLeftException e) {
        ignore(e);
    }
    try {
        futureAfterRestart.get(1, TimeUnit.SECONDS);
        fail("future.get() should have failed with TimeoutException!");
    } catch (TimeoutException e) {
        ignore(e);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MemberLeftException(com.hazelcast.core.MemberLeftException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

MemberLeftException (com.hazelcast.core.MemberLeftException)17 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)8 Member (com.hazelcast.cluster.Member)4 ExecutionException (java.util.concurrent.ExecutionException)4 Test (org.junit.Test)4 Address (com.hazelcast.cluster.Address)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 ArrayList (java.util.ArrayList)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 Config (com.hazelcast.config.Config)2 Member (com.hazelcast.core.Member)2 SimpleMemberImpl (com.hazelcast.instance.SimpleMemberImpl)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 Data (com.hazelcast.internal.serialization.Data)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 SerializableList (com.hazelcast.spi.impl.SerializableList)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 AssertTask (com.hazelcast.test.AssertTask)2