use of org.apache.ignite.events.Event in project ignite by apache.
the class GridCachePartitionedPreloadEventsSelfTest method testForcePreload.
/**
* Test events fired from
* {@link GridDhtForceKeysFuture}
*
* @throws Exception if failed.
*/
public void testForcePreload() throws Exception {
replicatedAffinity = false;
rebalanceDelay = -1;
Ignite g1 = startGrid("g1");
Collection<Integer> keys = new HashSet<>();
IgniteCache<Integer, String> cache = g1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) {
keys.add(i);
cache.put(i, "val");
}
Ignite g2 = startGrid("g2");
Map<ClusterNode, Collection<Object>> keysMap = g1.affinity(DEFAULT_CACHE_NAME).mapKeysToNodes(keys);
Collection<Object> g2Keys = keysMap.get(g2.cluster().localNode());
assertNotNull(g2Keys);
assertFalse("There are no keys assigned to g2", g2Keys.isEmpty());
for (Object key : g2Keys) // Need to force keys loading.
assertEquals("val", g2.cache(DEFAULT_CACHE_NAME).getAndPut(key, "changed val"));
Collection<Event> evts = g2.events().localQuery(F.<Event>alwaysTrue(), EVT_CACHE_REBALANCE_OBJECT_LOADED);
checkPreloadEvents(evts, g2, g2Keys);
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventStorageManager method waitForEvent.
/**
*
* @param timeout Timeout.
* @param c Optional continuation.
* @param p Optional predicate.
* @param types Event types to wait for.
* @return Event.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public Event waitForEvent(long timeout, @Nullable Runnable c, @Nullable final IgnitePredicate<? super Event> p, int... types) throws IgniteCheckedException {
assert timeout >= 0;
final GridFutureAdapter<Event> fut = new GridFutureAdapter<>();
addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
if (p == null || p.apply(evt)) {
fut.onDone(evt);
removeLocalEventListener(this);
}
}
}, types);
try {
if (c != null)
c.run();
} catch (Exception e) {
throw new IgniteCheckedException(e);
}
return fut.get(timeout);
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method warnNoAffinityNodes.
/**
*
*/
private void warnNoAffinityNodes() {
List<String> cachesWithoutNodes = null;
for (String name : cctx.cache().cacheNames()) {
if (discoCache.cacheAffinityNodes(name).isEmpty()) {
if (cachesWithoutNodes == null)
cachesWithoutNodes = new ArrayList<>();
cachesWithoutNodes.add(name);
// Fire event even if there is no client cache started.
if (cctx.gridEvents().isRecordable(EventType.EVT_CACHE_NODES_LEFT)) {
Event evt = new CacheEvent(name, cctx.localNode(), cctx.localNode(), "All server nodes have left the cluster.", EventType.EVT_CACHE_NODES_LEFT, 0, false, null, null, null, null, false, null, false, null, null, null);
cctx.gridEvents().record(evt);
}
}
}
if (cachesWithoutNodes != null) {
StringBuilder sb = new StringBuilder("All server nodes for the following caches have left the cluster: ");
for (int i = 0; i < cachesWithoutNodes.size(); i++) {
String cache = cachesWithoutNodes.get(i);
sb.append('\'').append(cache).append('\'');
if (i != cachesWithoutNodes.size() - 1)
sb.append(", ");
}
U.quietAndWarn(log, sb.toString());
U.quietAndWarn(log, "Must have server nodes for caches to operate.");
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class CacheMetricsForClusterGroupSelfTest method awaitMetricsUpdate.
/**
* Wait for {@link EventType#EVT_NODE_METRICS_UPDATED} event will be receieved.
*/
private void awaitMetricsUpdate() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch((GRID_CNT + 1) * 2);
IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event ignore) {
latch.countDown();
return true;
}
};
for (int i = 0; i < GRID_CNT; i++) grid(i).events().localListen(lsnr, EVT_NODE_METRICS_UPDATED);
latch.await();
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class IgniteCacheGroupsPartitionLossPolicySelfTest method prepareTopology.
/**
* @return Lost partition ID.
* @throws Exception If failed.
*/
private int prepareTopology() throws Exception {
startGrids(4);
final String cacheName = ThreadLocalRandom.current().nextBoolean() ? CACHE_1 : CACHE_2;
Affinity<Object> aff = ignite(0).affinity(cacheName);
for (int i = 0; i < aff.partitions(); i++) {
ignite(0).cache(CACHE_1).put(i, i);
ignite(0).cache(CACHE_2).put(i, i);
}
client = true;
startGrid(4);
client = false;
for (int i = 0; i < 5; i++) info(">>> Node [idx=" + i + ", nodeId=" + ignite(i).cluster().localNode().id() + ']');
awaitPartitionMapExchange();
ClusterNode killNode = ignite(3).cluster().localNode();
int part = -1;
for (int i = 0; i < aff.partitions(); i++) {
if (aff.isPrimary(killNode, i)) {
part = i;
break;
}
}
if (part == -1)
throw new IllegalStateException("No partition on node: " + killNode);
final CountDownLatch[] partLost = new CountDownLatch[3];
// Check events.
for (int i = 0; i < 3; i++) {
final CountDownLatch latch = new CountDownLatch(1);
partLost[i] = latch;
final int part0 = part;
grid(i).events().localListen(new P1<Event>() {
@Override
public boolean apply(Event evt) {
assert evt.type() == EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST;
CacheRebalancingEvent cacheEvt = (CacheRebalancingEvent) evt;
if (cacheEvt.partition() == part0 && F.eq(cacheName, cacheEvt.cacheName())) {
latch.countDown();
// Auto-unsubscribe.
return false;
}
return true;
}
}, EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST);
}
ignite(3).close();
for (CountDownLatch latch : partLost) assertTrue("Failed to wait for partition LOST event", latch.await(10, TimeUnit.SECONDS));
return part;
}
Aggregations