ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [09/50] [abbrv] incubator-ignite git commit: #IGNITE-53: Add test on clearing iterators.
Date Mon, 26 Jan 2015 10:01:50 GMT
#IGNITE-53: Add test on clearing iterators.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/eb745313
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/eb745313
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/eb745313

Branch: refs/heads/ignite-86
Commit: eb7453139fa5d1249098920a96863c7640600221
Parents: 0b48f37
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jan 19 19:03:23 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jan 19 19:03:23 2015 +0300

----------------------------------------------------------------------
 .../cache/GridCacheAbstractFullApiSelfTest.java | 55 +++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/eb745313/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
index 849e4fc..d0e8d34 100644
--- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheAbstractFullApiSelfTest.java
@@ -18,6 +18,7 @@
 package org.gridgain.grid.kernal.processors.cache;
 
 import com.google.common.collect.*;
+import junit.framework.*;
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
@@ -25,8 +26,10 @@ import org.apache.ignite.events.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.spi.swapspace.inmemory.*;
 import org.apache.ignite.transactions.*;
+import org.gridgain.grid.*;
 import org.gridgain.grid.cache.*;
 import org.gridgain.grid.kernal.*;
+import org.gridgain.grid.kernal.processors.cache.query.*;
 import org.gridgain.grid.util.lang.*;
 import org.gridgain.grid.util.typedef.*;
 import org.gridgain.grid.util.typedef.internal.*;
@@ -5084,7 +5087,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         assertFalse(cache.iterator().hasNext());
 
-        final int SIZE = 100;
+        final int SIZE = 1000;
 
         Map<String, Integer> entries = new HashMap<>();
 
@@ -5100,6 +5103,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         checkIteratorRemove(cache, entries);
 
+        checkIteratorEmpty(cache);
+
     }
 
     /**
@@ -5203,6 +5208,54 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
     }
 
     /**
+     * Checks iterators are cleared.
+     */
+    private void checkIteratorsCleared() {
+        for (int j = 0; j < gridCount(); j++) {
+
+            GridCacheQueryManager queries = context(j).queries();
+
+            Map map = GridTestUtils.getFieldValue(queries, GridCacheQueryManager.class, "qryIters");
+
+            for (Object obj : map.values())
+                assertEquals("Iterators not removed for grid " + j, 0, ((Map) obj).size());
+        }
+    }
+
+    /**
+     * Checks iterators are cleared after using.
+     */
+    private void checkIteratorEmpty(IgniteCache<String, Integer> cache) throws GridInterruptedException,
InterruptedException {
+        int cnt = 5;
+
+        for (int i = 0; i < cnt; ++i) {
+            Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
+
+            iter.next();
+
+            assert iter.hasNext();
+        }
+
+        System.gc();
+
+        for (int i = 0; i < 10; i++) {
+            try {
+                cache.size(); // Trigger weak queue poll.
+
+                checkIteratorsCleared();
+            }
+            catch (AssertionFailedError e) {
+                if (i == 9)
+                    throw e;
+
+                log.info("Set iterators not cleared, will wait");
+
+                Thread.sleep(500);
+            }
+        }
+    }
+
+    /**
      * @param cache Cache.
      * @param cnt Keys count.
      * @return Collection of keys for which given cache is primary.


Mime
View raw message