ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [02/50] [abbrv] incubator-ignite git commit: IGNITE-96 - Fixed Full API test.
Date Thu, 12 Feb 2015 10:33:44 GMT
IGNITE-96 - Fixed Full API test.


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

Branch: refs/heads/ignite-82
Commit: 2dd61e076bc72ad3658d2b978aff458ca350e688
Parents: 7a35d38
Author: Alexey Goncharuk <agoncharuk@gridgain.com>
Authored: Tue Feb 10 15:30:44 2015 -0800
Committer: Alexey Goncharuk <agoncharuk@gridgain.com>
Committed: Tue Feb 10 15:30:44 2015 -0800

----------------------------------------------------------------------
 .../processors/cache/GridCacheMapEntry.java     |  51 +--
 .../colocated/GridDhtDetachedCacheEntry.java    |   3 -
 .../cache/GridCacheAbstractFullApiSelfTest.java |  83 ++--
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 403 +++++++++++--------
 ...achePartitionedMultiNodeFullApiSelfTest.java |   8 +-
 .../junits/common/GridCommonAbstractTest.java   |   4 +-
 6 files changed, 335 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 5802227..9a18247 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -57,9 +57,6 @@ import static org.apache.ignite.transactions.IgniteTxState.*;
     "NonPrivateFieldAccessedInSynchronizedContext", "TooBroadScope", "FieldAccessedSynchronizedAndUnsynchronized"})
 public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K, V>
{
     /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
     private static final sun.misc.Unsafe UNSAFE = GridUnsafe.unsafe();
 
     /** */
@@ -1165,8 +1162,6 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                     subjId, null, taskName);
             }
 
-            CacheMode mode = cctx.config().getCacheMode();
-
             if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local()
&& !isNear()))
                 cctx.continuousQueries().onEntryUpdate(this, key, val, valueBytesUnlocked(),
old, oldBytes, false);
 
@@ -1326,8 +1321,6 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                         null, taskName);
                 }
 
-                CacheMode mode = cctx.config().getCacheMode();
-
                 if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local()
&& !isNear()))
                     cctx.continuousQueries().onEntryUpdate(this, key, null, null, old, oldBytes,
false);
 
@@ -1674,16 +1667,12 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
             if (isNew())
                 unswap(true, retval);
 
-            boolean newTtlResolved = false;
-
-            boolean drNeedResolve = false;
-
             Object transformClo = null;
 
             if (drResolve) {
                 GridCacheVersion oldDrVer = version().drVersion();
 
-                drNeedResolve = cctx.conflictNeedResolve(oldDrVer, drVer);
+                boolean drNeedResolve = cctx.conflictNeedResolve(oldDrVer, drVer);
 
                 if (drNeedResolve) {
                     // Get old value.
@@ -1714,8 +1703,6 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                         newExpireTime = CU.toExpireTime(newTtl);
                     }
 
-                    newTtlResolved = true;
-
                     GridCacheVersionedEntryEx<K, V> oldEntry = versionedEntry();
                     GridCacheVersionedEntryEx<K, V> newEntry =
                         new GridCachePlainVersionedEntry<>(k, (V)writeObj, newTtl,
newExpireTime, drVer);
@@ -1870,7 +1857,7 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                             expiryPlc.ttlUpdated(key,
                                 getOrMarshalKeyBytes(),
                                 version(),
-                                hasReaders() ? ((GridDhtCacheEntry) this).readers() : null);
+                                hasReaders() ? ((GridDhtCacheEntry<K, V>) this).readers()
: null);
                         }
                     }
 
@@ -4349,20 +4336,38 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
         }
 
         /** {@inheritDoc} */
