use of org.apache.ignite.events.Event in project ignite by apache.
the class IgniteCacheClientNodePartitionsExchangeTest method testSkipPreload.
/**
* @throws Exception If failed.
*/
public void testSkipPreload() throws Exception {
Ignite ignite0 = startGrid(0);
final CountDownLatch evtLatch0 = new CountDownLatch(1);
ignite0.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
log.info("Rebalance event: " + evt);
evtLatch0.countDown();
return true;
}
}, EventType.EVT_CACHE_REBALANCE_STARTED, EventType.EVT_CACHE_REBALANCE_STOPPED);
client = true;
Ignite ignite1 = startGrid(1);
assertTrue(evtLatch0.await(1000, TimeUnit.MILLISECONDS));
ignite1.close();
assertTrue(evtLatch0.await(1000, TimeUnit.MILLISECONDS));
ignite1 = startGrid(1);
final CountDownLatch evtLatch1 = new CountDownLatch(1);
ignite1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
log.info("Rebalance event: " + evt);
evtLatch1.countDown();
return true;
}
}, EventType.EVT_CACHE_REBALANCE_STARTED, EventType.EVT_CACHE_REBALANCE_STOPPED);
assertTrue(evtLatch0.await(1000, TimeUnit.MILLISECONDS));
client = false;
startGrid(2);
assertTrue(evtLatch0.await(1000, TimeUnit.MILLISECONDS));
assertFalse(evtLatch1.await(1000, TimeUnit.MILLISECONDS));
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridCacheReplicatedPreloadStartStopEventsSelfTest method testStartStopEvents.
/**
* @throws Exception If failed.
*/
public void testStartStopEvents() throws Exception {
Ignite ignite = startGrid(0);
final AtomicInteger preloadStartCnt = new AtomicInteger();
final AtomicInteger preloadStopCnt = new AtomicInteger();
ignite.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event e) {
if (e.type() == EVT_CACHE_REBALANCE_STARTED)
preloadStartCnt.incrementAndGet();
else if (e.type() == EVT_CACHE_REBALANCE_STOPPED)
preloadStopCnt.incrementAndGet();
else
fail("Unexpected event type: " + e.type());
return true;
}
}, EVT_CACHE_REBALANCE_STARTED, EVT_CACHE_REBALANCE_STOPPED);
startGrid(1);
startGrid(2);
startGrid(3);
assertTrue("Unexpected start count: " + preloadStartCnt.get(), preloadStartCnt.get() <= 1);
assertTrue("Unexpected stop count: " + preloadStopCnt.get(), preloadStopCnt.get() <= 1);
}
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 testStopLocalListenByCallback.
/**
* @throws Exception If failed.
*/
public void testStopLocalListenByCallback() throws Exception {
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
grid(0).events().localListen(new P1<Event>() {
@Override
public boolean apply(Event evt) {
info("Local event [" + evt.shortDisplay() + ']');
assertEquals(EVT_JOB_STARTED, evt.type());
cnt.incrementAndGet();
latch.countDown();
return false;
}
}, EVT_JOB_STARTED);
compute(grid(0).cluster().forLocal()).run(F.noop());
assert latch.await(2, SECONDS);
assertEquals(1, cnt.get());
compute(grid(0).cluster().forLocal()).run(F.noop());
U.sleep(500);
assertEquals(1, cnt.get());
}
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);
}
}
Aggregations