Search in sources :

Example 96 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class GridSpiTestContext method resetNodes.

/**
 * @param nodes Nodes to reset.
 * @param rmv Whether nodes that were not passed in should be removed or not.
 */
public void resetNodes(Collection<ClusterNode> nodes, boolean rmv) {
    for (ClusterNode node : nodes) {
        assert !node.equals(locNode);
        if (!rmtNodes.contains(node))
            addNode(node);
    }
    if (rmv) {
        for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext(); ) {
            ClusterNode node = iter.next();
            if (!nodes.contains(node)) {
                iter.remove();
                notifyListener(new DiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node));
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 97 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class GridSpiTestContext method addNode.

/**
 * @param node Node to add.
 */
public void addNode(ClusterNode node) {
    rmtNodes.add(node);
    notifyListener(new DiscoveryEvent(locNode, "Node joined", EVT_NODE_JOINED, node));
}
Also used : DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 98 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method connectionRestore_Coordinator.

/**
 * @param initNodes Number of initially started nodes.
 * @param startNodes Number of nodes to start after coordinator loose connection.
 * @param failCnt Number of nodes to stop after coordinator loose connection.
 * @throws Exception If failed.
 */
private void connectionRestore_Coordinator(final int initNodes, int startNodes, int failCnt) throws Exception {
    sesTimeout = 30_000;
    testSockNio = true;
    Ignite node0 = startGrids(initNodes);
    ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
    c0.closeSocket(true);
    final AtomicInteger nodeIdx = new AtomicInteger(initNodes);
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() {
            try {
                startGrid(nodeIdx.getAndIncrement());
            } catch (Exception e) {
                error("Start failed: " + e);
            }
            return null;
        }
    }, startNodes, "start-node");
    int cnt = 0;
    DiscoveryEvent[] expEvts = new DiscoveryEvent[startNodes - failCnt];
    int expEvtCnt = 0;
    sesTimeout = 1000;
    List<ZkTestClientCnxnSocketNIO> blockedC = new ArrayList<>();
    final List<String> failedZkNodes = new ArrayList<>(failCnt);
    for (int i = initNodes; i < initNodes + startNodes; i++) {
        final ZookeeperDiscoverySpi spi = helper.waitSpi(getTestIgniteInstanceName(i), spis);
        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                Object spiImpl = GridTestUtils.getFieldValue(spi, "impl");
                if (spiImpl == null)
                    return false;
                long internalOrder = GridTestUtils.getFieldValue(spiImpl, "rtState", "internalOrder");
                return internalOrder > 0;
            }
        }, 10_000));
        if (cnt++ < failCnt) {
            ZkTestClientCnxnSocketNIO c = ZkTestClientCnxnSocketNIO.forNode(getTestIgniteInstanceName(i));
            c.closeSocket(true);
            blockedC.add(c);
            failedZkNodes.add(ZookeeperDiscoverySpiTestHelper.aliveZkNodePath(spi));
        } else {
            expEvts[expEvtCnt] = ZookeeperDiscoverySpiTestHelper.joinEvent(initNodes + expEvtCnt + 1);
            expEvtCnt++;
        }
    }
    ZookeeperDiscoverySpiTestHelper.waitNoAliveZkNodes(log, zkCluster.getConnectString(), failedZkNodes, 30_000);
    c0.allowConnect();
    for (ZkTestClientCnxnSocketNIO c : blockedC) c.allowConnect();
    if (expEvts.length > 0) {
        for (int i = 0; i < initNodes; i++) helper.checkEvents(ignite(i), evts, expEvts);
    }
    fut.get();
    waitForTopology(initNodes + startNodes - failCnt);
}
Also used : ZkTestClientCnxnSocketNIO(org.apache.zookeeper.ZkTestClientCnxnSocketNIO) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ZookeeperDiscoverySpi(org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite)

Example 99 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class ZookeeperDiscoverySpiTestHelper method leftEvent.

/**
 * @param topVer Topology version.
 * @return Expected event instance.
 */
static DiscoveryEvent leftEvent(long topVer, boolean fail) {
    int eventType = fail ? EventType.EVT_NODE_FAILED : EventType.EVT_NODE_LEFT;
    DiscoveryEvent expEvt = new DiscoveryEvent(null, null, eventType, null);
    expEvt.topologySnapshot(topVer, null);
    return expEvt;
}
Also used : DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 100 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class ZookeeperDiscoverySpiTestHelper method checkEvents.

/**
 * @param nodeId Node ID.
 * @param expEvts Expected events.
 * @throws Exception If failed.
 */
private void checkEvents(final UUID nodeId, ConcurrentHashMap<UUID, Map<T2<Integer, Long>, DiscoveryEvent>> evts, final DiscoveryEvent... expEvts) throws Exception {
    Assert.assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
        @Override
        public boolean apply() {
            Map<T2<Integer, Long>, DiscoveryEvent> nodeEvts = evts.get(nodeId);
            if (nodeEvts == null) {
                info.accept("No events for node: " + nodeId);
                return false;
            }
            synchronized (nodeEvts) {
                for (DiscoveryEvent expEvt : expEvts) {
                    DiscoveryEvent evt0 = nodeEvts.get(new T2<>(clusterNum.get(), expEvt.topologyVersion()));
                    if (evt0 == null) {
                        info.accept("No event for version: " + expEvt.topologyVersion());
                        return false;
                    }
                    Assert.assertEquals(// todo check
                    "Unexpected event [topVer=" + expEvt.topologyVersion() + ", exp=" + U.gridEventName(expEvt.type()) + ", evt=" + evt0 + ']', expEvt.type(), evt0.type());
                }
            }
            return true;
        }
    }, 30000));
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)111 Event (org.apache.ignite.events.Event)56 UUID (java.util.UUID)49 ClusterNode (org.apache.ignite.cluster.ClusterNode)45 CountDownLatch (java.util.concurrent.CountDownLatch)30 Ignite (org.apache.ignite.Ignite)29 Test (org.junit.Test)27 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)25 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)24 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)23 ArrayList (java.util.ArrayList)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 List (java.util.List)16 Collection (java.util.Collection)12 HashMap (java.util.HashMap)12 Map (java.util.Map)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)11 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)10