Search in sources :

Example 81 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class DistributedObjectTest method testInitialization_whenEachNodeExecutesPostJoinOperations.

@Test
public void testInitialization_whenEachNodeExecutesPostJoinOperations() {
    int nodeCount = 4;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    Config config = new Config();
    config.getServicesConfig().addServiceConfig(new ServiceConfig().setImplementation(new TestInitializingObjectService()).setEnabled(true).setName(TestInitializingObjectService.NAME));
    String serviceName = TestInitializingObjectService.NAME;
    String objectName = "test-object";
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = factory.newHazelcastInstance(config);
        instances[i].getDistributedObject(serviceName, objectName);
    }
    for (int i = 0; i < nodeCount; i++) {
        Node node = TestUtil.getNode(instances[i]);
        ProxyServiceImpl proxyService = (ProxyServiceImpl) node.nodeEngine.getProxyService();
        Operation postJoinOperation = proxyService.getPostJoinOperation();
        for (int j = 0; j < nodeCount; j++) {
            if (i == j)
                continue;
            Node node2 = TestUtil.getNode(instances[j]);
            node.nodeEngine.getOperationService().send(postJoinOperation, node2.address);
        }
    }
    for (HazelcastInstance instance : instances) {
        TestInitializingObject obj = instance.getDistributedObject(serviceName, objectName);
        assertTrue(obj.init.get());
        assertFalse(obj.error);
    }
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 82 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class ClientListenersTest method testEntryMergeListener_withPortableNotRegisteredInNode.

@Test
public void testEntryMergeListener_withPortableNotRegisteredInNode() throws Exception {
    final IMap<Object, Object> map = client.getMap(randomMapName());
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(new EntryMergedListener<Object, Object>() {

        @Override
        public void entryMerged(EntryEvent<Object, Object> event) {
            latch.countDown();
        }
    }, true);
    Node node = getNode(server);
    NodeEngineImpl nodeEngine = node.nodeEngine;
    OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();
    SerializationService serializationService = getSerializationService(server);
    Data key = serializationService.toData(1);
    Data value = serializationService.toData(new ClientRegressionWithMockNetworkTest.SamplePortable(1));
    EntryView entryView = EntryViews.createSimpleEntryView(key, value, Mockito.mock(Record.class));
    MergeOperation op = new MergeOperation(map.getName(), key, entryView, new PassThroughMergePolicy());
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    operationService.invokeOnPartition(MapService.SERVICE_NAME, op, partitionId);
    assertOpenEventually(latch);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) PassThroughMergePolicy(com.hazelcast.map.merge.PassThroughMergePolicy) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) CountDownLatch(java.util.concurrent.CountDownLatch) EntryView(com.hazelcast.core.EntryView) Record(com.hazelcast.map.impl.record.Record) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 83 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class MasterClaimOperation method run.

@Override
public void run() {
    final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    Node node = nodeEngine.getNode();
    Joiner joiner = node.getJoiner();
    final ILogger logger = node.getLogger(getClass().getName());
    if (joiner instanceof TcpIpJoiner) {
        TcpIpJoiner tcpIpJoiner = (TcpIpJoiner) joiner;
        final Address endpoint = getCallerAddress();
        final Address masterAddress = node.getMasterAddress();
        approvedAsMaster = !tcpIpJoiner.isClaimingMaster() && !node.isMaster() && (masterAddress == null || masterAddress.equals(endpoint));
    } else {
        approvedAsMaster = false;
        logger.warning("This node requires MulticastJoin strategy!");
    }
    if (logger.isFineEnabled()) {
        logger.fine("Sending '" + approvedAsMaster + "' for master claim of node: " + getCallerAddress());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) TcpIpJoiner(com.hazelcast.cluster.impl.TcpIpJoiner) Joiner(com.hazelcast.cluster.Joiner) Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) ILogger(com.hazelcast.logging.ILogger) TcpIpJoiner(com.hazelcast.cluster.impl.TcpIpJoiner)

Example 84 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class MemberInfoUpdateOperation method processPartitionState.

final void processPartitionState() {
    if (partitionRuntimeState == null) {
        return;
    }
    partitionRuntimeState.setEndpoint(getCallerAddress());
    ClusterServiceImpl clusterService = getService();
    Node node = clusterService.getNodeEngine().getNode();
    node.partitionService.processPartitionRuntimeState(partitionRuntimeState);
}
Also used : Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Example 85 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class MemberInfoUpdateOperation method checkLocalMemberUuid.

final void checkLocalMemberUuid() {
    ClusterServiceImpl clusterService = getService();
    NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
    Node node = nodeEngine.getNode();
    if (!node.getThisUuid().equals(targetUuid)) {
        String msg = "targetUuid: " + targetUuid + " is different than this node's uuid: " + node.getThisUuid();
        throw new IllegalStateException(msg);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6