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:49 UTC

[1/3] incubator-ignite git commit: IGNITE-53: Add distributed Cache.iterator

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-53 [created] 84597ce4d


IGNITE-53: Add distributed Cache.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/0054c0d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0054c0d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0054c0d3

Branch: refs/heads/ignite-53
Commit: 0054c0d3e31854a9633a7a8601fdf4c1ca266d47
Parents: aceb586
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jan 14 11:10:25 2015 +0400
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jan 14 11:10:25 2015 +0400

----------------------------------------------------------------------
 .../processors/cache/IgniteCacheProxy.java      | 66 +++++++++++++++++++-
 .../cache/IgniteCacheProxyApiTest.java          |  7 +++
 2 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0054c0d3/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 a985fde..67797cf 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
@@ -14,6 +14,8 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.query.*;
 import org.apache.ignite.lang.*;
 import org.gridgain.grid.cache.*;
+import org.gridgain.grid.cache.query.GridCacheQuery;
+import org.gridgain.grid.cache.query.GridCacheQueryFuture;
 import org.gridgain.grid.kernal.*;
 import org.gridgain.grid.kernal.processors.cache.*;
 import org.gridgain.grid.util.tostring.*;
@@ -777,9 +779,9 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
     }
 
     /** {@inheritDoc} */
-    @Override public Iterator<Cache.Entry<K, V>> iterator() {
-        // TODO IGNITE-1.
-        throw new UnsupportedOperationException();
+    @Override
+    public Iterator<Cache.Entry<K, V>> iterator() {
+        return new IgniteCacheIterator();
     }
 
     /** {@inheritDoc} */
@@ -922,4 +924,62 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
     @Override public String toString() {
         return S.toString(IgniteCacheProxy.class, this);
     }
+
+    /**
+     * Iterator over the IgniteCacheProxy
+     */
+    private class IgniteCacheIterator implements Iterator<Cache.Entry<K, V>> {
+
+        /** Cache query future for all entries in distributed ignite cache. */
+        private final GridCacheQueryFuture<Map.Entry<K, V>> fut;
+
+        /** Current element from all entries in distributed ignite cache. */
+        private Map.Entry<K, V> curIter;
+
+        public IgniteCacheIterator() {
+            fut = delegate.queries().createScanQuery(null).execute();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            try {
+                curIter = fut.next();
+                return curIter != null;
+            } catch (IgniteCheckedException e) {
+                e.printStackTrace();
+                //TODO: ????
+            }
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Entry<K, V> next() {
+            return new Cache.Entry<K, V>() {
+                /** {@inheritDoc} */
+                @Override public K getKey() {
+                    return curIter.getKey();
+                }
+
+                /** {@inheritDoc} */
+                @Override public V getValue() {
+                    return curIter.getValue();
+                }
+
+                /** {@inheritDoc} */
+                @Override public <T> T unwrap(Class<T> clazz) {
+                    throw new IllegalArgumentException();
+                }
+            };
+        }
+
+        /** {@inheritDoc} */
+        @Override public void remove() {
+            try {
+                delegate.remove(curIter.getKey(), curIter.getValue());
+            } catch (IgniteCheckedException e) {
+                //TODO: ???
+                e.printStackTrace();
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0054c0d3/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
new file mode 100644
index 0000000..17c4c9d
--- /dev/null
+++ b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/IgniteCacheProxyApiTest.java
@@ -0,0 +1,7 @@
+package org.gridgain.grid.kernal.processors.cache;
+
+/**
+ * Created by GridGain on 13.01.2015.
+ */
+public class IgniteCacheProxyApiTest {
+}


[3/3] incubator-ignite git commit: Coding guidelines

Posted by sb...@apache.org.
Coding guidelines


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

Branch: refs/heads/ignite-53
Commit: 84597ce4d6ffa235c1f9ce3444d2874de9319df5
Parents: 8733b7c
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jan 14 13:15:57 2015 +0400
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jan 14 13:15:57 2015 +0400

----------------------------------------------------------------------
 .../ignite/internal/processors/cache/IgniteCacheProxy.java     | 6 ++++--
 .../processors/cache/GridCacheAbstractFullApiSelfTest.java     | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/84597ce4/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 333cb33..c6b4aba 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
@@ -945,7 +945,8 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
             try {
                 curIter = fut.next();
                 return curIter != null;
-            } catch (IgniteCheckedException e) {
+            }
+            catch (IgniteCheckedException e) {
                 throw cacheException(e);
             }
         }
@@ -974,7 +975,8 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
         @Override public void remove() {
             try {
                 delegate.remove(curIter.getKey(), curIter.getValue());
-            } catch (IgniteCheckedException e) {
+            }
+            catch (IgniteCheckedException e) {
                 throw cacheException(e);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/84597ce4/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 504a435..4b83532 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
@@ -5260,6 +5260,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
     /**
      * Remove one element from the cache. Throws exception if cache is empty.
+     *
      * @param cache Cache.
      * @throws Exception
      */
@@ -5267,7 +5268,8 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
         if (iter.hasNext()) {
             iter.remove();
-        } else {
+        }
+        else {
             assert false;
         }
     }


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

Posted by sb...@apache.org.
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;
+    }
 }