use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class IgniteCacheConfigVariationsAbstractTest method afterTest.
/**
* {@inheritDoc}
*/
@Override
protected void afterTest() throws Exception {
Transaction tx = jcache().unwrap(Ignite.class).transactions().tx();
if (tx != null) {
tx.close();
fail("Cache transaction remained after test completion: " + tx);
}
String cacheIsNotEmptyMsg = null;
for (int i = 0; i < gridCount(); i++) {
info("Checking grid: " + i);
while (true) {
try {
final int fi = i;
boolean cacheIsEmpty = GridTestUtils.waitForCondition(// Preloading may happen as nodes leave, so we need to wait.
new GridAbsPredicateX() {
@Override
public boolean applyx() throws IgniteCheckedException {
jcache(fi).removeAll();
if (jcache(fi).size(CachePeekMode.ALL) > 0) {
for (Cache.Entry<?, ?> k : jcache(fi).localEntries()) jcache(fi).remove(k.getKey());
}
int locSize = jcache(fi).localSize(CachePeekMode.ALL);
if (locSize != 0) {
info(">>>>> Debug localSize for grid: " + fi + " is " + locSize);
info(">>>>> Debug ONHEAP localSize for grid: " + fi + " is " + jcache(fi).localSize(CachePeekMode.ONHEAP));
info(">>>>> Debug OFFHEAP localSize for grid: " + fi + " is " + jcache(fi).localSize(CachePeekMode.OFFHEAP));
info(">>>>> Debug PRIMARY localSize for grid: " + fi + " is " + jcache(fi).localSize(CachePeekMode.PRIMARY));
info(">>>>> Debug BACKUP localSize for grid: " + fi + " is " + jcache(fi).localSize(CachePeekMode.BACKUP));
info(">>>>> Debug NEAR localSize for grid: " + fi + " is " + jcache(fi).localSize(CachePeekMode.NEAR));
}
return locSize == 0;
}
}, 10_000);
if (cacheIsEmpty)
assertTrue("Cache is not empty: " + " localSize = " + jcache(fi).localSize(CachePeekMode.ALL) + ", local entries " + entrySet(jcache(fi).localEntries()), cacheIsEmpty);
int primaryKeySize = jcache(i).localSize(CachePeekMode.PRIMARY);
int keySize = jcache(i).localSize();
int size = jcache(i).localSize();
int globalSize = jcache(i).size();
int globalPrimarySize = jcache(i).size(CachePeekMode.PRIMARY);
info("Size after [idx=" + i + ", size=" + size + ", keySize=" + keySize + ", primarySize=" + primaryKeySize + ", globalSize=" + globalSize + ", globalPrimarySize=" + globalPrimarySize + ", entrySet=" + jcache(i).localEntries() + ']');
if (!cacheIsEmpty) {
cacheIsNotEmptyMsg = "Cache is not empty: localSize = " + jcache(fi).localSize(CachePeekMode.ALL) + ", local entries " + entrySet(jcache(fi).localEntries());
break;
}
assertEquals("Cache is not empty [idx=" + i + ", entrySet=" + jcache(i).localEntries() + ']', 0, jcache(i).localSize(CachePeekMode.ALL));
break;
} catch (Exception e) {
if (X.hasCause(e, ClusterTopologyCheckedException.class)) {
info("Got topology exception while tear down (will retry in 1000ms).");
U.sleep(1000);
} else
throw e;
}
}
if (cacheIsNotEmptyMsg != null)
break;
}
assert jcache().unwrap(Ignite.class).transactions().tx() == null;
if (cacheIsNotEmptyMsg == null)
assertEquals("Cache is not empty", 0, jcache().localSize(CachePeekMode.ALL));
storeStgy.resetStore();
// Restore cache if current cache has garbage.
if (cacheIsNotEmptyMsg != null) {
for (int i = 0; i < gridCount(); i++) {
info("Destroing cache on grid: " + i);
IgniteCache<String, Integer> cache = jcache(i);
assert i != 0 || cache != null;
if (cache != null)
cache.destroy();
}
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@Override
public boolean applyx() {
for (int i = 0; i < gridCount(); i++) {
if (jcache(i) != null)
return false;
}
return true;
}
}, 10_000));
startCachesDinamically();
log.warning(cacheIsNotEmptyMsg);
throw new IllegalStateException(cacheIsNotEmptyMsg);
}
assertEquals(0, jcache().localSize());
assertEquals(0, jcache().size());
}
Aggregations