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:43:42 UTC
[12/12] incubator-ignite git commit: # ignite-53 review
# ignite-53 review
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/39946d07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/39946d07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/39946d07
Branch: refs/heads/ignite-53
Commit: 39946d07698c1493be92192527ed10e7aa16a5c5
Parents: f5039e3
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jan 14 14:43:20 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jan 14 14:43:20 2015 +0300
----------------------------------------------------------------------
.../processors/cache/IgniteCacheProxy.java | 29 ++++++++++--------
.../cache/GridCacheAbstractFullApiSelfTest.java | 31 ++++++++++----------
2 files changed, 33 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39946d07/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 307bb05..7e20204 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
@@ -16,8 +16,7 @@ import org.apache.ignite.cluster.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.resources.*;
import org.gridgain.grid.cache.*;
-import org.gridgain.grid.cache.query.GridCacheQuery;
-import org.gridgain.grid.cache.query.GridCacheQueryFuture;
+import org.gridgain.grid.cache.query.*;
import org.gridgain.grid.kernal.*;
import org.gridgain.grid.kernal.processors.cache.*;
import org.gridgain.grid.util.tostring.*;
@@ -852,9 +851,15 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
}
/** {@inheritDoc} */
- @Override
- public Iterator<Cache.Entry<K, V>> iterator() {
- return new IgniteCacheIterator();
+ @Override public Iterator<Cache.Entry<K, V>> iterator() {
+ GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+ try {
+ return new IgniteCacheIterator();
+ }
+ finally {
+ gate.leave(prev);
+ }
}
/** {@inheritDoc} */
@@ -1069,16 +1074,18 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
}
/**
- * Iterator over the IgniteCacheProxy
+ * Iterator over the cache.
*/
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. */
+ /** Current element. */
private Map.Entry<K, V> curIter;
+ /**
+ *
+ */
public IgniteCacheIterator() {
fut = delegate.queries().createScanQuery(null).execute();
}
@@ -1087,6 +1094,7 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
@Override public boolean hasNext() {
try {
curIter = fut.next();
+
return curIter != null;
}
catch (IgniteCheckedException e) {
@@ -1097,17 +1105,14 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
/** {@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();
}
@@ -1117,7 +1122,7 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
/** {@inheritDoc} */
@Override public void remove() {
try {
- delegate.remove(curIter.getKey(), curIter.getValue());
+ delegate.removex(curIter.getKey());
}
catch (IgniteCheckedException e) {
throw cacheException(e);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39946d07/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 a6e02dd..e2d7ba5 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,7 +24,7 @@ import org.gridgain.grid.util.typedef.internal.*;
import org.gridgain.testframework.*;
import org.jetbrains.annotations.*;
-import javax.cache.Cache;
+import javax.cache.*;
import javax.cache.expiry.*;
import javax.cache.processor.*;
import java.util.*;
@@ -5247,45 +5247,46 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
*/
public void testIgniteCacheIterator() throws Exception {
IgniteCache<String, Integer> cache = jcache(0);
- for (int i = 0; i < gridCount(); ++i) {
+
+ for (int i = 0; i < 100; ++i)
cache.put(Integer.toString(i), i);
- }
- checkIteratorCacheSize(cache, gridCount());
+ checkIteratorCacheSize(cache, 100);
removeCacheIterator(cache);
- checkIteratorCacheSize(cache, gridCount() - 1);
+ checkIteratorCacheSize(cache, 100 - 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 {
+ private void removeCacheIterator(IgniteCache<String, Integer> cache) {
Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
- if (iter.hasNext()) {
+
+ if (iter.hasNext())
iter.remove();
- }
- else {
- assert false;
- }
+ else
+ fail();
}
/**
* @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 {
+ private void checkIteratorCacheSize(IgniteCache<String, Integer> cache, int size) {
Iterator<Cache.Entry<String, Integer>> iter = cache.iterator();
+
int cnt = 0;
+
while (iter.hasNext()) {
iter.next();
+
cnt++;
}
- assert cnt == size;
+
+ assertEquals(size, cnt);
}
}