Search in sources :

Example 16 with DiscoveryEvent

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

the class GridSpiTestContext method removeNode.

/**
     * @param nodeId Node ID.
     */
public void removeNode(UUID nodeId) {
    for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext(); ) {
        ClusterNode node = iter.next();
        if (node.id().equals(nodeId)) {
            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 17 with DiscoveryEvent

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

the class GridDiscoveryEventSelfTest method testMixedSequenceEvents.

/**
     * @throws Exception If failed.
     */
public void testMixedSequenceEvents() throws Exception {
    try {
        Ignite g0 = startGrid(0);
        UUID id0 = g0.cluster().localNode().id();
        final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
        final CountDownLatch latch = new CountDownLatch(8);
        g0.events().localListen(new IgnitePredicate<Event>() {

            private AtomicInteger cnt = new AtomicInteger();

            @Override
            public boolean apply(Event evt) {
                assert evt.type() == EVT_NODE_JOINED || evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED : evt;
                evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
                latch.countDown();
                return true;
            }
        }, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
        UUID id1 = startGrid(1).cluster().localNode().id();
        UUID id2 = startGrid(2).cluster().localNode().id();
        UUID id3 = startGrid(3).cluster().localNode().id();
        stopGrid(3);
        stopGrid(2);
        stopGrid(1);
        UUID id4 = startGrid(4).cluster().localNode().id();
        stopGrid(4);
        assertTrue("Wrong count of events received [cnt= " + evts.size() + ", evts=" + evts + ']', latch.await(3000, MILLISECONDS));
        Collection<ClusterNode> top0 = evts.get(0);
        assertNotNull(top0);
        assertEquals(2, top0.size());
        assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id1));
        Collection<ClusterNode> top1 = evts.get(1);
        assertNotNull(top1);
        assertEquals(3, top1.size());
        assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id1));
        assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id2));
        Collection<ClusterNode> top2 = evts.get(2);
        assertNotNull(top2);
        assertEquals(4, top2.size());
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id1));
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id2));
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id3));
        Collection<ClusterNode> top3 = evts.get(3);
        assertNotNull(top3);
        assertEquals(3, top3.size());
        assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id1));
        assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top3, NODE_2ID).contains(id3));
        Collection<ClusterNode> top4 = evts.get(4);
        assertNotNull(top4);
        assertEquals(2, top4.size());
        assertTrue(F.viewReadOnly(top4, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top4, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top4, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top4, NODE_2ID).contains(id3));
        Collection<ClusterNode> top5 = evts.get(5);
        assertNotNull(top5);
        assertEquals(1, top5.size());
        assertTrue(F.viewReadOnly(top5, NODE_2ID).contains(id0));
        assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id3));
        Collection<ClusterNode> top6 = evts.get(6);
        assertNotNull(top6);
        assertEquals(2, top6.size());
        assertTrue(F.viewReadOnly(top6, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top6, NODE_2ID).contains(id4));
        assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id3));
        Collection<ClusterNode> top7 = evts.get(7);
        assertNotNull(top7);
        assertEquals(1, top7.size());
        assertTrue(F.viewReadOnly(top7, NODE_2ID).contains(id0));
        assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id3));
        assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id4));
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 18 with DiscoveryEvent

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

the class GridDiscoveryEventSelfTest method testDaemonNodeJoin.

/**
     * @throws Exception If failed.
     */
