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();
}
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);
}
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;
}
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();
}
}
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());
}
Aggregations