ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/3] incubator-ignite git commit: #IGNITE-53: wip
Date Thu, 15 Jan 2015 08:55:02 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-53 a0679e014 -> f3c6ec116


#IGNITE-53: wip


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

Branch: refs/heads/ignite-53
Commit: adf6bf9f9ea810beb6e77dde5bd3f36756ba2ea2
Parents: 984ac18
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Thu Jan 15 11:27:52 2015 +0400
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Thu Jan 15 11:27:52 2015 +0400

----------------------------------------------------------------------
 .../processors/cache/IgniteCacheProxy.java      | 66 ++++++++++++--------
 .../cache/GridCacheAbstractFullApiSelfTest.java | 15 ++---
 2 files changed, 47 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/adf6bf9f/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 3d8c75c..6a75ebb 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
@@ -1078,57 +1078,49 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
      */
     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;
+        private GridCacheQueryFuture<Map.Entry<K, V>> fut;
 
         /** Current element. */
-        private Map.Entry<K, V> curIter;
+        private Map.Entry<K, V> curEntry;
 
         /** Next element. */
-        private Map.Entry<K,V> nextIter;
+        private Map.Entry<K,V> nextEntry;
 
-        /**
-         * No-arg constructor.
-         */
-        public IgniteCacheIterator() {
-            fut = delegate.queries().createScanQuery(null).execute();
-
-            try {
-                nextIter = fut.next();
-            }
-            catch (IgniteCheckedException e) {
-                throw cacheException(e);
-            }
-        }
+        /** Init first time. */
+        private boolean firstTime = true;
 
         /** {@inheritDoc} */
         @Override public boolean hasNext() {
-            return nextIter != null;
+            initFirstTime();
+
+            return nextEntry != null;
         }
 
         /** {@inheritDoc} */
         @Override public Entry<K, V> next() {
-            curIter = nextIter;
+            initFirstTime();
 
-            if (curIter == null) {
+            curEntry = nextEntry;
+
+            if (curEntry == null)
                 throw new NoSuchElementException();
-            }
 
             try {
-                nextIter = fut.next();
+                nextEntry = fut.next();
             }
             catch (IgniteCheckedException e) {
-                curIter = null;
+                curEntry = null;
 
                 throw cacheException(e);
             }
 
             return new Cache.Entry<K, V>() {
                 @Override public K getKey() {
-                    return curIter.getKey();
+                    return curEntry.getKey();
                 }
 
                 @Override public V getValue() {
-                    return curIter.getValue();
+                    return curEntry.getValue();
                 }
 
                 @Override public <T> T unwrap(Class<T> clazz) {
@@ -1139,16 +1131,36 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
 
         /** {@inheritDoc} */
         @Override public void remove() {
-            if (curIter == null)
+            if (curEntry == null)
                 throw new IllegalStateException();
 
             try {
-                delegate.removex(curIter.getKey());
+                delegate.removex(curEntry.getKey());
+            }
+            catch (IgniteCheckedException e) {
+                throw cacheException(e);
+            }
+
+            curEntry = null;
+        }
+
+        /**
+         * Initialize fields at first call
+         */
+        private void initFirstTime() {
+            if (!firstTime) {
+                return;
+            }
+
+            firstTime = false;
+            fut = delegate.queries().createScanQuery(null).execute();
+
+            try {
+                nextEntry = fut.next();
             }
             catch (IgniteCheckedException e) {
                 throw cacheException(e);
             }
-            curIter = null;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/adf6bf9f/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 0753ab4..2cf5860 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
@@ -5291,19 +5291,20 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         checkIteratorCache(entries);
 
-        try {
-            //check that we cannot call Iterator.remove() without next().
-            Iterator<Cache.Entry<String, Integer>> iter = jcache(0).iterator();
+        //check that we cannot call Iterator.remove() without next().
+        Iterator<Cache.Entry<String, Integer>> iter = jcache(0).iterator();
 
-            assertTrue(iter.hasNext());
+        assertTrue(iter.hasNext());
 
-            iter.next();
-            iter.remove();
+        iter.next();
+        iter.remove();
+
+        try {
             iter.remove();
 
             fail();
         }
-        catch (Exception e) {
+        catch (IllegalStateException e) {
         }
     }
 


Mime
View raw message