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