+        @SuppressWarnings("unchecked")
         @Override public V getValue() {
-            for (;;) {
-                GridCacheEntryEx<K, V> e = cctx.cache().peekEx(key);
+            try {
+                IgniteInternalTx<K, V> tx = cctx.tm().userTx();
 
-                if (e == null)
-                    return null;
+                if (tx != null) {
+                    GridTuple<V> peek = tx.peek(cctx, false, key, null);
 
-                try {
-                    return e.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
+                    if (peek != null)
+                        return peek.get();
                 }
-                catch (GridCacheEntryRemovedException ignored) {
-                    // No-op.
+
+                if (detached())
+                    return rawGet();
+
+                for (;;) {
+                    GridCacheEntryEx<K, V> e = cctx.cache().peekEx(key);
+
+                    if (e == null)
+                        return null;
+
+                    try {
+                        return e.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
+                    }
+                    catch (GridCacheEntryRemovedException ignored) {
+                        // No-op.
+                    }
                 }
             }
+            catch (GridCacheFilterFailedException ignored) {
+                throw new IgniteException("Should never happen.");
+            }
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
index 25d35fc..549e552 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtDetachedCacheEntry.java
@@ -28,9 +28,6 @@ import org.jetbrains.annotations.*;
  * Detached cache entry.
  */
 public class GridDhtDetachedCacheEntry<K, V> extends GridDistributedCacheEntry<K,
V> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
     /**
      * @param ctx Cache context.
      * @param key Cache key.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/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 a292655..6863835 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
@@ -162,6 +162,13 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
     }
 
     /**
+     * @return A not near-only cache.
+     */
+    protected IgniteCache<String, Integer> fullCache() {
+        return jcache();
+    }
+
+    /**
      * @throws Exception In case of error.
      */
     public void testSize() throws Exception {
@@ -1566,14 +1573,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             IgniteFuture<Integer> fut1 = cacheAsync.future();
 
             assert fut1.get() == null;
-            assert cache.get("key") != null && cache.get("key") == 1;
+            assertEquals((Integer)1, cache.get("key"));
 
             cacheAsync.getAndPutIfAbsent("key", 2);
 
             IgniteFuture<Integer> fut2 = cacheAsync.future();
 
-            assert fut2.get() != null && fut2.get() == 1;
-            assert cache.get("key") != null && cache.get("key") == 1;
+            assertEquals((Integer)1, fut2.get());
+            assertEquals((Integer)1, cache.get("key"));
 
             if (tx != null)
                 tx.commit();
@@ -2987,20 +2994,23 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         final String key = primaryKeysForCache(jcache(), 1).get(0);
 
-        if (oldEntry)
-            c.put(key, 1);
-
-        GridCacheAdapter<Object, Object> internalCache = ((IgniteKernal)grid(0)).internalCache();
+        GridCacheAdapter<String, Integer> internalCache = internalCache(fullCache());
 
         if (internalCache.isNear())
             internalCache = internalCache.context().near().dht();
 
-        GridCacheEntryEx entry = internalCache.peekEx(key);
+        GridCacheEntryEx entry;
 
-        assert entry != null;
+        if (oldEntry) {
+            c.put(key, 1);
 
-        assertEquals(0, entry.ttl());
-        assertEquals(0, entry.expireTime());
+            entry = internalCache.peekEx(key);
+
+            assert entry != null;
+
+            assertEquals(0, entry.ttl());
+            assertEquals(0, entry.expireTime());
+        }
 
         long startTime = System.currentTimeMillis();
 
@@ -3015,10 +3025,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 tx.rollback();
             }
 
-            entry = internalCache.peekEx(key);
+            if (oldEntry) {
+                entry = internalCache.peekEx(key);
 
-            assertEquals(0, entry.ttl());
-            assertEquals(0, entry.expireTime());
+                assertEquals(0, entry.ttl());
+                assertEquals(0, entry.expireTime());
+            }
         }
 
         // Now commit transaction and check that ttl and expire time have been saved.
@@ -3039,8 +3051,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                GridCacheEntryEx<Object, Object> curEntry =
-                    internalCache.peekEx(key);
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
+
+                GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);
 
                 assertEquals(ttl, curEntry.ttl());
 
@@ -3068,8 +3084,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                GridCacheEntryEx<Object, Object> curEntry =
-                    internalCache.peekEx(key);
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
+
+                GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);
 
                 assertEquals(ttl, curEntry.ttl());
 
@@ -3097,8 +3117,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                GridCacheEntryEx<Object, Object> curEntry =
-                    internalCache.peekEx(key);
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
+
+                GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);
 
                 assertEquals(ttl, curEntry.ttl());
 
