Search in sources :

Example 86 with Event

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

the class TcpDiscoverySelfTest method testFailBeforeNodeAddedSent.

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

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EVT_NODE_JOINED)
                    joinCnt.countDown();
                else if (evt.type() == EVT_NODE_FAILED)
                    failCnt.countDown();
                else
                    assert false : "Unexpected event type: " + evt;
                return true;
            }
        }, EVT_NODE_JOINED, EVT_NODE_FAILED);
        final Ignite g = startGrid("FailBeforeNodeAddedSentSpi");
        discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {

            @Override
            public void apply(TcpDiscoveryAbstractMessage msg) {
                if (msg instanceof TcpDiscoveryNodeAddedMessage) {
                    discoMap.get(g.name()).simulateNodeFailure();
                    throw new RuntimeException("Avoid message sending: " + msg.getClass());
                }
            }
        });
        startGrid(3);
        assert joinCnt.await(10, SECONDS);
        assert failCnt.await(10, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) TcpDiscoveryNodeAddedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 87 with Event

use of org.apache.ignite.events.Event 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) IOException(java.io.IOException)

Example 88 with Event

use of org.apache.ignite.events.Event 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)

Example 89 with Event

use of org.apache.ignite.events.Event 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 90 with Event

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

the class TcpDiscoveryMultiThreadedTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings({ "IfMayBeConditional" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    UUID id = nodeId.get();
    if (id != null) {
        cfg.setNodeId(id);
        nodeId.set(null);
    }
    if (client())
        cfg.setClientMode(true);
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder).setJoinTimeout(60_000).setNetworkTimeout(10_000));
    int[] evts = { EVT_NODE_FAILED, EVT_NODE_LEFT };
    Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
    lsnrs.put(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            DiscoveryEvent discoveryEvt = (DiscoveryEvent) evt;
            failedNodes.add(discoveryEvt.eventNode().id());
            return true;
        }
    }, evts);
    cfg.setLocalEventListeners(lsnrs);
    cfg.setCacheConfiguration();
    cfg.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
    cfg.setIncludeProperties();
    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) CacheEntryEvent(javax.cache.event.CacheEntryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Aggregations

Event (org.apache.ignite.events.Event)210 CountDownLatch (java.util.concurrent.CountDownLatch)117 Ignite (org.apache.ignite.Ignite)104 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)88 UUID (java.util.UUID)66 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)43 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ClusterNode (org.apache.ignite.cluster.ClusterNode)35 JobEvent (org.apache.ignite.events.JobEvent)27 ArrayList (java.util.ArrayList)26 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)25 IgniteException (org.apache.ignite.IgniteException)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 HashSet (java.util.HashSet)15 TaskEvent (org.apache.ignite.events.TaskEvent)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 Collection (java.util.Collection)13 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)12 HashMap (java.util.HashMap)11 CacheException (javax.cache.CacheException)11