You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/01/14 12:25:50 UTC

[2/3] incubator-ignite git commit: Add tests for iterator

Add tests for iterator


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

Branch: refs/heads/ignite-53
Commit: 8733b7c98cdf238151f92ee387f6c7dc6ce27af5
Parents: 0054c0d
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jan 14 13:11:30 2015 +0400
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jan 14 13:11:30 2015 +0400

----------------------------------------------------------------------
 .../processors/cache/IgniteCacheProxy.java      |  7 +--
 .../cache/GridCacheAbstractFullApiSelfTest.java | 46 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733b7c9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 67797cf..333cb33 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -946,10 +946,8 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
                 curIter = fut.next();
                 return curIter != null;
             } catch (IgniteCheckedException e) {
-                e.printStackTrace();
-                //TODO: ????
+                throw cacheException(e);
             }
-            return false;
         }
 
         /** {@inheritDoc} */
@@ -977,8 +975,7 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
             try {
                 delegate.remove(curIter.getKey(), curIter.getValue());
             } catch (IgniteCheckedException e) {
-                //TODO: ???
-                e.printStackTrace();
+                throw cacheException(e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8733b7c9/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 54397cc..504a435 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
@@ -24,6 +24,7 @@ import org.gridgain.grid.util.typedef.internal.*;
 import org.gridgain.testframework.*;
 import org.jetbrains.annotations.*;
 
+import javax.cache.Cache;
 import javax.cache.expiry.*;
 import javax.cache.processor.*;
 import java.util.*;
@@ -5240,4 +5241,49 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         throw new IgniteCheckedException("Unable to find " + cnt + " keys as primary for cache.");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIgniteCacheIterator() throws Exception {
+        IgniteCache<String, Integer> cache = jcache(0);
+        for (int i = 0; i < gridCount(); ++i) {
+            cache.put(Integer.toString(i), i);
+        }
+
+        checkIteratorCacheSize(cache, gridCount());
+
+        removeCacheIterator(cache);
+
+        checkIteratorCacheSize(cache, gridCount() - 1);
+    }
+
+    /**
+     * Remove one element from the cache. Throws exception if cache is empty.
+     * @param cache Cache.
+     * @throws Exception
+     */
+    private void removeCacheIterator(IgniteCache<String, Integer> cache) throws Exception {
+        Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
+        if (iter.hasNext()) {
+            iter.remove();
+        } else {
+            assert false;
+        }
+    }
+
+    /**
+     * @param cache Cache.
+     * @param size Expected value of cache's size.
+     * @throws Exception if iteration size is not equal to expected value
+     */
+    private void checkIteratorCacheSize(IgniteCache<String, Integer> cache, int size)  throws Exception {
+        Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
+        int cnt = 0;
+        while (iter.hasNext()) {
+            iter.next();
+            cnt++;
+        }
+        assert cnt == size;
+    }
 }