use of org.apache.ignite.events.Event in project ignite by apache.
the class WeightedRandomLoadBalancingSpi method onContextInitialized0.
/**
* {@inheritDoc}
*/
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof TaskEvent || evt instanceof JobEvent;
if (evt.type() == EVT_TASK_FINISHED || evt.type() == EVT_TASK_FAILED) {
IgniteUuid sesId = ((TaskEvent) evt).taskSessionId();
taskTops.remove(sesId);
if (log.isDebugEnabled())
log.debug("Removed task topology from topology cache for session: " + sesId);
} else // Here we set mapped property and later cache will be ignored
if (evt.type() == EVT_JOB_MAPPED) {
IgniteUuid sesId = ((JobEvent) evt).taskSessionId();
IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(sesId);
if (weightedTop != null)
weightedTop.set1(true);
if (log.isDebugEnabled())
log.debug("Job has been mapped. Ignore cache for session: " + sesId);
}
}
}, EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventStorageRuntimeConfigurationSelfTest method testEnableWithIncludes.
/**
* @throws Exception If failed.
*/
@Test
public void testEnableWithIncludes() throws Exception {
inclEvtTypes = new int[] { EVT_TASK_STARTED, EVT_TASK_FINISHED };
try {
Ignite g = startGrid();
final AtomicInteger cnt = new AtomicInteger();
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
cnt.incrementAndGet();
return true;
}
}, EVT_TASK_STARTED, EVT_TASK_FINISHED, EVT_JOB_STARTED);
g.compute().run(F.noop());
assertEquals(2, cnt.get());
g.events().enableLocal(EVT_TASK_FINISHED, EVT_JOB_STARTED);
g.compute().run(F.noop());
assertEquals(5, cnt.get());
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridDiscoveryEventSelfTest method testMixedSequenceEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testMixedSequenceEvents() throws Exception {
try {
Ignite g0 = startGrid(0);
UUID id0 = g0.cluster().localNode().id();
final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
final CountDownLatch latch = new CountDownLatch(8);
g0.events().localListen(new IgnitePredicate<Event>() {
private AtomicInteger cnt = new AtomicInteger();
@Override
public boolean apply(Event evt) {
assert evt.type() == EVT_NODE_JOINED || evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED : evt;
evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
latch.countDown();
return true;
}
}, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
UUID id1 = startGrid(1).cluster().localNode().id();
UUID id2 = startGrid(2).cluster().localNode().id();
UUID id3 = startGrid(3).cluster().localNode().id();
stopGrid(3);
stopGrid(2);
stopGrid(1);
UUID id4 = startGrid(4).cluster().localNode().id();
stopGrid(4);
assertTrue("Wrong count of events received [cnt= " + evts.size() + ", evts=" + evts + ']', latch.await(3000, MILLISECONDS));
Collection<ClusterNode> top0 = evts.get(0);
assertNotNull(top0);
assertEquals(2, top0.size());
assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id1));
Collection<ClusterNode> top1 = evts.get(1);
assertNotNull(top1);
assertEquals(3, top1.size());
assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id1));
assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id2));
Collection<ClusterNode> top2 = evts.get(2);
assertNotNull(top2);
assertEquals(4, top2.size());
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id1));
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id2));
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id3));
Collection<ClusterNode> top3 = evts.get(3);
assertNotNull(top3);
assertEquals(3, top3.size());
assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id1));
assertTrue(F.viewReadOnly(top3, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top3, NODE_2ID).contains(id3));
Collection<ClusterNode> top4 = evts.get(4);
assertNotNull(top4);
assertEquals(2, top4.size());
assertTrue(F.viewReadOnly(top4, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top4, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top4, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top4, NODE_2ID).contains(id3));
Collection<ClusterNode> top5 = evts.get(5);
assertNotNull(top5);
assertEquals(1, top5.size());
assertTrue(F.viewReadOnly(top5, NODE_2ID).contains(id0));
assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top5, NODE_2ID).contains(id3));
Collection<ClusterNode> top6 = evts.get(6);
assertNotNull(top6);
assertEquals(2, top6.size());
assertTrue(F.viewReadOnly(top6, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top6, NODE_2ID).contains(id4));
assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top6, NODE_2ID).contains(id3));
Collection<ClusterNode> top7 = evts.get(7);
assertNotNull(top7);
assertEquals(1, top7.size());
assertTrue(F.viewReadOnly(top7, NODE_2ID).contains(id0));
assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id3));
assertFalse(F.viewReadOnly(top7, NODE_2ID).contains(id4));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridDiscoveryEventSelfTest method testLeaveSequenceEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testLeaveSequenceEvents() throws Exception {
try {
Ignite g0 = startGrid(0);
UUID id0 = g0.cluster().localNode().id();
UUID id1 = startGrid(1).cluster().localNode().id();
UUID id2 = startGrid(2).cluster().localNode().id();
UUID id3 = startGrid(3).cluster().localNode().id();
final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
final CountDownLatch latch = new CountDownLatch(3);
g0.events().localListen(new IgnitePredicate<Event>() {
private AtomicInteger cnt = new AtomicInteger();
@Override
public boolean apply(Event evt) {
assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED : evt;
evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
latch.countDown();
return true;
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
stopGrid(3);
stopGrid(2);
stopGrid(1);
assertTrue("Wrong count of events received: " + evts, latch.await(3000, MILLISECONDS));
Collection<ClusterNode> top2 = evts.get(0);
assertNotNull(top2);
assertEquals(3, top2.size());
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id1));
assertTrue(F.viewReadOnly(top2, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top2, NODE_2ID).contains(id3));
Collection<ClusterNode> top1 = evts.get(1);
assertNotNull(top1);
assertEquals(2, top1.size());
assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id0));
assertTrue(F.viewReadOnly(top1, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top1, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top1, NODE_2ID).contains(id3));
Collection<ClusterNode> top0 = evts.get(2);
assertNotNull(top0);
assertEquals(1, top0.size());
assertTrue(F.viewReadOnly(top0, NODE_2ID).contains(id0));
assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id1));
assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id2));
assertFalse(F.viewReadOnly(top0, NODE_2ID).contains(id3));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridDiscoveryEventSelfTest method testConcurrentJoinEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testConcurrentJoinEvents() throws Exception {
try {
Ignite g0 = startGrid(0);
UUID id0 = g0.cluster().localNode().id();
final ConcurrentMap<Integer, Collection<ClusterNode>> evts = new ConcurrentHashMap<>();
g0.events().localListen(new IgnitePredicate<Event>() {
private AtomicInteger cnt = new AtomicInteger();
@Override
public boolean apply(Event evt) {
assert evt.type() == EVT_NODE_JOINED : evt;
X.println(">>>>>>> Joined " + F.viewReadOnly(((DiscoveryEvent) evt).topologyNodes(), NODE_2ID));
evts.put(cnt.getAndIncrement(), ((DiscoveryEvent) evt).topologyNodes());
return true;
}
}, EVT_NODE_JOINED);
U.sleep(100);
startGridsMultiThreaded(1, 10);
U.sleep(100);
assertEquals(10, evts.size());
for (int i = 0; i < 10; i++) {
Collection<ClusterNode> snapshot = evts.get(i);
assertEquals(2 + i, snapshot.size());
assertTrue(F.viewReadOnly(snapshot, NODE_2ID).contains(id0));
for (ClusterNode n : snapshot) assertTrue("Wrong node order in snapshot [i=" + i + ", node=" + n + ']', n.order() <= 2 + i);
}
Collection<UUID> ids = F.viewReadOnly(evts.get(9), NODE_2ID);
for (int i = 1; i <= 10; i++) assertTrue(ids.contains(grid(i).localNode().id()));
} finally {
stopAllGrids();
}
}
Aggregations