Search in sources :

Example 11 with GridAbsPredicateX

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());
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) GridAbsPredicateX(org.apache.ignite.internal.util.lang.GridAbsPredicateX) Ignite(org.apache.ignite.Ignite) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

GridAbsPredicateX (org.apache.ignite.internal.util.lang.GridAbsPredicateX)11 Transaction (org.apache.ignite.transactions.Transaction)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Duration (javax.cache.expiry.Duration)4 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)4 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)4 Ignite (org.apache.ignite.Ignite)4 IgniteCache (org.apache.ignite.IgniteCache)4 Cache (javax.cache.Cache)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 CacheException (javax.cache.CacheException)1 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)1 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)1 EntryProcessorException (javax.cache.processor.EntryProcessorException)1 MutableEntry (javax.cache.processor.MutableEntry)1 IgniteException (org.apache.ignite.IgniteException)1