ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [2/2] ignite git commit: 2224-3
Date Wed, 27 Jan 2016 19:15:29 GMT
2224-3


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

Branch: refs/heads/ignite-2224-3
Commit: fdabdbf9612cce85db3d1eae382e6d337a9273c2
Parents: c5bf586
Author: Anton Vinogradov <av@apache.org>
Authored: Wed Jan 27 22:15:09 2016 +0300
Committer: Anton Vinogradov <av@apache.org>
Committed: Wed Jan 27 22:15:09 2016 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/IgniteCache.java     |   2 +-
 .../processors/cache/GridCacheAdapter.java      |  34 +--
 .../dht/GridPartitionedSingleGetFuture.java     |  23 +-
 .../distributed/near/GridNearGetFuture.java     |  37 +--
 .../local/atomic/GridLocalAtomicCache.java      |   5 +-
 .../transactions/IgniteTxLocalAdapter.java      |  17 +-
 .../processors/cache/CacheGetEntrySeltTest.java | 264 ++++++++++++++-----
 .../cache/CacheReadThroughRestartSelfTest.java  |  20 +-
 .../CacheSerializableTransactionsTest.java      | 230 ++++++++++++++++
 9 files changed, 480 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 696b520..3b06efc 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -392,7 +392,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K,
V>, IgniteAsyncS
      * <code>null</code> value for a key.
      */
     @IgniteAsyncSupported
