Search in sources :

Example 36 with DiscoveryEvent

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

the class TcpDiscoveryNodeAttributesUpdateOnReconnectTest method testReconnect.

/**
 * @throws Exception If failed.
 */
public void testReconnect() throws Exception {
    Ignite srv = startGrid("server");
    IgniteEvents evts = srv.events();
    evts.enableLocal(EventType.EVTS_DISCOVERY_ALL);
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            ClusterNode node = ((DiscoveryEvent) evt).eventNode();
            rejoinAttr = node.attribute("test");
            return true;
        }
    }, EventType.EVT_NODE_JOINED);
    Ignite client = startGrid("client");
    reconnectClientNode(log, client, srv, null);
    assertEquals("2", rejoinAttr);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteEvents(org.apache.ignite.IgniteEvents) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 37 with DiscoveryEvent

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

the class TcpDiscoverySelfTest method testPingInterruptedOnNodeFailed.

/**
 * @throws Exception If any error occurs.
 */
public void testPingInterruptedOnNodeFailed() throws Exception {
    try {
        final Ignite pingingNode = startGrid("testPingInterruptedOnNodeFailedPingingNode");
        final Ignite failedNode = startGrid("testPingInterruptedOnNodeFailedFailingNode");
        startGrid("testPingInterruptedOnNodeFailedSimpleNode");
        ((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).ignorePingResponse = true;
        final UUID failedNodeId = failedNode.cluster().localNode().id();
        final CountDownLatch pingLatch = new CountDownLatch(1);
        final CountDownLatch eventLatch = new CountDownLatch(1);
        final AtomicBoolean pingRes = new AtomicBoolean(true);
        final AtomicBoolean failRes = new AtomicBoolean(false);
        long startTs = System.currentTimeMillis();
        pingingNode.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event event) {
                if (((DiscoveryEvent) event).eventNode().id().equals(failedNodeId)) {
                    failRes.set(true);
                    eventLatch.countDown();
                }
                return true;
            }
        }, EventType.EVT_NODE_FAILED);
        IgniteInternalFuture<?> pingFut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                pingLatch.countDown();
                pingRes.set(pingingNode.configuration().getDiscoverySpi().pingNode(failedNodeId));
                return null;
            }
        }, 1);
        IgniteInternalFuture<?> failingFut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                pingLatch.await();
                Thread.sleep(3000);
                ((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).simulateNodeFailure();
                return null;
            }
        }, 1);
        failingFut.get();
        pingFut.get();
        assertFalse(pingRes.get());
        assertTrue(System.currentTimeMillis() - startTs < pingingNode.configuration().getFailureDetectionTimeout() / 2);
        assertTrue(eventLatch.await(7, TimeUnit.SECONDS));
        assertTrue(failRes.get());
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) SocketTimeoutException(java.net.SocketTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 38 with DiscoveryEvent

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

the class TcpDiscoverySelfTest method testMetricsSending.

/**
 * @throws Exception If any error occurs.
 */
public void testMetricsSending() throws Exception {
    final AtomicBoolean stopping = new AtomicBoolean();
    try {
        final CountDownLatch latch1 = new CountDownLatch(1);
        final Ignite g1 = startGrid(1);
        IgnitePredicate<Event> lsnr1 = new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info(evt.message());
                latch1.countDown();
                return true;
            }
        };
        g1.events().localListen(lsnr1, EVT_NODE_METRICS_UPDATED);
        assert latch1.await(10, SECONDS);
        g1.events().stopLocalListen(lsnr1);
        final CountDownLatch latch1_1 = new CountDownLatch(1);
        final CountDownLatch latch1_2 = new CountDownLatch(1);
        final CountDownLatch latch2_1 = new CountDownLatch(1);
        final CountDownLatch latch2_2 = new CountDownLatch(1);
        final Ignite g2 = startGrid(2);
        g2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (stopping.get())
                    return true;
                info(evt.message());
                UUID id = ((DiscoveryEvent) evt).eventNode().id();
                if (id.equals(g1.cluster().localNode().id()))
                    latch2_1.countDown();
                else if (id.equals(g2.cluster().localNode().id()))
                    latch2_2.countDown();
                else
                    assert false : "Event fired for unknown node.";
                return true;
            }
        }, EVT_NODE_METRICS_UPDATED);
        g1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (stopping.get())
                    return true;
                info(evt.message());
                UUID id = ((DiscoveryEvent) evt).eventNode().id();
                if (id.equals(g1.cluster().localNode().id()))
                    latch1_1.countDown();
                else if (id.equals(g2.cluster().localNode().id()))
                    latch1_2.countDown();
                else
                    assert false : "Event fired for unknown node.";
                return true;
            }
        }, EVT_NODE_METRICS_UPDATED);
        assert latch1_1.await(10, SECONDS);
        assert latch1_2.await(10, SECONDS);
        assert latch2_1.await(10, SECONDS);
        assert latch2_2.await(10, SECONDS);
    } finally {
        stopping.set(true);
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 39 with DiscoveryEvent

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

the class TcpDiscoverySelfTest method testNodeAdded.

/**
 * @throws Exception If any error occurs.
 */
public void testNodeAdded() throws Exception {
    try {
        final Ignite g1 = startGrid(1);
        final CountDownLatch cnt = new CountDownLatch(2);
        g1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info("Node joined: " + evt.message());
                DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
                TcpDiscoveryNode node = ((TcpDiscoveryNode) discoMap.get(g1.name()).getNode(discoEvt.eventNode().id()));
                assert node != null && node.visible();
                cnt.countDown();
                return true;
            }
        }, EventType.EVT_NODE_JOINED);
        startGrid(2);
        startGrid(3);
        info("Nodes were started");
        assert cnt.await(1, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 40 with DiscoveryEvent

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

the class TcpDiscoverySelfTest method testNoRingMessageWorkerAbnormalFailureOnSegmentation.

/**
 * @throws Exception If failed
 */
public void testNoRingMessageWorkerAbnormalFailureOnSegmentation() throws Exception {
    try {
        TestMessageWorkerFailureSpi1 spi1 = new TestMessageWorkerFailureSpi1(TestMessageWorkerFailureSpi1.SEGMENTATION_MODE);
        nodeSpi.set(spi1);
        Ignite ignite1 = startGrid("testNoRingMessageWorkerAbnormalFailureNormalNode");
        nodeSpi.set(new TcpDiscoverySpi());
        final Ignite ignite2 = startGrid("testNoRingMessageWorkerAbnormalFailureSegmentedNode");
        final AtomicBoolean disconnected = new AtomicBoolean();
        final AtomicBoolean segmented = new AtomicBoolean();
        final CountDownLatch disLatch = new CountDownLatch(1);
        final CountDownLatch segLatch = new CountDownLatch(1);
        final UUID failedNodeId = ignite2.cluster().localNode().id();
        ignite1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EventType.EVT_NODE_FAILED && failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                    disconnected.set(true);
                disLatch.countDown();
                return false;
            }
        }, EventType.EVT_NODE_FAILED);
        ignite2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (!failedNodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                    return true;
                if (evt.type() == EventType.EVT_NODE_SEGMENTED) {
                    segmented.set(true);
                    segLatch.countDown();
                }
                return true;
            }
        }, EventType.EVT_NODE_SEGMENTED);
        spi1.stop = true;
        disLatch.await(15, TimeUnit.SECONDS);
        assertTrue(disconnected.get());
        spi1.stop = false;
        segLatch.await(15, TimeUnit.SECONDS);
        assertTrue(segmented.get());
        Thread.sleep(10_000);
        String result = strLog.toString();
        assert result.contains("Local node SEGMENTED") && !result.contains("TcpDiscoverSpi's message worker thread failed abnormally") : result;
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)83 Event (org.apache.ignite.events.Event)54 UUID (java.util.UUID)39 ClusterNode (org.apache.ignite.cluster.ClusterNode)32 CountDownLatch (java.util.concurrent.CountDownLatch)24 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)24 Ignite (org.apache.ignite.Ignite)23 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)11 List (java.util.List)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 JobEvent (org.apache.ignite.events.JobEvent)8 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)7 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 IgniteException (org.apache.ignite.IgniteException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6