Search in sources :

Example 56 with Event

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

the class GridTaskTimeoutSelfTest method checkTimedOutEvents.

/**
 * @param execId Execution ID.
 */
private void checkTimedOutEvents(final IgniteUuid execId) {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    Collection<Event> evts = ignite.events().localQuery(new PE() {

        @Override
        public boolean apply(Event evt) {
            return ((TaskEvent) evt).taskSessionId().equals(execId);
        }
    }, EVT_TASK_TIMEDOUT);
    assert evts.size() == 1 : "Invalid number of timed out tasks: " + evts.size();
}
Also used : PE(org.apache.ignite.internal.util.typedef.PE) TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 57 with Event

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

the class IgniteClientReconnectAbstractTest method reconnectClientNodes.

/**
 * Reconnect client node.
 *
 * @param log  Logger.
 * @param clients Clients.
 * @param srv Server.
 * @param disconnectedC Closure which will be run when client node disconnected.
 * @throws Exception If failed.
 */
protected static void reconnectClientNodes(final IgniteLogger log, List<Ignite> clients, Ignite srv, @Nullable Runnable disconnectedC) throws Exception {
    final TestTcpDiscoverySpi srvSpi = spi(srv);
    final CountDownLatch disconnectLatch = new CountDownLatch(clients.size());
    final CountDownLatch reconnectLatch = new CountDownLatch(clients.size());
    log.info("Block reconnect.");
    for (Ignite client : clients) spi(client).writeLatch = new CountDownLatch(1);
    IgnitePredicate<Event> p = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                log.info("Disconnected: " + evt);
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                log.info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    };
    for (Ignite client : clients) client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    for (Ignite client : clients) srvSpi.failNode(client.cluster().localNode().id(), null);
    waitReconnectEvent(log, disconnectLatch);
    if (disconnectedC != null)
        disconnectedC.run();
    log.info("Allow reconnect.");
    for (Ignite client : clients) spi(client).writeLatch.countDown();
    waitReconnectEvent(log, reconnectLatch);
    for (Ignite client : clients) client.events().stopLocalListen(p);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 58 with Event

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

the class IgniteClientReconnectAbstractTest method reconnectServersRestart.

/**
 * @param log Logger.
 * @param client Client node.
 * @param srvs Server nodes to stop.
 * @param srvStartC Closure starting server nodes.
 * @throws Exception If failed.
 * @return Restarted servers.
 */
public static Collection<Ignite> reconnectServersRestart(final IgniteLogger log, Ignite client, Collection<Ignite> srvs, Callable<Collection<Ignite>> srvStartC) throws Exception {
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                log.info("Disconnected: " + evt);
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                log.info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    for (Ignite srv : srvs) srv.close();
    assertTrue(disconnectLatch.await(30_000, MILLISECONDS));
    Collection<Ignite> startedSrvs = srvStartC.call();
    assertTrue(reconnectLatch.await(10_000, MILLISECONDS));
    return startedSrvs;
}
Also used : Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 59 with Event

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

the class IgniteClientReconnectApiExceptionTest method doTestIgniteOperationOnDisconnect.

/**
 * @param client Client.
 * @param ops Operations closures.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void doTestIgniteOperationOnDisconnect(Ignite client, final List<T2<Callable, C1<Object, Boolean>>> ops) throws Exception {
    assertNotNull(client.cache(DEFAULT_CACHE_NAME));
    final TestTcpDiscoverySpi clientSpi = spi(client);
    Ignite srv = clientRouter(client);
    TestTcpDiscoverySpi srvSpi = spi(srv);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    log.info("Block reconnect.");
    clientSpi.writeLatch = new CountDownLatch(1);
    final List<IgniteInternalFuture> futs = new ArrayList<>();
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                assertEquals(1, reconnectLatch.getCount());
                for (T2<Callable, C1<Object, Boolean>> op : ops) futs.add(GridTestUtils.runAsync(op.get1()));
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    try {
        log.info("Fail client.");
        srvSpi.failNode(client.cluster().localNode().id(), null);
        waitReconnectEvent(disconnectLatch);
        assertEquals(ops.size(), futs.size());
        for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
        U.sleep(2000);
        for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
        log.info("Allow reconnect.");
        clientSpi.writeLatch.countDown();
        waitReconnectEvent(reconnectLatch);
        // Check operation after reconnect working.
        for (int i = 0; i < futs.size(); i++) {
            final int i0 = i;
            try {
                final Object futRes = futs.get(i0).get(2, SECONDS);
                assertTrue(GridTestUtils.runAsync(new Callable<Boolean>() {

                    @Override
                    public Boolean call() throws Exception {
                        return ops.get(i0).get2().apply(futRes);
                    }
                }).get(2, SECONDS));
            } catch (IgniteFutureTimeoutCheckedException e) {
                e.printStackTrace();
                fail("Operation timeout. Iteration: " + i + ".");
            }
        }
    } finally {
        clientSpi.writeLatch.countDown();
        for (IgniteInternalFuture fut : futs) fut.cancel();
        stopAllGrids();
    }
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2)

Example 60 with Event

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

the class IgniteClientReconnectCacheTest method testReconnectInitialExchangeInProgress.

/**
 * @throws Exception If failed.
 */
public void testReconnectInitialExchangeInProgress() throws Exception {
    final UUID clientId = UUID.randomUUID();
    Ignite srv = grid(0);
    final CountDownLatch joinLatch = new CountDownLatch(1);
    srv.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_NODE_JOINED && ((DiscoveryEvent) evt).eventNode().id().equals(clientId)) {
                info("Client joined: " + evt);
                joinLatch.countDown();
            }
            return true;
        }
    }, EVT_NODE_JOINED);
    TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) srv.configuration().getCommunicationSpi();
    srvCommSpi.blockMessages(GridDhtPartitionsFullMessage.class, clientId);
    clientMode = true;
    nodeId = clientId;
    IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                Ignition.start(optimize(getConfiguration(getTestIgniteInstanceName(SRV_CNT))));
                return true;
            } catch (IgniteClientDisconnectedException e) {
                log.info("Expected start error: " + e);
                try {
                    e.reconnectFuture().get();
                    fail();
                } catch (IgniteException e0) {
                    log.info("Expected future error: " + e0);
                }
                return true;
            } catch (Throwable e) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        }
    });
    TestTcpDiscoverySpi srvSpi = spi(srv);
    try {
        if (!joinLatch.await(10_000, MILLISECONDS)) {
            log.error("Failed to wait for join event, will dump threads.");
            U.dumpThreads(log);
            fail("Failed to wait for join event.");
        }
        U.sleep(1000);
        assertNotDone(fut);
        srvSpi.failNode(clientId, null);
    } finally {
        srvCommSpi.stopBlock(false);
    }
    assertTrue(fut.get());
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Aggregations

Event (org.apache.ignite.events.Event)226 CountDownLatch (java.util.concurrent.CountDownLatch)127 Ignite (org.apache.ignite.Ignite)112 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)96 UUID (java.util.UUID)71 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)44 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)43 ClusterNode (org.apache.ignite.cluster.ClusterNode)38 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)28 ArrayList (java.util.ArrayList)27 JobEvent (org.apache.ignite.events.JobEvent)27 IgniteException (org.apache.ignite.IgniteException)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 HashSet (java.util.HashSet)15 TaskEvent (org.apache.ignite.events.TaskEvent)15 Collection (java.util.Collection)13 HashMap (java.util.HashMap)12 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)12 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)12