IGNITE-52 - Tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6734ef3c Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6734ef3c Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6734ef3c Branch: refs/heads/sprint-1 Commit: 6734ef3c8d94da2cab6a76d534f5295fd528f9ad Parents: f14e1aa Author: Alexey Goncharuk <agoncha...@gridgain.com> Authored: Tue Jan 27 16:13:14 2015 -0800 Committer: Alexey Goncharuk <agoncha...@gridgain.com> Committed: Tue Jan 27 16:13:14 2015 -0800 ---------------------------------------------------------------------- .../processors/cache/GridCacheAdapter.java | 12 +++++-- .../cache/distributed/dht/GridDhtGetFuture.java | 3 +- .../transactions/IgniteTxLocalAdapter.java | 38 +++++++++++--------- .../IgniteCacheContainsKeyAbstractSelfTest.java | 5 ++- ...CacheContainsKeyColocatedAtomicSelfTest.java | 33 +++++++++++++++++ ...gniteCacheContainsKeyNearAtomicSelfTest.java | 28 +++++++++++++++ .../IgniteCacheContainsKeyNearSelfTest.java | 23 ++++++++++++ 7 files changed, 121 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index 4ccafd4..c713c96 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -649,8 +649,16 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>, /** {@inheritDoc} */ @Override public IgniteFuture<Boolean> containsKeyAsync(final K key) { - return getAllAsync(Collections.singletonList(key), false, null, false, null, null, false, false, null, true) - .chain(new CX1<IgniteFuture<Map<K, V>>, Boolean>() { + return getAllAsync( + Collections.singletonList(key), + /*force primary*/false, + /*skip tx*/false, + /*entry*/null, + /*subj id*/null, + /*task name*/null, + /*deserialize portable*/false, + /*skip values*/true + ).chain(new CX1<IgniteFuture<Map<K, V>>, Boolean>() { @Override public Boolean applyx(IgniteFuture<Map<K, V>> fut) throws IgniteCheckedException { return fut.get().get(key) != null; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java index ddbe518..067a1cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtGetFuture.java @@ -320,7 +320,8 @@ public final class GridDhtGetFuture<K, V> extends GridCompoundIdentityFuture<Col // TODO: To fix, check that reader is contained in the list of readers once // TODO: again after the returned future completes - if not, try again. // TODO: Also, why is info read before transactions are complete, and not after? - IgniteFuture<Boolean> f = (!e.deleted() && k.getValue()) ? e.addReader(reader, msgId, topVer) : null; + IgniteFuture<Boolean> f = (!e.deleted() && k.getValue() && skipVals) ? + e.addReader(reader, msgId, topVer) : null; if (f != null) { if (txFut == null) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/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 1d5b42f..836e708 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 @@ -1036,6 +1036,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> * @param missed Map of missed keys. * @param keysCnt Keys count (to avoid call to {@code Collection.size()}). * @param deserializePortable Deserialize portable flag. + * @param skipVals Skip values flag. * @throws IgniteCheckedException If failed. * @return Enlisted keys. */ @@ -1048,7 +1049,9 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> Map<K, V> map, Map<K, GridCacheVersion> missed, int keysCnt, - boolean deserializePortable) throws IgniteCheckedException { + boolean deserializePortable, + boolean skipVals + ) throws IgniteCheckedException { assert !F.isEmpty(keys); assert keysCnt == keys.size(); assert cached == null || F.first(keys).equals(cached.key()); @@ -1070,7 +1073,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> if (key == null) continue; - if (pessimistic() && !readCommitted()) + if (pessimistic() && !readCommitted() && !skipVals) addActiveCache(cacheCtx); IgniteTxKey<K> txKey = cacheCtx.txKey(key); @@ -1093,7 +1096,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> if (cacheCtx.portableEnabled()) val0 = (V)cacheCtx.unwrapPortableIfNeeded(val, !deserializePortable); - map.put(key, val0); + map.put(key, (V)CU.skipValue(val0, skipVals)); } } else { @@ -1119,7 +1122,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> null); if (val != null) { - if (!readCommitted()) + if (!readCommitted() && !skipVals) txEntry.readValue(val); if (!F.isEmpty(txEntry.entryProcessors())) @@ -1130,7 +1133,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> if (cacheCtx.portableEnabled()) val0 = (V)cacheCtx.unwrapPortableIfNeeded(val, !deserializePortable); - map.put(key, val0); + map.put(key, (V)CU.skipValue(val0, skipVals)); } else missed.put(key, txEntry.cached().version()); @@ -1152,10 +1155,10 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> } // First time access within transaction. else { - if (lockKeys == null) + if (lockKeys == null && !skipVals) lockKeys = single ? (Collection<K>)keys : new ArrayList<K>(keysCnt); - if (!single) + if (!single && !skipVals) lockKeys.add(key); while (true) { @@ -1174,7 +1177,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> V val = null; - if (!pessimistic() || readCommitted() || groupLock()) { + if (!pessimistic() || readCommitted() || groupLock() && !skipVals) { IgniteCacheExpiryPolicy accessPlc = optimistic() ? accessPolicy(cacheCtx, txKey, expiryPlc) : null; @@ -1198,7 +1201,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> if (cacheCtx.portableEnabled()) val0 = (V)cacheCtx.unwrapPortableIfNeeded(val, !deserializePortable); - map.put(key, val0); + map.put(key, (V)CU.skipValue(val0, skipVals)); } else missed.put(key, ver); @@ -1207,7 +1210,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> // We must wait for the lock in pessimistic mode. missed.put(key, ver); - if (!readCommitted()) { + if (!readCommitted() && !skipVals) { txEntry = addEntry(READ, val, null, @@ -1319,7 +1322,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> final Map<K, GridCacheVersion> missedMap, @Nullable final Collection<K> redos, final boolean deserializePortable, - boolean skipVals + final boolean skipVals ) { assert redos != null || pessimistic(); @@ -1377,7 +1380,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> nextVer = cctx.versions().next(topologyVersion()); while (true) { - assert txEntry != null || readCommitted() || groupLock(); + assert txEntry != null || readCommitted() || groupLock() || skipVals; GridCacheEntryEx<K, V> e = txEntry == null ? entryEx(cacheCtx, txKey) : txEntry.cached(); @@ -1413,11 +1416,11 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> // In pessimistic mode, we should always be able to set. assert set || !pessimistic(); - if (readCommitted() || groupLock()) { + if (readCommitted() || groupLock() || skipVals) { cacheCtx.evicts().touch(e, topologyVersion()); if (visibleVal != null) - map.put(key, visibleVal); + map.put(key, (V)CU.skipValue(visibleVal, skipVals)); } else { assert txEntry != null; @@ -1516,13 +1519,14 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> retMap, missed, keysCnt, - deserializePortable); + deserializePortable, + skipVals); if (single && missed.isEmpty()) return new GridFinishedFuture<>(cctx.kernalContext(), retMap); // Handle locks. - if (pessimistic() && !readCommitted() && !groupLock()) { + if (pessimistic() && !readCommitted() && !groupLock() && !skipVals) { if (expiryPlc == null) expiryPlc = cacheCtx.expiry(); @@ -1667,7 +1671,7 @@ public abstract class IgniteTxLocalAdapter<K, V> extends IgniteTxAdapter<K, V> } } else { - assert optimistic() || readCommitted() || groupLock(); + assert optimistic() || readCommitted() || groupLock() || skipVals; final Collection<K> redos = new LinkedList<>(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheContainsKeyAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheContainsKeyAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheContainsKeyAbstractSelfTest.java index 28d2c08..a1ec0d7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheContainsKeyAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheContainsKeyAbstractSelfTest.java @@ -69,8 +69,11 @@ public abstract class IgniteCacheContainsKeyAbstractSelfTest extends GridCacheAb cache(0).put(key, 1); - for (int i = 0; i < gridCount(); i++) + for (int i = 0; i < gridCount(); i++) { assertTrue("Invalid result on grid: " + i, cache(i).containsKey(key)); + + assertFalse("Invalid result on grid: " + i, cache(i).containsKey("2")); + } } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyColocatedAtomicSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyColocatedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyColocatedAtomicSelfTest.java new file mode 100644 index 0000000..eb102c2 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyColocatedAtomicSelfTest.java @@ -0,0 +1,33 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.processors.cache.distributed.dht.atomic; + +import org.apache.ignite.cache.*; +import org.apache.ignite.internal.processors.cache.*; + +/** + * + */ +public class IgniteCacheContainsKeyColocatedAtomicSelfTest extends IgniteCacheContainsKeyAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return CacheAtomicityMode.ATOMIC; + } + + /** {@inheritDoc} */ + @Override protected CacheDistributionMode distributionMode() { + return CacheDistributionMode.PARTITIONED_ONLY; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyNearAtomicSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyNearAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyNearAtomicSelfTest.java new file mode 100644 index 0000000..17235b8 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheContainsKeyNearAtomicSelfTest.java @@ -0,0 +1,28 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.processors.cache.distributed.dht.atomic; + +import org.apache.ignite.cache.*; +import org.apache.ignite.internal.processors.cache.*; + +/** + * + */ +public class IgniteCacheContainsKeyNearAtomicSelfTest extends IgniteCacheContainsKeyAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return CacheAtomicityMode.ATOMIC; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6734ef3c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheContainsKeyNearSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheContainsKeyNearSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheContainsKeyNearSelfTest.java new file mode 100644 index 0000000..126eb19 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheContainsKeyNearSelfTest.java @@ -0,0 +1,23 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.internal.processors.cache.distributed.near; + +import org.apache.ignite.cache.*; +import org.apache.ignite.internal.processors.cache.*; + +/** + * + */ +public class IgniteCacheContainsKeyNearSelfTest extends IgniteCacheContainsKeyAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } +}