use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySpiReconnectDelayTest method checkServerJoinAtStart.
/**
* Check that client restores connection after the given time, with the expected number of messages sent
* and expected time elapsed.
* @param numOfFailedRequests number of TcpDiscoveryJoinRequestMessage to be failed before succeed to connect.
* @param reconnectDelay argument for {@link TcpDiscoverySpi#setReconnectDelay(int)}
*/
private void checkServerJoinAtStart(int numOfFailedRequests, int reconnectDelay) throws Exception {
try (Ignite ignite1 = G.start(getConfiguration("server", false, reconnectDelay))) {
final CountDownLatch joinLatch = new CountDownLatch(1);
final AtomicInteger failJoinReqRes = ((FailingTcpDiscoverySpi) ignite1.configuration().getDiscoverySpi()).failJoinReqRes;
failJoinReqRes.set(numOfFailedRequests);
ignite1.events().localListen(new IgnitePredicate<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent evt) {
info("Node1 event: " + evt);
if (evt.type() == EVT_NODE_JOINED)
joinLatch.countDown();
return true;
}
}, EVT_NODE_JOINED);
final long startTime = System.currentTimeMillis();
try (Ignite ignite2 = G.start(getConfiguration("server-2", false, reconnectDelay))) {
assertTrue(joinLatch.await(EVT_TIMEOUT, MILLISECONDS));
long endTime = System.currentTimeMillis();
// Check topology.
assertEquals(1L, ignite1.cluster().localNode().order());
assertEquals(2L, ignite2.cluster().localNode().order());
assertEquals(2L, ignite2.cluster().topologyVersion());
// Check connection time.
// Total time should be at least the sum of all delays.
long totalTime = endTime - startTime;
long expTotalTime = numOfFailedRequests * reconnectDelay;
assertTrue(totalTime >= expTotalTime);
// Check number of messages.
// If exactly numOfFailedRequests fail, counter will be at -1.
// If unexpected additional requests are sent, counter will be <= -2.
int cntr = failJoinReqRes.get();
int numOfMessages = numOfFailedRequests - cntr;
int expNumOfMessages = numOfFailedRequests + 1;
assertEquals("Unexpected number of messages", expNumOfMessages, numOfMessages);
}
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class HadoopJobTracker method onKernalStart.
/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public void onKernalStart() throws IgniteCheckedException {
super.onKernalStart();
jobMetaCache().context().continuousQueries().executeInternalQuery(new CacheEntryUpdatedListener<HadoopJobId, HadoopJobMetadata>() {
@Override
public void onUpdated(final Iterable<CacheEntryEvent<? extends HadoopJobId, ? extends HadoopJobMetadata>> evts) {
if (!busyLock.tryReadLock())
return;
try {
// Must process query callback in a separate thread to avoid deadlocks.
evtProcSvc.execute(new EventHandler() {
@Override
protected void body() throws IgniteCheckedException {
processJobMetadataUpdates(evts);
}
});
} finally {
busyLock.readUnlock();
}
}
}, null, true, true, false);
ctx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(final Event evt) {
if (!busyLock.tryReadLock())
return;
try {
// Must process discovery callback in a separate thread to avoid deadlock.
evtProcSvc.execute(new EventHandler() {
@Override
protected void body() {
processNodeLeft((DiscoveryEvent) evt);
}
});
} finally {
busyLock.readUnlock();
}
}
}, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridMapQueryExecutor method start.
/**
* @param ctx Context.
* @param h2 H2 Indexing.
* @throws IgniteCheckedException If failed.
*/
public void start(final GridKernalContext ctx, IgniteH2Indexing h2) throws IgniteCheckedException {
this.ctx = ctx;
this.h2 = h2;
log = ctx.log(GridMapQueryExecutor.class);
final UUID locNodeId = ctx.localNodeId();
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(final Event evt) {
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
GridH2QueryContext.clearAfterDeadNode(locNodeId, nodeId);
MapNodeResults nodeRess = qryRess.remove(nodeId);
if (nodeRess == null)
return;
nodeRess.cancelAll();
}
}, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {
@SuppressWarnings("deprecation")
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
if (!busyLock.enterBusy())
return;
try {
if (msg instanceof GridCacheQueryMarshallable)
((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
GridMapQueryExecutor.this.onMessage(nodeId, msg);
} finally {
busyLock.leaveBusy();
}
}
});
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class IgniteCacheReplicatedQuerySelfTest method testNodeLeft.
/**
* @throws Exception If failed.
*/
@IgniteIgnore(value = "https://issues.apache.org/jira/browse/IGNITE-613", forceFailure = true)
public void testNodeLeft() throws Exception {
Ignite g = startGrid("client");
try {
assertTrue(g.configuration().isClientMode());
IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
for (int i = 0; i < 1000; i++) cache.put(i, i);
// Client cache should be empty.
assertEquals(0, cache.localSize());
QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 0 order by _key").setPageSize(10));
assertEquals(0, (int) q.iterator().next().getKey());
// Query for replicated cache was run on one of nodes.
ConcurrentMap<?, ?> mapNode1 = queryResultMap(0);
ConcurrentMap<?, ?> mapNode2 = queryResultMap(1);
ConcurrentMap<?, ?> mapNode3 = queryResultMap(2);
assertEquals(1, mapNode1.size() + mapNode2.size() + mapNode3.size());
final UUID nodeId = g.cluster().localNode().id();
final CountDownLatch latch = new CountDownLatch(1);
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (((DiscoveryEvent) evt).eventNode().id().equals(nodeId))
latch.countDown();
return true;
}
}, EVT_NODE_LEFT);
stopGrid("client");
latch.await();
assertEquals(0, mapNode1.size());
assertEquals(0, mapNode2.size());
assertEquals(0, mapNode3.size());
} finally {
stopGrid("client");
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridMemoryEventStorageMultiThreadedSelfTest method testMultiThreaded.
/**
* @throws Exception If test failed
*/
public void testMultiThreaded() throws Exception {
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < 100000; i++) getSpi().record(new DiscoveryEvent(null, "Test event", 1, null));
return null;
}
}, 10, "event-thread");
Collection<Event> evts = getSpi().localEvents(F.<Event>alwaysTrue());
info("Events count in memory: " + evts.size());
assert evts.size() <= 10000 : "Incorrect number of events: " + evts.size();
}
Aggregations