# ignite-91
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e45b390e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e45b390e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e45b390e Branch: refs/heads/sprint-1 Commit: e45b390e167d239b5c3eec88672001639964c31e Parents: a92f084 Author: sboikov <semen.boi...@inria.fr> Authored: Wed Jan 28 23:31:42 2015 +0300 Committer: sboikov <semen.boi...@inria.fr> Committed: Wed Jan 28 23:31:42 2015 +0300 ---------------------------------------------------------------------- .../dht/atomic/GridDhtAtomicCache.java | 4 + .../dht/atomic/GridNearAtomicUpdateFuture.java | 12 +- .../local/atomic/GridLocalAtomicCache.java | 58 +++- .../transactions/IgniteTxLocalAdapter.java | 13 +- .../cache/GridCacheAbstractFullApiSelfTest.java | 289 +++++++++++++++++-- .../dht/GridCacheAtomicFullApiSelfTest.java | 11 +- 6 files changed, 340 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java index 1076041..d2150de 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java @@ -481,6 +481,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { @SuppressWarnings("unchecked") @Override public IgniteFuture<V> removeAsync(K key, @Nullable GridCacheEntryEx<K, V> entry, @Nullable IgnitePredicate<CacheEntry<K, V>>... filter) { + A.notNull(key, "key"); + return removeAllAsync0(Collections.singletonList(key), null, entry, true, false, filter); } @@ -520,6 +522,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> { /** {@inheritDoc} */ @Override public IgniteFuture<Boolean> removeAsync(K key, V val) { + A.notNull(key, "key", val, "val"); + return removexAsync(key, ctx.equalsPeekArray(val)); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java index 6f6f03b..539a462 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java @@ -549,15 +549,19 @@ public class GridNearAtomicUpdateFuture<K, V> extends GridFutureAdapter<Object> // We still can get here if user pass map with single element. if (key == null) { - onDone(new GridCacheReturn<>(null, false)); + NullPointerException err = new NullPointerException("Null key."); - return; + onDone(err); + + throw err; } if (val == null && op != GridCacheOperation.DELETE) { - onDone(new GridCacheReturn<>(null, false)); + NullPointerException err = new NullPointerException("Null value."); - return; + onDone(err); + + throw err; } if (cctx.portableEnabled()) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java index 2c360ba..6e72c84 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java @@ -248,6 +248,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { /** {@inheritDoc} */ @Override public boolean replace(K key, V oldVal, V newVal) throws IgniteCheckedException { + A.notNull(oldVal, "oldVal"); + return putx(key, newVal, ctx.equalsPeekArray(oldVal)); } @@ -442,7 +444,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { /** {@inheritDoc} */ @Override public boolean remove(K key, V val) throws IgniteCheckedException { - A.notNull(key, "key"); + A.notNull(key, "key", val, "val"); ctx.denyOnLocalRead(); @@ -665,9 +667,30 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { /** {@inheritDoc} */ @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll(Set<? extends K> keys, - EntryProcessor<K, V, T> entryProcessor, + final EntryProcessor<K, V, T> entryProcessor, Object... args) throws IgniteCheckedException { - return invokeAllAsync(keys, entryProcessor, args).get(); + A.notNull(keys, "keys", entryProcessor, "entryProcessor"); + + if (keyCheck) + validateCacheKeys(keys); + + ctx.denyOnLocalRead(); + + Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() { + @Override public EntryProcessor apply(K k) { + return entryProcessor; + } + }); + + return (Map<K, EntryProcessorResult<T>>)updateAllInternal(TRANSFORM, + invokeMap.keySet(), + invokeMap.values(), + args, + expiryPerCall(), + true, + false, + null, + ctx.writeThrough()); } /** {@inheritDoc} */ @@ -736,10 +759,26 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { } /** {@inheritDoc} */ + @SuppressWarnings("unchecked") @Override public <T> Map<K, EntryProcessorResult<T>> invokeAll( Map<? extends K, ? extends EntryProcessor<K, V, T>> map, Object... args) throws IgniteCheckedException { - return invokeAllAsync(map, args).get(); + A.notNull(map, "map"); + + if (keyCheck) + validateCacheKeys(map.keySet()); + + ctx.denyOnLocalRead(); + + return (Map<K, EntryProcessorResult<T>>)updateAllInternal(TRANSFORM, + map.keySet(), + map.values(), + args, + expiryPerCall(), + true, + false, + null, + ctx.writeThrough()); } /** {@inheritDoc} */ @@ -910,10 +949,13 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { boolean intercept = ctx.config().getInterceptor() != null; for (K key : keys) { + if (key == null) + throw new NullPointerException("Null key."); + Object val = valsIter != null ? valsIter.next() : null; - if (key == null) - continue; + if (val == null && op != DELETE) + throw new NullPointerException("Null value."); while (true) { GridCacheEntryEx<K, V> entry = null; @@ -1044,7 +1086,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { Object val = valsIter != null ? valsIter.next() : null; if (val == null && op != DELETE) - continue; + throw new NullPointerException("Null value."); try { try { @@ -1394,7 +1436,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> { while (true) { for (K key : keys) { if (key == null) - continue; + throw new NullPointerException("Null key."); GridCacheEntryEx<K, V> entry = entryEx(key); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java index d9c49d8..90e09d1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java @@ -1901,6 +1901,12 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> groupLockSanityCheck(cacheCtx, keys); for (K key : keys) { + if (key == null) { + setRollbackOnly(); + + throw new NullPointerException("Null key."); + } + V val = rmv || lookup == null ? null : lookup.get(key); EntryProcessor entryProcessor = invokeMap == null ? null : invokeMap.get(key); @@ -1930,13 +1936,10 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> drExpireTime = -1L; } - if (key == null) - continue; - if (!rmv && val == null && entryProcessor == null) { - skipped = skip(skipped, key); + setRollbackOnly(); - continue; + throw new NullPointerException("Null value."); } if (cacheCtx.portableEnabled()) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 905f6b4..84a9b31 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -467,7 +467,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract if (tx != null) tx.commit(); - assert cache().getAll(null).isEmpty(); + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache().getAll(null).isEmpty(); + + return null; + } + }, NullPointerException.class, null); + assert cache().getAll(Collections.<String>emptyList()).isEmpty(); Map<String, Integer> map1 = cache().getAll(F.asList("key1", "key2", "key9999")); @@ -494,7 +501,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract if (txEnabled()) { tx = cache().txStart(); - assert cache().getAll(null).isEmpty(); assert cache().getAll(Collections.<String>emptyList()).isEmpty(); map1 = cache().getAll(F.asList("key1", "key2", "key9999")); @@ -660,11 +666,17 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract cache().put("key1", 1); cache().put("key2", 2); - IgniteFuture<Map<String, Integer>> fut1 = cache().getAllAsync(null); + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache().getAllAsync(null); + + return null; + } + }, NullPointerException.class, null); + IgniteFuture<Map<String, Integer>> fut2 = cache().getAllAsync(Collections.<String>emptyList()); IgniteFuture<Map<String, Integer>> fut3 = cache().getAllAsync(F.asList("key1", "key2")); - assert fut1.get().isEmpty(); assert fut2.get().isEmpty(); assert fut3.get().size() == 2 : "Invalid map: " + fut3.get(); assert fut3.get().get("key1") == 1; @@ -988,25 +1000,26 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract }, NullPointerException.class, null); { - Map<String, Integer> m = new HashMap<>(2); - - m.put("key1", 1); - m.put(null, 2); - - // WARN: F.asMap() doesn't work here, because it will throw NPE. - - cache.putAll(m); - } - - { - Set<String> keys = new HashSet<>(2); + final Set<String> keys = new LinkedHashSet<>(2); keys.add("key1"); keys.add(null); - // WARN: F.asSet() doesn't work here, because it will throw NPE. + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.invokeAll(keys, INCR_PROCESSOR); - cache.invokeAll(keys, INCR_PROCESSOR); + return null; + } + }, NullPointerException.class, null); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.invokeAll(F.asSet("key1"), null); + + return null; + } + }, NullPointerException.class, null); } } @@ -1695,32 +1708,139 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract /** * @throws Exception In case of error. */ + public void testNullInTx() throws Exception { + if (!txEnabled()) + return; + + final IgniteCache<String, Integer> cache = jcache(); + + for (int i = 0; i < 100; i++) { + final String key = "key-" + i; + + GridTestUtils.assertThrows(log, new Callable<Void>() { + public Void call() throws Exception { + IgniteTransactions txs = grid(0).transactions(); + + try (IgniteTx tx = txs.txStart()) { + cache.put(key, 1); + + cache.put(null, 2); + + tx.commit(); + } + + return null; + } + }, NullPointerException.class, null); + + assertNull(cache.get(key)); + + cache.put(key, 1); + + assertEquals(1, (int) cache.get(key)); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + public Void call() throws Exception { + IgniteTransactions txs = grid(0).transactions(); + + try (IgniteTx tx = txs.txStart()) { + cache.put(key, 2); + + cache.remove(null); + + tx.commit(); + } + + return null; + } + }, NullPointerException.class, null); + + assertEquals(1, (int) cache.get(key)); + + cache.put(key, 2); + + assertEquals(2, (int)cache.get(key)); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + public Void call() throws Exception { + IgniteTransactions txs = grid(0).transactions(); + + Map<String, Integer> map = new LinkedHashMap<String, Integer>(); + + map.put("k1", 1); + map.put("k2", 2); + map.put(null, 3); + + try (IgniteTx tx = txs.txStart()) { + cache.put(key, 1); + + cache.putAll(map); + + tx.commit(); + } + + return null; + } + }, NullPointerException.class, null); + + assertNull(cache.get("k1")); + assertNull(cache.get("k2")); + + assertEquals(2, (int) cache.get(key)); + + cache.put(key, 3); + + assertEquals(3, (int)cache.get(key)); + } + } + + /** + * @throws Exception In case of error. + */ public void testPutAllWithNulls() throws Exception { - final GridCache<String, Integer> cache = cache(); + final IgniteCache<String, Integer> cache = jcache(); { - Map<String, Integer> m = new HashMap<>(2); + final Map<String, Integer> m = new LinkedHashMap<>(2); m.put("key1", 1); m.put(null, 2); - // WARN: F.asMap() doesn't work here, because it will throw NPE. + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override + public Void call() throws Exception { + cache.putAll(m); - cache.putAll(m); + return null; + } + }, NullPointerException.class, null); - assertNotNull(cache.get("key1")); + cache.put("key1", 1); + + assertEquals(1, (int)cache.get("key1")); } { - Map<String, Integer> m = new HashMap<>(2); + final Map<String, Integer> m = new LinkedHashMap<>(2); m.put("key3", 3); m.put("key4", null); + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override + public Void call() throws Exception { + cache.putAll(m); + + return null; + } + }, NullPointerException.class, null); + + m.put("key4", 4); + cache.putAll(m); - assertNotNull(cache.get("key3")); - assertNull(cache.get("key4")); + assertEquals(3, (int) cache.get("key3")); + assertEquals(4, (int)cache.get("key4")); } assertThrows(log, new Callable<Object>() { @@ -1730,6 +1850,78 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract return null; } }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.getAndPut("key1", null); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.put(null, 1); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.replace(null, 1); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.getAndReplace(null, 1); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.replace("key", null); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.getAndReplace("key", null); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.replace(null, 1, 2); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.replace("key", null, 2); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); + + assertThrows(log, new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + cache.replace("key", 1, null); + + return null; + } + }, NullPointerException.class, A.NULL_MSG_PREFIX); } /** @@ -2498,14 +2690,53 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract * @throws Exception In case of error. */ public void testRemoveAllWithNulls() throws Exception { - GridCache<String, Integer> cache = cache(); + final IgniteCache<String, Integer> cache = jcache(); - Collection<String> c = new LinkedList<>(); + final Set<String> c = new LinkedHashSet<>(); c.add("key1"); c.add(null); - cache.removeAll(c); + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override + public Void call() throws Exception { + cache.removeAll(c); + + return null; + } + }, NullPointerException.class, null); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.removeAll(null); + + return null; + } + }, NullPointerException.class, null); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.remove(null); + + return null; + } + }, NullPointerException.class, null); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.getAndRemove(null); + + return null; + } + }, NullPointerException.class, null); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache.remove("key1", null); + + return null; + } + }, NullPointerException.class, null); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e45b390e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java index 4a817cf..a9cc2e7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheAtomicFullApiSelfTest.java @@ -20,8 +20,10 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; import org.apache.ignite.cache.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.testframework.*; import java.util.*; +import java.util.concurrent.*; import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; @@ -74,7 +76,14 @@ public class GridCacheAtomicFullApiSelfTest extends GridCachePartitionedFullApiS cache().put("key1", 1); cache().put("key2", 2); - assert cache().getAll((Collection<String>)null).isEmpty(); + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + cache().getAll(null).isEmpty(); + + return null; + } + }, NullPointerException.class, null); + assert cache().getAll(Collections.<String>emptyList()).isEmpty(); Map<String, Integer> map1 = cache().getAll(F.asList("key1", "key2", "key9999"));