Package com.hazelcast.instance

Examples of com.hazelcast.instance.Node


    protected boolean isInstanceNotActive(HazelcastInstance hz) {
        if (hz == null) {
            return true;
        }
        Node node = TestUtil.getNode(hz);
        if (node == null) {
            return true;
        } else {
            return !node.isActive();
        }
    }
View Full Code Here


        String className = value == null ? "null" : value.getClass().getName();
        return className + "<" + valueString + ">";
    }

    public static boolean isInstanceInSafeState(final HazelcastInstance instance) {
        final Node node = TestUtil.getNode(instance);
        if (node != null) {
            final InternalPartitionService ps = node.getPartitionService();
            return ps.isMemberStateSafe();
        }
        else {
            return true;
        }
View Full Code Here

        remote = instances[1];
    }

    @Test
    public void invocationToLocalMember() throws ExecutionException, InterruptedException {
        Node localNode = getNode(local);

        Data response = localNode.nodeEngine.toData(new DummyObject());
        Operation op = new OperationWithResponse(response);

        OperationService service = localNode.nodeEngine.getOperationService();
View Full Code Here

        assertNotSame(instance2, response);
    }

    @Test
    public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
        Node localNode = getNode(local);

        Data response = localNode.nodeEngine.toData(new DummyObject());
        Operation op = new OperationWithResponse(response);

        Address remoteAddress = getNode(remote).address;
View Full Code Here

        assertEquals(3, h3.getCluster().getMembers().size());
    }

    private void closeConnectionBetween(HazelcastInstance h1, HazelcastInstance h2) {
        if (h1 == null || h2 == null) return;
        final Node n1 = TestUtil.getNode(h1);
        final Node n2 = TestUtil.getNode(h2);
        n1.clusterService.removeAddress(n2.address);
        n2.clusterService.removeAddress(n1.address);
    }
View Full Code Here

        HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
        HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
        HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());

        final Node n1 = TestUtil.getNode(hz1);
        Node n2 = TestUtil.getNode(hz2);
        Node n3 = TestUtil.getNode(hz3);

        final CountDownLatch splitLatch = new CountDownLatch(2);
        MembershipAdapter membershipAdapter = new MembershipAdapter() {
            @Override
            public void memberRemoved(MembershipEvent event) {
                if (n1.getLocalMember().equals(event.getMember())) {
                    splitLatch.countDown();
                }
            }
        };

        hz2.getCluster().addMembershipListener(membershipAdapter);
        hz3.getCluster().addMembershipListener(membershipAdapter);

        final CountDownLatch mergeLatch = new CountDownLatch(2);
        LifecycleListener lifecycleListener = new LifecycleListener() {
            @Override
            public void stateChanged(LifecycleEvent event) {
                if (event.getState() == LifecycleState.MERGED) {
                    mergeLatch.countDown();
                }
            }
        };
        hz2.getLifecycleService().addLifecycleListener(lifecycleListener);
        hz3.getLifecycleService().addLifecycleListener(lifecycleListener);

        FirewallingTcpIpConnectionManager cm1 = getConnectionManager(hz1);
        FirewallingTcpIpConnectionManager cm2 = getConnectionManager(hz2);
        FirewallingTcpIpConnectionManager cm3 = getConnectionManager(hz3);

        // block n2 & n3 on n1
        cm1.block(n2.address);
        cm1.block(n3.address);

        // remove and block n1 on n2 & n3
        n2.clusterService.removeAddress(n1.address);
        n3.clusterService.removeAddress(n1.address);
        cm2.block(n1.address);
        cm3.block(n1.address);

        assertTrue(splitLatch.await(120, TimeUnit.SECONDS));
        assertEquals(3, hz1.getCluster().getMembers().size());
        assertEquals(2, hz2.getCluster().getMembers().size());
        assertEquals(2, hz3.getCluster().getMembers().size());

        // unblock n2 on n1 and n1 on n2 & n3
        // n1 still blocks access to n3
        cm1.unblock(n2.address);
        cm2.unblock(n1.address);
        cm3.unblock(n1.address);

        assertTrue(mergeLatch.await(120, TimeUnit.SECONDS));
        assertEquals(3, hz1.getCluster().getMembers().size());
        assertEquals(3, hz2.getCluster().getMembers().size());
        assertEquals(3, hz3.getCluster().getMembers().size());

        assertEquals(n1.getThisAddress(), n1.getMasterAddress());
        assertEquals(n1.getThisAddress(), n2.getMasterAddress());
        assertEquals(n1.getThisAddress(), n3.getMasterAddress());
    }
