use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventConsumeSelfTest method testAllEvents.
/**
* @throws Exception If failed.
*/
public void testAllEvents() 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>() {
@Override
public boolean apply(UUID nodeId, Event evt) {
info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
if (evt.type() == EVT_JOB_STARTED) {
nodeIds.add(nodeId);
cnt.incrementAndGet();
latch.countDown();
}
return true;
}
}, null);
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 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 testLocalNodeOnly.
/**
* @throws Exception If failed.
*/
public void testLocalNodeOnly() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
UUID consumeId = events(grid(0).cluster().forLocal()).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 true;
}
}, 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());
assertEquals(grid(0).localNode().id(), F.first(nodeIds));
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventConsumeSelfTest method testApi.
/**
* @throws Exception If failed.
*/
public void testApi() throws Exception {
try {
grid(0).events().stopRemoteListen(null);
} catch (NullPointerException ignored) {
// No-op.
}
grid(0).events().stopRemoteListen(UUID.randomUUID());
UUID consumeId = null;
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
}, EVTS_DISCOVERY);
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {
@Override
public boolean apply(UUID uuid, Event evt) {
return false;
}
}, new P1<Event>() {
@Override
public boolean apply(Event e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventConsumeSelfTest method testNodeJoinWithProjection.
/**
* @throws Exception If failed.
*/
public void testNodeJoinWithProjection() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(GRID_CNT);
UUID consumeId = events(grid(0).cluster().forAttribute("include", null)).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 true;
}
}, null, EVT_JOB_STARTED);
try {
assertNotNull(consumeId);
include = true;
startGrid("anotherGrid1");
include = false;
startGrid("anotherGrid2");
grid(0).compute().broadcast(F.noop());
assert latch.await(2, SECONDS);
assertEquals(GRID_CNT, nodeIds.size());
assertEquals(GRID_CNT, cnt.get());
} finally {
stopGrid("anotherGrid1");
stopGrid("anotherGrid2");
grid(0).events().stopRemoteListen(consumeId);
}
}
Aggregations