@@ -3130,8 +3154,12 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                GridCacheEntryEx<Object, Object> curEntry =
-                    internalCache.peekEx(key);
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
+
+                GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);
 
                 assertEquals(ttl, curEntry.ttl());
                 assertEquals(expireTimes[i], curEntry.expireTime());
@@ -3143,7 +3171,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
             @SuppressWarnings("unchecked")
-            @Override public boolean applyx() throws IgniteCheckedException {
+            @Override public boolean applyx() {
                 try {
                     Integer val = c.get(key);
 
@@ -3173,11 +3201,16 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
         if (internalCache.isLocal())
             return;
 
+        assert c.get(key) == null;
+
+        internalCache = internalCache(fullCache());
+
+        if (internalCache.isNear())
+            internalCache = internalCache.context().near().dht();
+
         // Ensure that old TTL and expire time are not longer "visible".
         entry = internalCache.peekEx(key);
 
-        assert c.get(key) == null;
-
         assertEquals(0, entry.ttl());
         assertEquals(0, entry.expireTime());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
index 15b56b3..b4f6654 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java
@@ -24,10 +24,14 @@ import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.lang.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.transactions.*;
 
+import javax.cache.expiry.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
@@ -119,7 +123,7 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
     /**
      * @return A not near-only cache.
      */
-    protected IgniteCache<String, Integer> fullCache() {
+    @Override protected IgniteCache<String, Integer> fullCache() {
         return nearIdx == 0 ? jcache(1) : jcache(0);
     }
 
@@ -202,167 +206,242 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
      * @throws Exception
      */
     private void checkReaderTtl(boolean inTx) throws Exception {
-        assert false : "ignite-96";
-
-//        int ttl = 1000;
-//
-//        final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS,
ttl));
-//
-//        final GridCache<String, Integer> c = cache();
-//
-//        final String key = primaryKeysForCache(jcache(), 1).get(0);
-//
-//        c.put(key, 1);
-//
-//        Cache.Entry<String, Integer> entry = c.entry(key);
-//
-//        assert entry != null;
-//
-//        assertEquals(0, entry.timeToLive());
-//        assertEquals(0, entry.expirationTime());
-//
-//        long startTime = System.currentTimeMillis();
-//
-//        int fullIdx = nearIdx == 0 ? 1 : 0;
-//
-//        // Now commit transaction and check that ttl and expire time have been saved.
-//        IgniteTx tx = inTx ? grid(fullIdx).transactions().txStart() : null;
-//
-//        try {
-//            jcache(fullIdx).withExpiryPolicy(expiry).put(key, 1);
-//
-//            if (tx != null)
-//                tx.commit();
-//        }
-//        finally {
-//            if (tx != null)
-//                tx.close();
-//        }
-//
-//        long[] expireTimes = new long[gridCount()];
-//
-//        for (int i = 0; i < gridCount(); i++) {
-//            CacheEntry<String, Integer> curEntry = cache(i).entry(key);
-//
-//            if (curEntry.primary() || curEntry.backup() || i == nearIdx) {
-//                assertEquals(ttl, curEntry.timeToLive());
-//
-//                assert curEntry.expirationTime() > startTime;
-//
-//                expireTimes[i] = curEntry.expirationTime();
-//            }
-//        }
-//
-//        // One more update from the same cache entry to ensure that expire time is shifted
forward.
-//        U.sleep(100);
-//
-//        tx = inTx ? grid(fullIdx).transactions().txStart() : null;
-//
-//        try {
-//            jcache(fullIdx).withExpiryPolicy(expiry).put(key, 2);
-//
-//            if (tx != null)
-//                tx.commit();
-//        }
-//        finally {
-//            if (tx != null)
-//                tx.close();
-//        }
-//
-//        for (int i = 0; i < gridCount(); i++) {
-//            CacheEntry<String, Integer> curEntry = cache(i).entry(key);
-//
-//            if (curEntry.primary() || curEntry.backup() || i == nearIdx) {
-//                assertEquals(ttl, curEntry.timeToLive());
-//
-//                assert curEntry.expirationTime() > expireTimes[i];
-//
-//                expireTimes[i] = curEntry.expirationTime();
-//            }
-//        }
-//
-//        // And one more update to ensure that ttl is not changed and expire time is not
shifted forward.
-//        U.sleep(100);
-//
-//        tx = inTx ? grid(fullIdx).transactions().txStart() : null;
-//
-//        try {
-//            jcache(fullIdx).put(key, 4);
-//        }
-//        finally {
-//            if (tx != null)
-//                tx.commit();
-//        }
-//
-//        for (int i = 0; i < gridCount(); i++) {
-//            CacheEntry<String, Integer> curEntry = cache(i).entry(key);
-//
-//            if (curEntry.primary() || curEntry.backup() || i == nearIdx) {
-//                assertEquals(ttl, curEntry.timeToLive());
-//                assertEquals(expireTimes[i], curEntry.expirationTime());
-//            }
-//        }
-//
-//        // Avoid reloading from store.
-//        map.remove(key);
-//
-//        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
-//            @SuppressWarnings("unchecked")
-//            @Override public boolean applyx() throws IgniteCheckedException {
-//                try {
-//                    Integer val = c.get(key);
-//
-//                    if (val != null) {
-//                        info("Value is in cache [key=" + key + ", val=" + val + ']');
-//
-//                        return false;
-//                    }
-//
-//                    // Get "cache" field from GridCacheProxyImpl.
-//                    GridCacheAdapter c0 = GridTestUtils.getFieldValue(c, "cache");
-//
-//                    if (!c0.context().deferredDelete()) {
-//                        GridCacheEntryEx e0 = c0.peekEx(key);
-//
-//                        return e0 == null || (e0.rawGet() == null && e0.valueBytes()
== null);
-//                    }
-//                    else
-//                        return true;
-//                }
-//                catch (GridCacheEntryRemovedException e) {
-//                    throw new RuntimeException(e);
-//                }
-//            }
-//        }, Math.min(ttl * 10, getTestTimeout())));
-//
-//        // Ensure that old TTL and expire time are not longer "visible".
-//        entry = c.entry(key);
-//
-//        assert entry.get() == null;
-//
-//        assertEquals(0, entry.timeToLive());
-//        assertEquals(0, entry.expirationTime());
-//
-//        // Ensure that next update will not pick old expire time.
-//
-//        tx = inTx ? c.txStart() : null;
-//
-//        try {
-//            entry.set(10);
-//        }
-//        finally {
-//            if (tx != null)
-//                tx.commit();
-//        }
-//
-//        U.sleep(2000);
-//
-//        entry = c.entry(key);
-//
-//        assertEquals((Integer)10, entry.get());
-//
-//        assertEquals(0, entry.timeToLive());
-//        assertEquals(0, entry.expirationTime());
+        int ttl = 1000;
+
+        final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS,
ttl));
+
+        final GridCache<String, Integer> c = cache();
+
+        final String key = primaryKeysForCache(fullCache(), 1).get(0);
+
+        c.put(key, 1);
+
+        info("Finished first put.");
+
+        {
+            GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
+
+            if (dht.context().isNear())
+                dht = dht.context().near().dht();
+
+            GridCacheEntryEx<String, Integer> entry = dht.peekEx(key);
+
+            assert entry != null;
+
+            assertEquals(0, entry.ttl());
+            assertEquals(0, entry.expireTime());
+        }
+
+        long startTime = System.currentTimeMillis();
+
+        int fullIdx = nearIdx == 0 ? 1 : 0;
+
+        // Now commit transaction and check that ttl and expire time have been saved.
+        IgniteTx tx = inTx ? grid(fullIdx).transactions().txStart() : null;
+
+        try {
+            jcache(fullIdx).withExpiryPolicy(expiry).put(key, 1);
+
+            if (tx != null)
+                tx.commit();
+        }
+        finally {
+            if (tx != null)
+                tx.close();
+        }
+
+        long[] expireTimes = new long[gridCount()];
+
+        for (int i = 0; i < gridCount(); i++) {
+            info("Checking grid: " + grid(i).localNode().id());
+
+            GridCacheEntryEx<String, Integer> entry = null;
+
+            if (cache(i).affinity().isPrimaryOrBackup(grid(i).localNode(), key)) {
+                GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
+
+                if (dht.context().isNear())
+                    dht = dht.context().near().dht();
+
+                entry = dht.peekEx(key);
+
+                assert entry != null;
+            }
+            else if (i == nearIdx) {
+                GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
+
+                entry = near.peekEx(key);
+
+                assert entry != null;
+            }
+
+            if (entry != null) {
+                assertEquals(ttl, entry.ttl());
+                assert entry.expireTime() > startTime;
+                expireTimes[i] = entry.expireTime();
+            }
+        }
+
+        // One more update from the same cache entry to ensure that expire time is shifted
forward.
+        U.sleep(100);
+
+        tx = inTx ? grid(fullIdx).transactions().txStart() : null;
+
+        try {
+            jcache(fullIdx).withExpiryPolicy(expiry).put(key, 2);
+
+            if (tx != null)
+                tx.commit();
+        }
+        finally {
+            if (tx != null)
+                tx.close();
+        }
+
+        for (int i = 0; i < gridCount(); i++) {
+            GridCacheEntryEx<String, Integer> entry = null;
+
+            if (cache(i).affinity().isPrimaryOrBackup(grid(i).localNode(), key)) {
+                GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
+
+                if (dht.context().isNear())
+                    dht = dht.context().near().dht();
+
+                entry = dht.peekEx(key);
+
+                assert entry != null;
+            }
+            else if (i == nearIdx) {
+                GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
+
+                entry = near.peekEx(key);
+
+                assert entry != null;
+            }
+
+            if (entry != null) {
+                assertEquals(ttl, entry.ttl());
+                assert entry.expireTime() > expireTimes[i];
+                expireTimes[i] = entry.expireTime();
+            }
+        }
+
+        // And one more update to ensure that ttl is not changed and expire time is not shifted
forward.
+        U.sleep(100);
+
+        tx = inTx ? grid(fullIdx).transactions().txStart() : null;
+
+        try {
+            jcache(fullIdx).put(key, 4);
+        }
+        finally {
+            if (tx != null)
+                tx.commit();
+        }
+
+        for (int i = 0; i < gridCount(); i++) {
+            GridCacheEntryEx<String, Integer> entry = null;
+
+            if (cache(i).affinity().isPrimaryOrBackup(grid(i).localNode(), key)) {
+                GridCacheAdapter<String, Integer> dht = internalCache(jcache(i));
+
+                if (dht.context().isNear())
+                    dht = dht.context().near().dht();
+
+                entry = dht.peekEx(key);
+
+                assert entry != null;
+            }
+            else if (i == nearIdx) {
+                GridCacheAdapter<String, Integer> near = internalCache(jcache(i));
+
+                entry = near.peekEx(key);
+
+                assert entry != null;
+            }
+
+            if (entry != null) {
+                assertEquals(ttl, entry.ttl());
+                assertEquals(expireTimes[i], entry.expireTime());
+            }
+        }
+
+        // Avoid reloading from store.
+        map.remove(key);
+
+        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
+            @SuppressWarnings("unchecked")
+            @Override public boolean applyx() throws IgniteCheckedException {
+                try {
+                    Integer val = c.get(key);
+
+                    if (val != null) {
+                        info("Value is in cache [key=" + key + ", val=" + val + ']');
+
+                        return false;
+                    }
+
+                    // Get "cache" field from GridCacheProxyImpl.
+                    GridCacheAdapter c0 = GridTestUtils.getFieldValue(c, "cache");
+
+                    if (!c0.context().deferredDelete()) {
+                        GridCacheEntryEx e0 = c0.peekEx(key);
+
+                        return e0 == null || (e0.rawGet() == null && e0.valueBytes()
== null);
+                    }
+                    else
+                        return true;
+                }
+                catch (GridCacheEntryRemovedException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }, Math.min(ttl * 10, getTestTimeout())));
+
+        // Ensure that old TTL and expire time are not longer "visible".
+        {
+            GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
+
+            if (dht.context().isNear())
+                dht = dht.context().near().dht();
+
+            GridCacheEntryEx<String, Integer> entry = dht.peekEx(key);
+
+            assert entry != null;
+
+            assertEquals(0, entry.ttl());
+            assertEquals(0, entry.expireTime());
+        }
+
+        // Ensure that next update will not pick old expire time.
+        tx = inTx ? c.txStart() : null;
+
+        try {
+            c.put(key, 10);
+
+            if (tx != null)
+                tx.commit();
+        }
+        finally {
+            if (tx != null)
+                tx.close();
+        }
+
+        U.sleep(2000);
+
+        {
+            GridCacheAdapter<String, Integer> dht = internalCache(fullCache());
+
+            if (dht.context().isNear())
+                dht = dht.context().near().dht();
+
+            GridCacheEntryEx<String, Integer> entry = dht.peekEx(key);
+
+            assert entry != null;
+
+            assertEquals(0, entry.ttl());
+            assertEquals(0, entry.expireTime());
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
index 538b5a4..4af2550 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
@@ -236,11 +236,12 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
                 assertEquals((Integer)1, c.localPeek("key", BACKUP));
             }
             else if (!c.unwrap(Ignite.class).affinity(null).isPrimaryOrBackup(grid(i).localNode(),
"key")) {
+                // Initialize near reader.
+                assertEquals((Integer)1, jcache(i).get("key"));
+
                 assertEquals(nearPeekVal, c.localPeek("key", NEAR));
 
                 assertNull(c.localPeek("key", PRIMARY, BACKUP));
-
-                assertEquals((Integer)1, jcache(i).get("key"));
             }
         }
     }
@@ -264,6 +265,9 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
                 assert c.peek("key", Arrays.asList(PARTITIONED_ONLY)) == 1;
             }
             else if (!c.affinity().isPrimaryOrBackup(grid(i).localNode(), "key")) {
+                // Initialize near reader.
+                assertEquals((Integer)1, jcache(i).get("key"));
+
                 assertEquals(nearPeekVal, c.peek("key", Arrays.asList(NEAR_ONLY)));
 
                 assert c.peek("key", Arrays.asList(PARTITIONED_ONLY)) == null;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2dd61e07/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index eb005e2..40bb49f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -121,8 +121,8 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest
{
     /**
      * @param cache Cache.
      */
-    protected <K, V> GridCache<K, V> internalCache(IgniteCache<K, V> cache)
{
-        return ((IgniteKernal)cache.unwrap(Ignite.class)).cache(cache.getName());
+    protected <K, V> GridCacheAdapter<K, V> internalCache(IgniteCache<K, V>
cache) {
+        return ((IgniteKernal)cache.unwrap(Ignite.class)).internalCache(cache.getName());
     }
 
     /**


Mime
View raw message