Search in sources :

Example 81 with Event

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

the class GridEventConsumeSelfTest method testStopByCallback.

/**
     * @throws Exception If failed.
     */
public void testStopByCallback() throws Exception {
    final Collection<UUID> nodeIds = new HashSet<>();
    final AtomicInteger cnt = new AtomicInteger();
    final CountDownLatch latch = new CountDownLatch(1);
    UUID consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {

        @Override
        public boolean apply(UUID nodeId, Event evt) {
            info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
            assertEquals(EVT_JOB_STARTED, evt.type());
            nodeIds.add(nodeId);
            cnt.incrementAndGet();
            latch.countDown();
            return false;
        }
    }, null, EVT_JOB_STARTED);
    try {
        assertNotNull(consumeId);
        grid(0).compute().broadcast(F.noop());
        assert latch.await(2, SECONDS);
        assertEquals(1, nodeIds.size());
        assertEquals(1, cnt.get());
    } finally {
        grid(0).events().stopRemoteListen(consumeId);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Example 82 with Event

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

the class GridEventConsumeSelfTest method testMasterNodeLeaveNoAutoUnsubscribe.

/**
     * @throws Exception If failed.
     */
public void testMasterNodeLeaveNoAutoUnsubscribe() throws Exception {
    Ignite g = startGrid("anotherGrid");
    final CountDownLatch discoLatch;
    try {
        final UUID nodeId = g.cluster().localNode().id();
        discoLatch = new CountDownLatch(GRID_CNT);
        for (int i = 0; i < GRID_CNT; i++) {
            grid(0).events().localListen(new IgnitePredicate<Event>() {

                @Override
                public boolean apply(Event evt) {
                    if (nodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
                        discoLatch.countDown();
                    return true;
                }
            }, EVT_NODE_LEFT);
        }
        consumeLatch = new CountDownLatch(GRID_CNT * 2 + 1);
        consumeCnt = new AtomicInteger();
        noAutoUnsubscribe = true;
        g.events().remoteListen(1, 0, false, null, new P1<Event>() {

            @Override
            public boolean apply(Event evt) {
                consumeLatch.countDown();
                consumeCnt.incrementAndGet();
                return true;
            }
        }, EVT_JOB_STARTED);
        grid(0).compute().broadcast(F.noop());
    } finally {
        stopGrid("anotherGrid");
    }
    discoLatch.await(3000, MILLISECONDS);
    grid(0).compute().broadcast(F.noop());
    assert consumeLatch.await(2, SECONDS);
    assertEquals(GRID_CNT * 2 + 1, consumeCnt.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Example 83 with Event

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

the class GridEventConsumeSelfTest method testResources.

/**
     * @throws Exception If failed.
     */
public void testResources() throws Exception {
    final Collection<UUID> nodeIds = new HashSet<>();
    final AtomicInteger cnt = new AtomicInteger();
    final CountDownLatch latch = new CountDownLatch(GRID_CNT);
    UUID consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {

        @IgniteInstanceResource
        private Ignite grid;

        @Override
        public boolean apply(UUID nodeId, Event evt) {
            info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
            assertEquals(EVT_JOB_STARTED, evt.type());
            assertNotNull(grid);
            nodeIds.add(nodeId);
            cnt.incrementAndGet();
            latch.countDown();
            return true;
        }
    }, new P1<Event>() {

        @IgniteInstanceResource
        private Ignite grid;

        @Override
        public boolean apply(Event evt) {
            assertNotNull(grid);
            return true;
        }
    }, EVT_JOB_STARTED);
    try {
        assertNotNull(consumeId);
        grid(0).compute().broadcast(F.noop());
        assert latch.await(2, SECONDS);
        assertEquals(GRID_CNT, nodeIds.size());
        assertEquals(GRID_CNT, cnt.get());
    } finally {
        grid(0).events().stopRemoteListen(consumeId);
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Example 84 with Event

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

the class TcpDiscoverySelfTest method testOrdinaryNodeFailure.

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

            @Override
            public boolean apply(Event evt) {
                cnt.countDown();
                return true;
            }
        }, EventType.EVT_NODE_FAILED);
        info("Nodes were started");
        discoMap.get(g2.name()).simulateNodeFailure();
        discoMap.get(g3.name()).simulateNodeFailure();
        assert cnt.await(25, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 85 with Event

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

the class TcpDiscoverySelfTest method testOrdinaryNodeLeave.

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

            @Override
            public boolean apply(Event evt) {
                cnt.countDown();
                return true;
            }
        }, EVT_NODE_LEFT, EVT_NODE_FAILED);
        info("Nodes were started");
        stopGrid(3);
        stopGrid(2);
        boolean res = cnt.await(1, SECONDS);
        assert res;
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

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