-    <T> Map<K, EntryProcessorResult<T>> invokeAll(Map<? extends K, ?
extends EntryProcessor<K, V, T>> map,
+    public <T> Map<K, EntryProcessorResult<T>> invokeAll(Map<? extends
K, ? extends EntryProcessor<K, V, T>> map,
         Object... args);
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/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 bbb4a83..ce34680 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
@@ -1636,12 +1636,9 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
         Map<K, CacheEntry<K, V>> res;
 
         if (F.isEmpty(keys)) {
-            res = U.newHashMap(map.size());
+            assert map.isEmpty();
 
-            for (Map.Entry<K, T2<V, GridCacheVersion>> e : map.entrySet())
-                res.put(e.getKey(), new CacheEntryImplEx<>(e.getKey(), e.getValue().get1(),
e.getValue().get2()));
-
-            return res.values();
+            return Collections.emptySet();
         }
 
         res = U.newHashMap(keys.size());
@@ -1900,25 +1897,14 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K,
V
                                     ctx.evicts().touch(entry, topVer);
                             }
                             else {
-                                if (needVer) {
-                                    ctx.addResult(map,
-                                        key,
-                                        res.get1(),
-                                        skipVals,
-                                        keepCacheObjects,
-                                        deserializeBinary,
-                                        true,
-                                        res.get2());
-                                }
-                                else {
-                                    ctx.addResult(map,
-                                        key,
-                                        res.get1(),
-                                        skipVals,
-                                        keepCacheObjects,
-                                        deserializeBinary,
-                                        true);
-                                }
+                                ctx.addResult(map,
+                                    key,
+                                    res.get1(),
+                                    skipVals,
+                                    keepCacheObjects,
+                                    deserializeBinary,
+                                    true,
+                                    needVer ? res.get2() : null);
 
                                 if (tx == null || (!tx.implicit() && tx.isolation()
== READ_COMMITTED))
                                     ctx.evicts().touch(entry, topVer);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
index 5f1688b..01e61bf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedSingleGetFuture.java
@@ -625,26 +625,13 @@ public class GridPartitionedSingleGetFuture extends GridFutureAdapter<Object>
im
             assert !skipVals;
 
             if (val != null) {
-                if (needVer) {
-                    assert ver != null;
+                if (!keepCacheObjects) {
+                    Object res = cctx.unwrapBinaryIfNeeded(val, !deserializeBinary);
 
-                    if (!keepCacheObjects) {
-                        Object res = cctx.unwrapBinaryIfNeeded(val, !deserializeBinary &&
!skipVals);
-
-                        onDone(new T2<>(res, ver));
-                    }
-                    else
-                        onDone(new T2<>(val, ver));
-                }
-                else {
-                    if (!keepCacheObjects) {
-                        Object res = cctx.unwrapBinaryIfNeeded(val, !deserializeBinary);
-
-                        onDone(res);
-                    }
-                    else
-                        onDone(val);
+                    onDone(needVer ? new T2<>(res, ver) : res);
                 }
+                else
+                    onDone(needVer ? new T2<>(val, ver) : val);
             }
             else
                 onDone(null);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
index f7c3f06..06fc0a5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
@@ -650,36 +650,25 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
      */
     @SuppressWarnings("unchecked")
     private void addResult(KeyCacheObject key, CacheObject v, GridCacheVersion ver) {
-        if (needVer) {
-            if (keepCacheObjects) {
-                V val0 = (V)new T2<>(skipVals ? true : v, ver);
+        if (keepCacheObjects) {
+            K key0 = (K)key;
+            V val0 = needVer ?
+                (V)new T2<>(skipVals ? true : v, ver) :
+                (V)(skipVals ? true : v);
 
-                add(new GridFinishedFuture<>(Collections.singletonMap((K)key, val0)));
-            }
-            else {
-                K key0 = (K)cctx.unwrapBinaryIfNeeded(key, !deserializeBinary, false);
-                V val0 = (V)new T2<>(!skipVals ?
-                    (V)cctx.unwrapBinaryIfNeeded(v, !deserializeBinary, false) :
-                    (V)Boolean.TRUE, ver);
-
-                add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
-            }
+            add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
         }
         else {
-            if (keepCacheObjects) {
-                K key0 = (K)key;
-                V val0 = (V)(skipVals ? true : v);
-
-                add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
-            }
-            else {
-                K key0 = (K)cctx.unwrapBinaryIfNeeded(key, !deserializeBinary, false);
-                V val0 = !skipVals ?
+            K key0 = (K)cctx.unwrapBinaryIfNeeded(key, !deserializeBinary, false);
+            V val0 = needVer ?
+                (V)new T2<>(!skipVals ?
+                    (V)cctx.unwrapBinaryIfNeeded(v, !deserializeBinary, false) :
+                    (V)Boolean.TRUE, ver) :
+                !skipVals ?
                     (V)cctx.unwrapBinaryIfNeeded(v, !deserializeBinary, false) :
                     (V)Boolean.TRUE;
 
-                add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
-            }
+            add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/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 942f0a7..fed3e33 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
@@ -589,9 +589,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K,
V> {
                     entry = swapOrOffheap ? entryEx(cacheKey) : peekEx(cacheKey);
 
                     if (entry != null) {
-
-                        CacheObject v = null;
-                        GridCacheVersion ver = null;
+                        CacheObject v ;
+                        GridCacheVersion ver;
 
                         if (needVer) {
                             T2<CacheObject, GridCacheVersion> res = entry.innerGetVersioned(

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/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 3b8992e..b9ae613 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
@@ -1408,12 +1408,17 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
implements Ig
                         GridCacheVersion ver = null;
 
                         if (needVer) {
-                            try {
-                                ver = txEntry.cached().version();
-                            }
-                            catch (GridCacheEntryRemovedException ignored) {
-                                if (log.isDebugEnabled())
-                                    log.debug("Got removed entry in transaction getAllAsync(..)"
+ key);
+                            if (txEntry.op() != READ)
+                                ver = xidVersion();
+                            else {
+                                if (serializable()) {
+                                    ver = txEntry.serializableReadVersion();
+                                }
+                                else
+                                    throw new IgniteCheckedException(
+                                        "Get versioned entry within transaction failed. "
+
+                                            "Transaction should be Optimistic Serializable.
" +
+                                            "[level=" + isolation + ", conc=" + concurrency
+ "]");
                             }
                         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntrySeltTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntrySeltTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntrySeltTest.java
index a9131d9..7ef68c8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntrySeltTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntrySeltTest.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
+import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheEntry;
@@ -28,7 +29,13 @@ import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
 
@@ -45,132 +52,249 @@ public class CacheGetEntrySeltTest extends GridCacheAbstractSelfTest
{
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        CacheConfiguration cacheCfg1 = new CacheConfiguration();
-        cacheCfg1.setCacheMode(CacheMode.PARTITIONED);
-        cacheCfg1.setName("near");
-        cacheCfg1.setNearConfiguration(new NearCacheConfiguration());
+        cfg.setMarshaller(null);
 
-        CacheConfiguration cacheCfg1t = new CacheConfiguration();
-        cacheCfg1t.setCacheMode(CacheMode.PARTITIONED);
-        cacheCfg1t.setAtomicityMode(TRANSACTIONAL);
-        cacheCfg1t.setName("nearT");
-        cacheCfg1t.setNearConfiguration(new NearCacheConfiguration());
+        return cfg;
+    }
 
-        CacheConfiguration cacheCfg2 = new CacheConfiguration();
-        cacheCfg2.setCacheMode(CacheMode.PARTITIONED);
-        cacheCfg2.setName("partitioned");
+    /** */
+    public void testNear() {
+        CacheConfiguration cfg = new CacheConfiguration();
 
-        CacheConfiguration cacheCfg2t = new CacheConfiguration();
-        cacheCfg2t.setCacheMode(CacheMode.PARTITIONED);
-        cacheCfg2t.setAtomicityMode(TRANSACTIONAL);
-        cacheCfg2t.setName("partitionedT");
+        cfg.setCacheMode(CacheMode.PARTITIONED);
+        cfg.setName("near");
+        cfg.setNearConfiguration(new NearCacheConfiguration());
 
-        CacheConfiguration cacheCfg3 = new CacheConfiguration();
-        cacheCfg3.setCacheMode(CacheMode.LOCAL);
-        cacheCfg3.setName("local");
+        test(cfg);
+    }
 
-        CacheConfiguration cacheCfg3t = new CacheConfiguration();
-        cacheCfg3t.setCacheMode(CacheMode.LOCAL);
-        cacheCfg3t.setAtomicityMode(TRANSACTIONAL);
-        cacheCfg3t.setName("localT");
+    /** */
+    public void testNearTransactional() {
+        CacheConfiguration cfg = new CacheConfiguration();
 
-        CacheConfiguration cacheCfg4 = new CacheConfiguration();
-        cacheCfg4.setCacheMode(CacheMode.REPLICATED);
-        cacheCfg4.setName("replicated");
+        cfg.setCacheMode(CacheMode.PARTITIONED);
+        cfg.setAtomicityMode(TRANSACTIONAL);
+        cfg.setName("nearT");
+        cfg.setNearConfiguration(new NearCacheConfiguration());
 
-        CacheConfiguration cacheCfg4t = new CacheConfiguration();
-        cacheCfg4t.setCacheMode(CacheMode.REPLICATED);
-        cacheCfg4t.setAtomicityMode(TRANSACTIONAL);
-        cacheCfg4t.setName("replicatedT");
+        testT(cfg);
+    }
 
-        cfg.setMarshaller(null);
+    /** */
+    public void testPartitioned() {
+        CacheConfiguration cfg = new CacheConfiguration();
+        cfg.setCacheMode(CacheMode.PARTITIONED);
+        cfg.setName("partitioned");
+
+        test(cfg);
+    }
 
-        cfg.setCacheConfiguration(cfg.getCacheConfiguration()[0], cacheCfg1, cacheCfg1t,
cacheCfg2, cacheCfg2t,
-            cacheCfg3, cacheCfg3t, cacheCfg4, cacheCfg4t);
+    /** */
+    public void testPartitionedTransactional() {
+        CacheConfiguration cfg = new CacheConfiguration();
 
-        return cfg;
+        cfg.setCacheMode(CacheMode.PARTITIONED);
+        cfg.setAtomicityMode(TRANSACTIONAL);
+        cfg.setName("partitionedT");
+
+        testT(cfg);
     }
 
-    @Override protected long getTestTimeout() {
-        return Long.MAX_VALUE;
+    /** */
+    public void testLocal() {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setCacheMode(CacheMode.LOCAL);
+        cfg.setName("local");
+
+        test(cfg);
     }
 
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetEntry() throws Exception {
-        test0("near");
-        test0("nearT");
-        test0("partitioned");
-        test0("partitionedT");
-        test0("local");
-        test0("localT");
-        test0("replicated");
-        test0("replicatedT");
+    /** */
+    public void testLocalTransactional() {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setCacheMode(CacheMode.LOCAL);
+        cfg.setAtomicityMode(TRANSACTIONAL);
+        cfg.setName("localT");
+
+        testT(cfg);
+    }
+
+    /** */
+    public void testReplicated() {
+        CacheConfiguration cfg = new CacheConfiguration();
+
+        cfg.setCacheMode(CacheMode.REPLICATED);
+        cfg.setName("replicated");
+
+        test(cfg);
     }
 
-    private void test0(String name) {
-        IgniteCache<Integer, TestValue> cache = grid(0).cache(name);
+    /** */
+    public void testReplicatedTransactional() {
+        CacheConfiguration cfg = new CacheConfiguration();
 
+        cfg.setCacheMode(CacheMode.REPLICATED);
+        cfg.setAtomicityMode(TRANSACTIONAL);
+        cfg.setName("replicatedT");
+
+        testT(cfg);
+    }
+
+    /** */
+    private void testT(CacheConfiguration cfg) {
+        Ignite ignite = grid(0);
+
+        try (IgniteCache<Integer, TestValue> cache = ignite.createCache(cfg)) {
+            init(cache);
+
+            for (TransactionConcurrency txConcurrency : TransactionConcurrency.values())
{
+                for (TransactionIsolation txIsolation : TransactionIsolation.values()) {
+                    try (Transaction tx = ignite.transactions().txStart(txConcurrency, txIsolation,
100000, 1000)) {
+                        try {
+                            testGetEntry(cache);
+
+                            tx.commit();
+                        }
+                        catch (Exception e) {
+                            assert txIsolation == TransactionIsolation.REPEATABLE_READ ||
+                                (txIsolation == TransactionIsolation.SERIALIZABLE &&
+                                    tx.concurrency() == TransactionConcurrency.PESSIMISTIC);
+                        }
+                    }
+
+                    try (Transaction tx = ignite.transactions().txStart(txConcurrency, txIsolation,
100000, 1000)) {
+                        try {
+                            testGetEntries(cache);
+
+                            tx.commit();
+                        }
+                        catch (Exception e) {
+                            assert txIsolation == TransactionIsolation.REPEATABLE_READ ||
+                                (txIsolation == TransactionIsolation.SERIALIZABLE &&
+                                    tx.concurrency() == TransactionConcurrency.PESSIMISTIC);
+                        }
+                    }
+                }
+
+            }
+        }
+    }
+
+    /** */
+    private void test(CacheConfiguration cfg) {
+        try (IgniteCache<Integer, TestValue> cache = grid(0).createCache(cfg)) {
+            init(cache);
+
+            testGetEntry(cache);
+
+            testGetEntries(cache);
+        }
+    }
+
+    /** */
+    private void init(IgniteCache<Integer, TestValue> cache) {
         // Put.
-        for (int i = 0; i < 10_000; ++i)
+        for (int i = 0; i < 100; ++i)
             cache.put(i, new TestValue(i));
+    }
 
+    /** */
+    private void checkVersion(CacheEntry<Integer, ?> e, IgniteCache<Integer, TestValue>
cache) {
+        CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
+
+        if (cfg.getCacheMode() != CacheMode.LOCAL) {
+            Ignite prim = primaryNode(e.getKey(), cache.getName());
+
+            GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal)prim).internalCache(cache.getName());
+
+            if (cfg.getNearConfiguration() != null)
+                cacheAdapter = ((GridNearCacheAdapter)cacheAdapter).dht();
+
+            IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
+
+            CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
+
+            GridCacheMapEntry me = cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx,
e.getKey(), true));
+
+            try {
+                assert me.version().equals(e.version());
+            }
+            catch (GridCacheEntryRemovedException ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+    }
+
+    /** */
+    private void testGetEntry(IgniteCache<Integer, TestValue> cache) {
         // getEntry regular.
-        for (int i = 0; i < 10_000; ++i) {
+        for (int i = 0; i < 100; ++i) {
             CacheEntry<Integer, TestValue> e = cache.getEntry(i);
 
+            checkVersion(e, cache);
+
             assertEquals(e.getValue().val, i);
 
             assertNotNull(e.version());
         }
 
+        IgniteCache<Integer, BinaryObject> cacheB = cache.withKeepBinary();
+
+        // getEntry withKeepBinary.
+        for (int i = 0; i < 100; ++i) {
+            CacheEntry<Integer, BinaryObject> e = cacheB.getEntry(i);
+
+            checkVersion(e, cache);
+
+            assertEquals(((TestValue)e.getValue().deserialize()).val, i);
+
+            assertNotNull(e.version());
+        }
+    }
+
+    /** */
+    private void testGetEntries(IgniteCache<Integer, TestValue> cache) {
         // getEntries regular.
-        for (int i = 0; i < 10_000; ++i) {
+        for (int i = 0; i < 100; i++) {
             Set<Integer> set = new HashSet<>();
 
             for (int j = 0; j < 10; j++)
-                set.add(++i);
+                set.add(i + j);
 
             Collection<CacheEntry<Integer, TestValue>> es = cache.getEntries(set);
 
             for (CacheEntry<Integer, TestValue> e : es) {
+                checkVersion(e, cache);
+
                 assertEquals((Integer)e.getValue().val, e.getKey());
 
-                assertTrue(e.getValue().val <= i);
-                assertTrue(e.getValue().val > i - 10);
+                assertTrue(set.contains(e.getValue().val));
 
                 assertNotNull(e.version());
             }
         }
 
-        IgniteCache<Integer, BinaryObject> cacheB = grid(0).cache(name).withKeepBinary();
-
-        // getEntry withKeepBinary.
-        for (int i = 0; i < 10_000; ++i) {
-            CacheEntry<Integer, BinaryObject> e = cacheB.getEntry(i);
-
-            assertEquals(((TestValue)e.getValue().deserialize()).val, i);
-
-            assertNotNull(e.version());
-        }
+        IgniteCache<Integer, BinaryObject> cacheB = cache.withKeepBinary();
 
         // getEntries withKeepBinary.
-        for (int i = 0; i < 10_000; ++i) {
+        for (int i = 0; i < 100; i++) {
             Set<Integer> set = new HashSet<>();
 
             for (int j = 0; j < 10; j++)
-                set.add(++i);
+                set.add(i + j);
 
             Collection<CacheEntry<Integer, BinaryObject>> es = cacheB.getEntries(set);
 
             for (CacheEntry<Integer, BinaryObject> e : es) {
+                checkVersion(e, cache);
+
                 TestValue tv = e.getValue().deserialize();
 
                 assertEquals((Integer)tv.val, e.getKey());
 
-                assertTrue((tv).val <= i);
-                assertTrue((tv).val > i - 10);
+                assertTrue(set.contains((tv).val));
 
                 assertNotNull(e.version());
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadThroughRestartSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadThroughRestartSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadThroughRestartSelfTest.java
index 8b2055b..e21b76a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadThroughRestartSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheReadThroughRestartSelfTest.java
@@ -167,16 +167,24 @@ public class CacheReadThroughRestartSelfTest extends GridCacheAbstractSelfTest
{
         for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
             for (TransactionIsolation txIsolation : TransactionIsolation.values()) {
                 try (Transaction tx = ignite.transactions().txStart(txConcurrency, txIsolation,
100000, 1000)) {
-                    for (int k = 0; k < 100; k++) {
-                        Set<String> keys = new HashSet<>();
+                    try {
+                        for (int k = 0; k < 100; k++) {
+                            Set<String> keys = new HashSet<>();
 
-                        for (int j = k; j < k + 10; j++)
-                            keys.add("key" + j);
+                            for (int j = k; j < k + 10; j++)
+                                keys.add("key" + j);
 
-                        assertNotNull("Null value for keys: " + k + " - " + k + 9, cache.getEntries(keys));
+                            assertNotNull("Null value for keys: " + k + " - " + k + 9, cache.getEntries(keys));
+                        }
+
+                        tx.commit();
                     }
+                    catch (Exception e) {
+                        assert txIsolation == TransactionIsolation.REPEATABLE_READ ||
+                            (txIsolation == TransactionIsolation.SERIALIZABLE &&
+                                tx.concurrency() == TransactionConcurrency.PESSIMISTIC);
 
-                    tx.commit();
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fdabdbf9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
index 812d571..81f225b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -46,6 +47,7 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteTransactions;
+import org.apache.ignite.cache.CacheEntry;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.store.CacheStore;
@@ -621,6 +623,53 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest
{
     /**
      * @throws Exception If failed.
      */
+    public void testTxCommitReadOnlyGetEntries() throws Exception {
+        Ignite ignite0 = ignite(0);
+
+        final IgniteTransactions txs = ignite0.transactions();
+
+        for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
+            logCacheInfo(ccfg);
+
+            try {
+                IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
+
+                Set<Integer> keys = new HashSet<>();
+
+                for (int i = 0; i < 100; i++)
+                    keys.add(i);
+
+                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                    Collection<CacheEntry<Integer, Integer>> c = cache.getEntries(keys);
+
+                    assertTrue(c.isEmpty());
+
+                    tx.commit();
+                }
+
+                for (Integer key : keys)
+                    checkValue(key, null, cache.getName());
+
+                try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                    Collection<CacheEntry<Integer, Integer>> c = cache.getEntries(keys);
+
+                    assertTrue(c.isEmpty());
+
+                    tx.rollback();
+                }
+
+                for (Integer key : keys)
+                    checkValue(key, null, cache.getName());
+            }
+            finally {
+                destroyCache(ccfg.getName());
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testTxCommitReadWriteTwoNodes() throws Exception {
         Ignite ignite0 = ignite(0);
 
@@ -664,6 +713,20 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntry1() throws Exception {
+        txConflictReadEntry(true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntry2() throws Exception {
+        txConflictReadEntry(false);
+    }
+
+    /**
      * @param noVal If {@code true} there is no cache value when read in tx.
      * @throws Exception If failed.
      */
@@ -728,6 +791,70 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * @param noVal If {@code true} there is no cache value when read in tx.
+     * @throws Exception If failed.
+     */
+    private void txConflictReadEntry(boolean noVal) throws Exception {
+        Ignite ignite0 = ignite(0);
+
+        final IgniteTransactions txs = ignite0.transactions();
+
+        for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
+            logCacheInfo(ccfg);
+
+            try {
+                IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
+
+                List<Integer> keys = testKeys(cache);
+
+                for (Integer key : keys) {
+                    log.info("Test key: " + key);
+
+                    Integer expVal = null;
+
+                    if (!noVal) {
+                        expVal = -1;
+
+                        cache.put(key, expVal);
+                    }
+
+                    try {
+                        try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                            CacheEntry<Integer, Integer> val = cache.getEntry(key);
+
+                            assertEquals(expVal, val == null ? null : val.getValue());
+
+                            updateKey(cache, key, 1);
+
+                            tx.commit();
+                        }
+
+                        fail();
+                    }
+                    catch (TransactionOptimisticException e) {
+                        log.info("Expected exception: " + e);
+                    }
+
+                    checkValue(key, 1, cache.getName());
+
+                    try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                        CacheEntry<Integer, Integer> val = cache.getEntry(key);
+
+                        assertEquals((Integer)1, val.getValue());
+
+                        tx.commit();
+                    }
+
+                    checkValue(key, 1, cache.getName());
+                }
+            }
+            finally {
+                destroyCache(ccfg.getName());
+            }
+        }
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testTxConflictReadWrite1() throws Exception {
@@ -756,6 +883,34 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntryWrite1() throws Exception {
+        txConflictReadEntryWrite(true, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntryWrite2() throws Exception {
+        txConflictReadEntryWrite(false, false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntryRemove1() throws Exception {
+        txConflictReadEntryWrite(true, true);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTxConflictReadEntryRemove2() throws Exception {
+        txConflictReadEntryWrite(false, true);
+    }
+
+    /**
      * @param noVal If {@code true} there is no cache value when read in tx.
      * @param rmv If {@code true} tests remove, otherwise put.
      * @throws Exception If failed.
@@ -831,6 +986,81 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * @param noVal If {@code true} there is no cache value when read in tx.
+     * @param rmv If {@code true} tests remove, otherwise put.
+     * @throws Exception If failed.
+     */
+    private void txConflictReadEntryWrite(boolean noVal, boolean rmv) throws Exception {
+        Ignite ignite0 = ignite(0);
+
+        final IgniteTransactions txs = ignite0.transactions();
+
+        for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
+            logCacheInfo(ccfg);
+
+            try {
+                IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
+
+                List<Integer> keys = testKeys(cache);
+
+                for (Integer key : keys) {
+                    log.info("Test key: " + key);
+
+                    Integer expVal = null;
+
+                    if (!noVal) {
+                        expVal = -1;
+
+                        cache.put(key, expVal);
+                    }
+
+                    try {
+                        try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                            CacheEntry<Integer, Integer> val = cache.getEntry(key);
+
+                            assertEquals(expVal, val == null ? null : val.getValue());
+
+                            updateKey(cache, key, 1);
+
+                            if (rmv)
+                                cache.remove(key);
+                            else
+                                cache.put(key, 2);
+
+                            tx.commit();
+                        }
+
+                        fail();
+                    }
+                    catch (TransactionOptimisticException e) {
+                        log.info("Expected exception: " + e);
+                    }
+
+                    checkValue(key, 1, cache.getName());
+
+                    try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
+                        CacheEntry<Integer, Integer> val = cache.getEntry(key);
+
+                        assertEquals(1, (Object) val.getValue());
+
+                        if (rmv)
+                            cache.remove(key);
+                        else
+                            cache.put(key, 2);
+
+                        tx.commit();
+                    }
+
+                    checkValue(key, rmv ? null : 2, cache.getName());
+                }
+            }
+            finally {
+                destroyCache(ccfg.getName());
+            }
+        }
+    }
+
+    /**
      * @throws Exception If failed
      */
     public void testTxConflictGetAndPut1() throws Exception {


Mime
View raw message