View Full Code Here

        HazelcastInstance hz1 = newHazelcastInstance(config, "test-node1", new FirewallingNodeContext());
        HazelcastInstance hz2 = newHazelcastInstance(config, "test-node2", new FirewallingNodeContext());
        HazelcastInstance hz3 = newHazelcastInstance(config, "test-node3", new FirewallingNodeContext());

        Node n1 = TestUtil.getNode(hz1);
        Node n2 = TestUtil.getNode(hz2);
        final Node n3 = TestUtil.getNode(hz3);

        final CountDownLatch splitLatch = new CountDownLatch(2);
        MembershipAdapter membershipAdapter = new MembershipAdapter() {
            @Override
            public void memberRemoved(MembershipEvent event) {
                if (n3.getLocalMember().equals(event.getMember())) {
                    splitLatch.countDown();
                }
            }
        };

        hz1.getCluster().addMembershipListener(membershipAdapter);
        hz2.getCluster().addMembershipListener(membershipAdapter);

        final CountDownLatch mergeLatch = new CountDownLatch(2);
        LifecycleListener lifecycleListener = new LifecycleListener() {
            @Override
            public void stateChanged(LifecycleEvent event) {
                if (event.getState() == LifecycleState.MERGED) {
                    mergeLatch.countDown();
                }
            }
        };
        hz1.getLifecycleService().addLifecycleListener(lifecycleListener);
        hz2.getLifecycleService().addLifecycleListener(lifecycleListener);

        FirewallingTcpIpConnectionManager cm1 = getConnectionManager(hz1);
        FirewallingTcpIpConnectionManager cm2 = getConnectionManager(hz2);
        FirewallingTcpIpConnectionManager cm3 = getConnectionManager(hz3);

        cm3.block(n1.address);
        cm3.block(n2.address);

        n1.clusterService.removeAddress(n3.address);
        n2.clusterService.removeAddress(n3.address);
        cm1.block(n3.address);
        cm2.block(n3.address);

        assertTrue(splitLatch.await(20, TimeUnit.SECONDS));
        assertEquals(2, hz1.getCluster().getMembers().size());
        assertEquals(2, hz2.getCluster().getMembers().size());
        assertEquals(3, hz3.getCluster().getMembers().size());

        cm3.unblock(n1.address);
        cm1.unblock(n3.address);
        cm2.unblock(n3.address);

        assertTrue(mergeLatch.await(60, TimeUnit.SECONDS));
        assertEquals(3, hz1.getCluster().getMembers().size());
        assertEquals(3, hz2.getCluster().getMembers().size());
        assertEquals(3, hz3.getCluster().getMembers().size());

        assertEquals(n3.getThisAddress(), n1.getMasterAddress());
        assertEquals(n3.getThisAddress(), n2.getMasterAddress());
        assertEquals(n3.getThisAddress(), n3.getMasterAddress());
    }
View Full Code Here

            return new FirewallingTcpIpConnectionManager(ioService, serverSocketChannel);
        }
    }

    private static FirewallingTcpIpConnectionManager getConnectionManager(HazelcastInstance hz) {
        Node node = TestUtil.getNode(hz);
        return (FirewallingTcpIpConnectionManager) node.getConnectionManager();
    }
View Full Code Here

        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        HazelcastInstance local = factory.newHazelcastInstance();
        HazelcastInstance remote = factory.newHazelcastInstance();
        warmUpPartitions(local, remote);

        Node localNode = getNode(local);
        OperationService service = localNode.nodeEngine.getOperationService();
        Operation op = new PartitionTargetOperation();
        String partitionKey = generateKeyOwnedBy(remote);
        int partitionId = localNode.nodeEngine.getPartitionService().getPartitionId(partitionKey);
        Future f = service.createInvocationBuilder(null, op, partitionId).setCallTimeout(30000).invoke();
View Full Code Here

            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 (int i = 0; i < instances.length; i++) {
View Full Code Here

TOP

Related Classes of com.hazelcast.instance.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.