ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [06/28] incubator-ignite git commit: # IGNITE-56 Use IgniteCache in ignite-core module (3).
Date Fri, 06 Feb 2015 14:50:46 GMT
# IGNITE-56 Use IgniteCache in ignite-core module (3).


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

Branch: refs/heads/ignite-160
Commit: c10fad8bdc9e81cbd6d75ce7c9d21bed2682d510
Parents: d6ed718
Author: sevdokimov <sergey.evdokimov@jetbrains.com>
Authored: Mon Feb 2 00:15:16 2015 +0300
Committer: sevdokimov <sergey.evdokimov@jetbrains.com>
Committed: Mon Feb 2 00:15:16 2015 +0300

----------------------------------------------------------------------
 ...tomicClientOnlyMultiNodeFullApiSelfTest.java |  18 +--
 ...eAtomicNearOnlyMultiNodeFullApiSelfTest.java |  22 +--
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 159 ++++++++-----------
 3 files changed, 86 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10fad8b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
index bd6600d..1607d19 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
@@ -92,15 +92,15 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
         int fullCacheSize = 0;
 
         for (int i = 0; i < gridCount(); i++)
-            fullCacheSize += cache(i).primarySize();
+            fullCacheSize += jcache(i).localSize();
 
-        assertEquals("Invalid cache size", 10, fullCacheSize);
+        assertEquals("Invalid cache size", fullCacheSize, cache.size());
     }
 
     /** {@inheritDoc} */
     @Override public void testClear() throws Exception {
         IgniteCache<String, Integer> nearCache = jcache();
-        GridCache<String, Integer> primary = fullCache();
+        IgniteCache<String, Integer> primary = fullCache();
 
         Collection<String> keys = primaryKeysForCache(primary, 3);
 
@@ -135,7 +135,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
     /** {@inheritDoc} */
     @Override public void testClearKeys() throws Exception {
         IgniteCache<String, Integer> nearCache = jcache();
-        GridCache<String, Integer> primary = fullCache();
+        IgniteCache<String, Integer> primary = fullCache();
 
         Collection<String> keys = primaryKeysForCache(primary, 3);
 
@@ -162,7 +162,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
 
         for (String key : subKeys) {
             assertNull(nearCache.localPeek(key));
-            assertNotNull(primary.peek(key));
+            assertNotNull(primary.localPeek(key));
         }
 
         assertEquals(null, nearCache.localPeek(lastKey));
@@ -186,7 +186,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
         Thread.sleep(ttl + 100);
 
         // Expired entry should not be swapped.
-        cache.localEvict(Collections.<String>singleton(key));
+        cache.localEvict(Collections.singleton(key));
 
         assertNull(cache.localPeek(key));
 
@@ -198,8 +198,8 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
 
         // Force reload on primary node.
         for (int i = 0; i < gridCount(); i++) {
-            if (cache(i).entry(key).primary())
-                cache(i).reload(key);
+            if (ignite(i).affinity(null).isPrimary(ignite(i).cluster().localNode(), key))
+                jcache(i).loadAll(Collections.singleton(key), true, null);
         }
 
         // Will do near get request.
@@ -285,7 +285,7 @@ public class GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends
GridCache
     @Override public void testEvict() throws Exception {
         IgniteCache<String, Integer> cache = jcache();
 
-        List<String> keys = primaryKeysForCache(cache(), 2);
+        List<String> keys = primaryKeysForCache(jcache(), 2);
 
         String key = keys.get(0);
         String key2 = keys.get(1);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10fad8b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
index 8515b08..809d537 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
@@ -76,7 +76,7 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe
     /** {@inheritDoc} */
     @Override public void testClear() throws Exception {
         IgniteCache<String, Integer> nearCache = jcache();
-        GridCache<String, Integer> primary = fullCache();
+        IgniteCache<String, Integer> primary = fullCache();
 
         Collection<String> keys = primaryKeysForCache(primary, 3);
 
@@ -114,7 +114,7 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends GridCacheNe
 
     /** {@inheritDoc} */
     @Override public void testEvictExpired() throws Exception {
-        GridCache<String, Integer> cache = cache();
+        IgniteCache<String, Integer> cache = jcache();
 
         String key = primaryKeysForCache(cache, 1).get(0);
 
@@ -130,25 +130,25 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest extends
GridCacheNe
         Thread.sleep(ttl + 100);
 
         // Expired entry should not be swapped.
-        assertTrue(cache.evict(key));
+        cache.localEvict(Collections.<String>singleton(key));
 
-        assertNull(cache.peek(key));
+        assertNull(cache.localPeek(key));
 
-        assertNull(cache.promote(key));
+        cache.localPromote(Collections.singleton(key));
 
-        assertNull(cache.peek(key));
+        assertNull(cache.localPeek(key));
 
-        assertTrue(cache.isEmpty());
+        assertTrue(cache.localSize() == 0);
 
         // Force reload on primary node.
         for (int i = 0; i < gridCount(); i++) {
-            if (cache(i).entry(key).primary())
-                cache(i).reload(key);
+            if (ignite(i).affinity(null).isPrimary(ignite(i).cluster().localNode(), key))
+                jcache(i).loadAll(Collections.singleton(key), true, null);
         }
 
         // Will do near get request.
-        cache.reload(key);
+        cache.loadAll(Collections.singleton(key), true, null);
 
-        assertEquals((Integer)1, cache.peek(key));
+        assertEquals((Integer)1, cache.localPeek(key));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c10fad8b/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 f338277..49719d8 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
@@ -30,6 +30,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
+import java.util.concurrent.locks.*;
 
 import static org.apache.ignite.events.IgniteEventType.*;
 import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
@@ -117,8 +118,15 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
     /**
      * @return A not near-only cache.
      */
-    protected GridCache<String, Integer> fullCache() {
-        return nearIdx == 0 ? cache(1) : cache(0);
+    protected IgniteCache<String, Integer> fullCache() {
+        return nearIdx == 0 ? jcache(1) : jcache(0);
+    }
+
+    /**
+     * @return For the purpose of this test returns the near-only instance.
+     */
+    @Override protected IgniteCache<String, Integer> jcache() {
+        return jcache(nearIdx);
     }
 
     /**
@@ -134,8 +142,17 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
     }
 
     /** {@inheritDoc} */
+    @Override protected List<String> primaryKeysForCache(IgniteCache<String, Integer>
cache, int cnt)
+        throws IgniteCheckedException {
+        if (cache.equals(jcache()))
+            return super.primaryKeysForCache(fullCache(), cnt);
+
+        return super.primaryKeysForCache(cache, cnt);
+    }
+
+    /** {@inheritDoc} */
     @Override public void testSize() throws Exception {
-        GridCache<String, Integer> nearCache = cache();
+        IgniteCache<String, Integer> nearCache = jcache();
 
         int size = 10;
 
@@ -152,16 +169,14 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
 
         checkSize(map.keySet());
 
-        assertEquals("Primary keys found in near-only cache [" +
-            "primaryEntries=" + nearCache.primaryEntrySet() + ", dht=" + dht(nearIdx).allEntries()
+ "]",
-            0, nearCache.primarySize());
+        assertEquals(10, nearCache.localSize());
 
         int fullCacheSize = 0;
 
         for (int i = 0; i < gridCount(); i++)
-            fullCacheSize += cache(i).primarySize();
+            fullCacheSize += jcache(i).localSize();
 
-        assertEquals("Invalid cache size", 10, fullCacheSize);
+        assertEquals("Invalid cache size", fullCacheSize, nearCache.size());
     }
 
     /** {@inheritDoc} */
@@ -211,14 +226,14 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
 
     /** {@inheritDoc} */
     @Override public void testClear() throws Exception {
-        GridCache<String, Integer> nearCache = cache();
-        GridCache<String, Integer> primary = fullCache();
+        IgniteCache<String, Integer> nearCache = jcache();
+        IgniteCache<String, Integer> primary = fullCache();
 
         Collection<String> keys = primaryKeysForCache(primary, 3);
 
         info("Keys: " + keys);
 
-        Map<String, Integer> vals = new HashMap<>(keys.size());
+        Map<String, Integer> vals = new HashMap<>();
 
         int i = 0;
 
@@ -231,72 +246,40 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
         }
 
         for (String key : keys)
-            assertEquals(vals.get(key), nearCache.peek(key));
+            assertEquals(vals.get(key), nearCache.localPeek(key));
 
-        nearCache.clearAll();
+        nearCache.clear();
 
         for (String key : keys)
-            assertNull(nearCache.peek(key));
+            assertNull(nearCache.localPeek(key));
 
         for (Map.Entry<String, Integer> entry : vals.entrySet())
             nearCache.put(entry.getKey(), entry.getValue());
 
         for (String key : keys)
-            assertEquals(vals.get(key), nearCache.peek(key));
+            assertEquals(vals.get(key), nearCache.localPeek(key));
 
         String first = F.first(keys);
 
-        assertTrue(nearCache.lock(first, 0L));
+        Lock lock = nearCache.lock(first);
 
-        nearCache.clearAll();
+        lock.lock();
 
-        assertEquals(vals.get(first), nearCache.peek(first));
-        assertEquals(vals.get(first), primary.peek(first));
-
-        nearCache.unlock(first);
-
-        nearCache.projection(gte100).clear(first);
-
-        assertEquals(vals.get(first), nearCache.peek(first));
-        assertEquals(vals.get(first), primary.peek(first));
-
-        nearCache.put(first, 101);
-
-        nearCache.projection(gte100).clear(first);
-
-        assertTrue(nearCache.isEmpty());
-        assertFalse(primary.isEmpty());
-
-        i = 0;
-
-        for (String key : keys) {
-            nearCache.put(key, i);
+        try {
+            nearCache.clear();
 
-            vals.put(key, i);
-
-            i++;
+            assertEquals(vals.get(first), nearCache.localPeek(first));
+            assertEquals(vals.get(first), primary.localPeek(first));
         }
-
-        nearCache.put(first, 101);
-        vals.put(first, 101);
-
-        nearCache.projection(gte100).clear(first);
-
-        for (String key : keys)
-            assertEquals(vals.get(key), primary.peek(key));
-
-        for (String key : keys) {
-            if (first.equals(key))
-                assertNull(nearCache.peek(key));
-            else
-                assertEquals(vals.get(key), nearCache.peek(key));
+        finally {
+            lock.unlock();
         }
     }
 
     /** {@inheritDoc} */
     @Override public void testClearKeys() throws Exception {
-        GridCache<String, Integer> nearCache = cache();
-        GridCache<String, Integer> primary = fullCache();
+        IgniteCache<String, Integer> nearCache = jcache();
+        IgniteCache<String, Integer> primary = fullCache();
 
         Collection<String> keys = primaryKeysForCache(primary, 3);
 
@@ -309,7 +292,7 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
 
         subKeys.remove(lastKey);
 
-        Map<String, Integer> vals = new HashMap<>(keys.size());
+        Map<String, Integer> vals = new HashMap<>();
 
         int i = 0;
 
@@ -318,29 +301,14 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
 
         nearCache.putAll(vals);
 
-        for (String subKey : subKeys)
-            nearCache.clear(subKey);
+        nearCache.clear(subKeys);
 
         for (String key : subKeys) {
-            assertNull(nearCache.peek(key));
-            assertNotNull(primary.peek(key));
+            assertNull(nearCache.localPeek(key));
+            assertNotNull(primary.localPeek(key));
         }
 
-        assertEquals(vals.get(lastKey), nearCache.peek(lastKey));
-
-        nearCache.clearAll();
-
-        vals.put(lastKey, 102);
-
-        nearCache.putAll(vals);
-
-        for (String key : keys)
-            nearCache.projection(gte100).clear(key);
-
-        assertNull(nearCache.peek(lastKey));
-
-        for (String key : subKeys)
-            assertEquals(vals.get(key), nearCache.peek(key));
+        assertEquals(vals.get(lastKey), nearCache.localPeek(lastKey));
     }
 
     /** {@inheritDoc} */
@@ -349,14 +317,14 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
         // because some of them were blocked due to having readers.
         for (int i = 0; i < gridCount(); i++) {
             if (i != nearIdx)
-                for (String key : primaryKeysForCache(cache(i), 3))
-                    cache(i).put(key, 1);
+                for (String key : primaryKeysForCache(jcache(i), 3))
+                    jcache(i).put(key, 1);
         }
 
-        cache().globalClearAll();
+        jcache().clear();
 
         for (int i = 0; i < gridCount(); i++)
-            assertTrue(String.valueOf(cache(i).entrySet()), cache(i).isEmpty());
+            assertTrue(String.valueOf(jcache(i)), jcache(i).localSize() == 0);
     }
 
     /** {@inheritDoc} */
@@ -383,36 +351,41 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
                 }
             }, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
 
-            GridCache<String, Integer> nearCache = cache();
-            GridCache<String, Integer> cache = fullCache();
+            IgniteCache<String, Integer> nearCache = jcache();
+            IgniteCache<String, Integer> cache = fullCache();
 
             String key = primaryKeysForCache(cache, 1).get(0);
 
             nearCache.put(key, 1);
 
-            assert !nearCache.isLocked(key);
-            assert !cache.isLocked(key);
+            assert !nearCache.isLocalLocked(key, false);
+            assert !cache.isLocalLocked(key, false);
 
-            nearCache.lock(key, 0L);
+            Lock lock = nearCache.lock(key);
 
-            lockCnt.await();
+            lock.lock();
 
-            assert nearCache.isLocked(key);
-            assert cache.isLocked(key);
+            try {
+                lockCnt.await();
 
-            nearCache.unlock(key);
+                assert nearCache.isLocalLocked(key, false);
+                assert cache.isLocalLocked(key, false);
+            }
+            finally {
+                lock.unlock();
+            }
 
             unlockCnt.await();
 
             for (int i = 0; i < 100; i++) {
-                if (cache.isLocked(key))
+                if (cache.isLocalLocked(key, false))
                     Thread.sleep(10);
                 else
                     break;
             }
 
-            assert !nearCache.isLocked(key);
-            assert !cache.isLocked(key);
+            assert !nearCache.isLocalLocked(key, false);
+            assert !cache.isLocalLocked(key, false);
         }
     }
 


Mime
View raw message