Search in sources :

Example 21 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class ClusterInfoTest method all_nodes_should_have_the_same_cluster_start_time_and_cluster_id.

@Test
public void all_nodes_should_have_the_same_cluster_start_time_and_cluster_id() throws Exception {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    HazelcastInstance h2 = factory.newHazelcastInstance();
    HazelcastInstance h3 = factory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    Node node1 = TestUtil.getNode(h1);
    Node node2 = TestUtil.getNode(h2);
    Node node3 = TestUtil.getNode(h3);
    //All nodes should have same startTime
    final ClusterServiceImpl clusterService = node1.getClusterService();
    long node1ClusterStartTime = clusterService.getClusterClock().getClusterStartTime();
    long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    String node1ClusterId = clusterService.getClusterId();
    assertTrue(clusterUpTime > 0);
    assertNotEquals(node1ClusterStartTime, Long.MIN_VALUE);
    assertEquals(node1ClusterStartTime, node2.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node3.getClusterService().getClusterClock().getClusterStartTime());
    //All nodes should have same clusterId
    assertNotNull(node1ClusterId);
    assertEquals(node1ClusterId, node2.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node3.getClusterService().getClusterId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class ClusterInfoTest method all_nodes_should_have_the_same_cluster_start_time_and_id_after_master_shutdown_and_new_node_join.

@Test
public void all_nodes_should_have_the_same_cluster_start_time_and_id_after_master_shutdown_and_new_node_join() {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    HazelcastInstance h2 = factory.newHazelcastInstance();
    HazelcastInstance h3 = factory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    Node node1 = TestUtil.getNode(h1);
    final ClusterServiceImpl clusterService = node1.getClusterService();
    long node1ClusterStartTime = clusterService.getClusterClock().getClusterStartTime();
    long clusterUpTime = clusterService.getClusterClock().getClusterUpTime();
    String node1ClusterId = clusterService.getClusterId();
    assertTrue(clusterUpTime > 0);
    assertTrue(node1.isMaster());
    h1.shutdown();
    assertClusterSizeEventually(2, h2);
    HazelcastInstance h4 = factory.newHazelcastInstance();
    Node node2 = TestUtil.getNode(h2);
    Node node3 = TestUtil.getNode(h3);
    Node node4 = TestUtil.getNode(h4);
    //All nodes should have the same cluster start time
    assertNotEquals(node1ClusterStartTime, Long.MIN_VALUE);
    assertEquals(node1ClusterStartTime, node2.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node3.getClusterService().getClusterClock().getClusterStartTime());
    assertEquals(node1ClusterStartTime, node4.getClusterService().getClusterClock().getClusterStartTime());
    //All nodes should have the same clusterId
    assertEquals(node1ClusterId, node2.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node3.getClusterService().getClusterId());
    assertEquals(node1ClusterId, node4.getClusterService().getClusterId());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class LiteMemberJoinTest method reconnect.

private void reconnect(final HazelcastInstance instance1, final HazelcastInstance instance2) {
    final Node node1 = getNode(instance1);
    final Node node2 = getNode(instance2);
    final ClusterServiceImpl clusterService = node1.getClusterService();
    clusterService.merge(node2.address);
}
Also used : Node(com.hazelcast.instance.Node) HazelcastTestSupport.getNode(com.hazelcast.test.HazelcastTestSupport.getNode) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 24 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.

private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz2);
    NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
    OperationService operationService3 = nodeEngine3.getOperationService();
    Operation op = new AlwaysBlockingOperation();
    Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
    // just wait a little to make sure
    // operation is landed on wait-queue
    sleepSeconds(1);
    // execute the given split action
    splitAction.run(node1, node2, node3);
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    try {
        future.get(1, TimeUnit.MINUTES);
        fail("Future.get() should fail with a MemberLeftException!");
    } catch (MemberLeftException e) {
        // expected
        EmptyStatement.ignore(e);
    } catch (Exception e) {
        fail(e.getClass().getName() + ": " + e.getMessage());
    }
}
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) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 25 with ClusterServiceImpl

use of com.hazelcast.internal.cluster.impl.ClusterServiceImpl in project hazelcast by hazelcast.

the class HeartbeatOperation method run.

@Override
public void run() {
    ClusterServiceImpl service = getService();
    MemberImpl member = service.getMember(getCallerAddress());
    if (member == null) {
        ILogger logger = getLogger();
        if (logger.isFineEnabled()) {
            logger.fine("Heartbeat received from an unknown endpoint: " + getCallerAddress());
        }
        return;
    }
    service.getClusterHeartbeatManager().onHeartbeat(member, timestamp);
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ILogger(com.hazelcast.logging.ILogger)

Aggregations

ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)41 Node (com.hazelcast.instance.Node)13 Address (com.hazelcast.nio.Address)13 ILogger (com.hazelcast.logging.ILogger)9 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 ClusterState (com.hazelcast.cluster.ClusterState)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 OperationService (com.hazelcast.spi.OperationService)4 Member (com.hazelcast.core.Member)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 ClusterStateManager (com.hazelcast.internal.cluster.impl.ClusterStateManager)3 Config (com.hazelcast.config.Config)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 Connection (com.hazelcast.nio.Connection)2 Operation (com.hazelcast.spi.Operation)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2