public void testDaemonNodeJoin() throws Exception {
    try {
        startGridsMultiThreaded(3);
        final AtomicReference<IgniteCheckedException> err = new AtomicReference<>();
        for (int i = 0; i < 3; i++) {
            Ignite g = grid(i);
            g.events().localListen(new IgnitePredicate<Event>() {

                @Override
                public boolean apply(Event evt) {
                    DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
                    if (discoEvt.topologyNodes().size() != 3)
                        err.compareAndSet(null, new IgniteCheckedException("Invalid discovery event [evt=" + discoEvt + ", nodes=" + discoEvt.topologyNodes() + ']'));
                    return true;
                }
            }, EventType.EVT_NODE_JOINED);
        }
        daemon = true;
        IgniteKernal daemon = (IgniteKernal) startGrid(3);
        DiscoveryEvent join = daemon.context().discovery().localJoinEvent();
        assertEquals(3, join.topologyNodes().size());
        U.sleep(100);
        if (err.get() != null)
            throw err.get();
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignite(org.apache.ignite.Ignite)

Example 19 with DiscoveryEvent

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

the class GridDiscoveryEventSelfTest method testLeaveSequenceEvents.

/**
     * @throws Exception If failed.
     */
public void testLeaveSequenceEvents() throws Exception {
    try {
        Ignite g0 = startGrid(0);
        UUID id0 = g0.cluster().localNode().id();
        UUID id1 = startGrid(1).cluster().localNode().id();
        UUID id2 = startGrid(2).cluster().localNode().id();
        UUID id3 = startGrid(3).cluster().localNode().id();
        final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
        final CountDownLatch latch = new CountDownLatch(3);
        g0.events().localListen(new IgnitePredicate<Event>() {

            private AtomicInteger cnt = new AtomicInteger();

            @Override
            public boolean apply(Event evt) {
                assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED : evt;
                evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
                latch.countDown();
                return true;
            }
        }, EVT_NODE_LEFT, EVT_NODE_FAILED);
        stopGrid(3);
        stopGrid(2);
        stopGrid(1);
        assertTrue("Wrong count of events received: " + evts, latch.await(3000, MILLISECONDS));
        Collection<ClusterNode> top2 = evts.get(0);
        assertNotNull(top2);
        assertEquals(3, top2.size());
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id1));
        assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top2, NODE_2ID).contains(id3));
        Collection<ClusterNode> top1 = evts.get(1);
        assertNotNull(top1);
        assertEquals(2, top1.size());
        assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id0));
        assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top1, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top1, NODE_2ID).contains(id3));
        Collection<ClusterNode> top0 = evts.get(2);
        assertNotNull(top0);
        assertEquals(1, top0.size());
        assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id0));
        assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id1));
        assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id2));
        assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id3));
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 20 with DiscoveryEvent

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

the class GridDiscoveryEventSelfTest method testConcurrentJoinEvents.

/**
     * @throws Exception If failed.
     */
public void testConcurrentJoinEvents() throws Exception {
    try {
        Ignite g0 = startGrid(0);
        UUID id0 = g0.cluster().localNode().id();
        final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
        g0.events().localListen(new IgnitePredicate<Event>() {

            private AtomicInteger cnt = new AtomicInteger();

            @Override
            public boolean apply(Event evt) {
                assert evt.type() == EVT_NODE_JOINED : evt;
                X.println(">>>>>>> Joined " + F.viewReadOnly(((DiscoveryEvent) evt).topologyNodes(), NODE_2ID));
                evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
                return true;
            }
        }, EVT_NODE_JOINED);
        U.sleep(100);
        startGridsMultiThreaded(1, 10);
        U.sleep(100);
        assertEquals(10, evts.size());
        for (int i = 0; i < 10; i++) {
            Collection<ClusterNode> snapshot = evts.get(i);
            assertEquals(2 + i, snapshot.size());
            assertTrue(F.viewReadOnly(snapshot, NODE_2ID).contains(id0));
            for (ClusterNode n : snapshot) assertTrue("Wrong node order in snapshot [i=" + i + ", node=" + n + ']', n.order() <= 2 + i);
        }
        Collection<UUID> ids = F.viewReadOnly(evts.get(9), NODE_2ID);
        for (int i = 1; i <= 10; i++) assertTrue(ids.contains(grid(i).localNode().id()));
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)68 Event (org.apache.ignite.events.Event)49 UUID (java.util.UUID)36 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)22 Ignite (org.apache.ignite.Ignite)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 List (java.util.List)9 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 JobEvent (org.apache.ignite.events.JobEvent)8 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IgniteException (org.apache.ignite.IgniteException)5 HashMap (java.util.HashMap)4