ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [13/50] [abbrv] incubator-ignite git commit: # IGNITE-56 Enable GridCacheEntryMemorySizeSelfTest.
Date Thu, 12 Feb 2015 12:12:43 GMT
# IGNITE-56 Enable GridCacheEntryMemorySizeSelfTest.


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

Branch: refs/heads/ignite-191
Commit: 755637408f17cbfbac7f459d6146e8b4c42e5076
Parents: 7f6091b
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Wed Feb 11 13:11:47 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed Feb 11 13:14:46 2015 +0300

----------------------------------------------------------------------
 .../cache/GridCacheEntryMemorySizeSelfTest.java | 282 +++++++++----------
 1 file changed, 140 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/75563740/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
index be397f8..c3f77bc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
@@ -30,8 +30,8 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.junits.common.*;
 
-import javax.cache.*;
 import java.io.*;
+import java.lang.reflect.*;
 import java.util.*;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
@@ -126,145 +126,151 @@ public class GridCacheEntryMemorySizeSelfTest extends GridCommonAbstractTest
{
 
     /** @throws Exception If failed. */
     public void testLocal() throws Exception {
-        assert false : "ignite-96";
-//        mode = LOCAL;
-//
-//        try {
-//            GridCache<Integer, Value> cache = startGrid().cache(null);
-//
-//            assertTrue(cache.putx(1, new Value(new byte[1024])));
-//            assertTrue(cache.putx(2, new Value(new byte[2048])));
-//
-//            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + extrasSize(cache.entry(0)),
-//                cache.entry(0).memorySize());
-//            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + extrasSize(cache.entry(1)),
-//                cache.entry(1).memorySize());
-//            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + extrasSize(cache.entry(2)),
-//                cache.entry(2).memorySize());
-//        }
-//        finally {
-//            stopAllGrids();
-//        }
+        mode = LOCAL;
+
+        try {
+            IgniteCache<Integer, Value> cache = startGrid().jcache(null);
+
+            cache.put(1, new Value(new byte[1024]));
+            cache.put(2, new Value(new byte[2048]));
+
+            GridCacheAdapter<Integer, Value> internalCache = internalCache(cache);
+
+            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + extrasSize(internalCache.entryEx(0)),
+                internalCache.entryEx(0).memorySize());
+            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + extrasSize(internalCache.entryEx(1)),
+                internalCache.entryEx(1).memorySize());
+            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + extrasSize(internalCache.entryEx(2)),
+                internalCache.entryEx(2).memorySize());
+        }
+        finally {
+            stopAllGrids();
+        }
     }
 
     /** @throws Exception If failed. */
     public void testReplicated() throws Exception {
-        assert false : "ignite-96";
-
-//        mode = REPLICATED;
-//
-//        try {
-//            GridCache<Integer, Value> cache = startGrid().cache(null);
-//
-//            assertTrue(cache.putx(1, new Value(new byte[1024])));
-//            assertTrue(cache.putx(2, new Value(new byte[2048])));
-//
-//            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
-//                extrasSize(cache.entry(0)), cache.entry(0).memorySize());
-//            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
-//                extrasSize(cache.entry(1)), cache.entry(1).memorySize());
-//            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
-//                extrasSize(cache.entry(2)), cache.entry(2).memorySize());
-//        }
-//        finally {
-//            stopAllGrids();
-//        }
+        mode = REPLICATED;
+
+        try {
+            IgniteCache<Integer, Value> cache = startGrid().jcache(null);
+
+            cache.put(1, new Value(new byte[1024]));
+            cache.put(2, new Value(new byte[2048]));
+
+            GridCacheAdapter<Integer, Value> internalCache = dht(cache);
+
+            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
+                extrasSize(internalCache.entryEx(0)), internalCache.entryEx(0).memorySize());
+            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
+                extrasSize(internalCache.entryEx(1)), internalCache.entryEx(1).memorySize());
+            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + REPLICATED_ENTRY_OVERHEAD
+
+                extrasSize(internalCache.entryEx(2)), internalCache.entryEx(2).memorySize());
+        }
+        finally {
+            stopAllGrids();
+        }
     }
 
     /** @throws Exception If failed. */
     public void testPartitionedNearEnabled() throws Exception {
-        assert false : "ignite-96";
-
-//        try {
-//            startGridsMultiThreaded(2);
-//
-//            int[] keys = new int[3];
-//
-//            int key = 0;
-//
-//            for (int i = 0; i < keys.length; i++) {
-//                while (true) {
-//                    key++;
-//
-//                    if (grid(0).mapKeyToNode(null, key).equals(grid(0).localNode())) {
-//                        if (i > 0)
-//                            jcache(0).put(key, new Value(new byte[i * 1024]));
-//
-//                        keys[i] = key;
-//
-//                        break;
-//                    }
-//                }
-//            }
-//
-//            // Create near entries.
-//            assertNotNull(jcache(1).get(keys[1]));
-//            assertNotNull(jcache(1).get(keys[2]));
-//
-//            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
-//                extrasSize(cache(0).entry(keys[0])), cache(0).entry(keys[0]).memorySize());
-//            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+ READER_SIZE +
-//                extrasSize(cache(0).entry(keys[1])), cache(0).entry(keys[1]).memorySize());
-//            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+ READER_SIZE +
-//                extrasSize(cache(0).entry(keys[2])), cache(0).entry(keys[2]).memorySize());
-//
-//            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
-//                extrasSize(cache(1).entry(keys[0])), cache(1).entry(keys[0]).memorySize());
-//            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
-//                extrasSize(cache(1).entry(keys[1])), cache(1).entry(keys[1]).memorySize());
-//            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
-//                extrasSize(cache(1).entry(keys[2])), cache(1).entry(keys[2]).memorySize());
-//        }
-//        finally {
-//            stopAllGrids();
-//        }
+        mode = PARTITIONED;
+        nearEnabled = true;
+
+        try {
+            startGridsMultiThreaded(2);
+
+            int[] keys = new int[3];
+
+            int key = 0;
+
+            for (int i = 0; i < keys.length; i++) {
+                while (true) {
+                    key++;
+
+                    if (grid(0).mapKeyToNode(null, key).equals(grid(0).localNode())) {
+                        if (i > 0)
+                            jcache(0).put(key, new Value(new byte[i * 1024]));
+
+                        keys[i] = key;
+
+                        break;
+                    }
+                }
+            }
+
+            // Create near entries.
+            assertNotNull(jcache(1).get(keys[1]));
+            assertNotNull(jcache(1).get(keys[2]));
+
+            GridCacheAdapter<Object, Object> cache0 = dht(jcache(0));
+
+            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD +
+                extrasSize(cache0.entryEx(keys[0])), cache0.entryEx(keys[0]).memorySize());
+            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+ READER_SIZE +
+                extrasSize(cache0.entryEx(keys[1])), cache0.entryEx(keys[1]).memorySize());
+            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+ READER_SIZE +
+                extrasSize(cache0.entryEx(keys[2])), cache0.entryEx(keys[2]).memorySize());
+
+            GridCacheAdapter<Object, Object> cache1 = near(jcache(1));
+
+            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
+                extrasSize(cache1.entryEx(keys[0])), cache1.entryEx(keys[0]).memorySize());
+            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
+                extrasSize(cache1.entryEx(keys[1])), cache1.entryEx(keys[1]).memorySize());
+            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + NEAR_ENTRY_OVERHEAD
+
+                extrasSize(cache1.entryEx(keys[2])), cache1.entryEx(keys[2]).memorySize());
+        }
+        finally {
+            stopAllGrids();
+        }
     }
 
     /** @throws Exception If failed. */
     public void testPartitionedNearDisabled() throws Exception {
-        assert false : "ignite-96";
-
-//        mode = PARTITIONED;
-//        nearEnabled = false;
-//
-//        try {
-//            startGridsMultiThreaded(2);
-//
-//            int[] keys = new int[3];
-//
-//            int key = 0;
-//
-//            for (int i = 0; i < keys.length; i++) {
-//                while (true) {
-//                    key++;
-//
-//                    if (grid(0).mapKeyToNode(null, key).equals(grid(0).localNode())) {
-//                        if (i > 0)
-//                            assertTrue(cache(0).putx(key, new Value(new byte[i * 1024])));
-//
-//                        keys[i] = key;
-//
-//                        break;
-//                    }
-//                }
-//            }
-//
-//            // Create near entries.
-//            assertNotNull(cache(1).get(keys[1]));
-//            assertNotNull(cache(1).get(keys[2]));
-//
-//            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
-//                extrasSize(cache(0).entry(keys[0])), cache(0).entry(keys[0]).memorySize());
-//            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
-//                extrasSize(cache(0).entry(keys[1])), cache(0).entry(keys[1]).memorySize());
-//            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
-//                extrasSize(cache(0).entry(keys[2])), cache(0).entry(keys[2]).memorySize());
-//
-//            // Do not test other node since there are no backups.
-//        }
-//        finally {
-//            stopAllGrids();
-//        }
+        mode = PARTITIONED;
+        nearEnabled = false;
+
+        try {
+            startGridsMultiThreaded(2);
+
+            int[] keys = new int[3];
+
+            int key = 0;
+
+            for (int i = 0; i < keys.length; i++) {
+                while (true) {
+                    key++;
+
+                    if (grid(0).mapKeyToNode(null, key).equals(grid(0).localNode())) {
+                        if (i > 0)
+                            jcache(0).put(key, new Value(new byte[i * 1024]));
+
+                        keys[i] = key;
+
+                        break;
+                    }
+                }
+            }
+
+            // Create near entries.
+            assertNotNull(jcache(1).get(keys[1]));
+            assertNotNull(jcache(1).get(keys[2]));
+
+            GridCacheAdapter<Object, Object> cache = dht(jcache(0));
+
+            assertEquals(KEY_SIZE + NULL_REF_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD +
+                extrasSize(cache.entryEx(keys[0])), cache.entryEx(keys[0]).memorySize());
+            assertEquals(KEY_SIZE + ONE_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
+                extrasSize(cache.entryEx(keys[1])), cache.entryEx(keys[1]).memorySize());
+            assertEquals(KEY_SIZE + TWO_KB_VAL_SIZE + ENTRY_OVERHEAD + DHT_ENTRY_OVERHEAD
+
+                extrasSize(cache.entryEx(keys[2])), cache.entryEx(keys[2]).memorySize());
+
+            // Do not test other node since there are no backups.
+        }
+        finally {
+            stopAllGrids();
+        }
     }
 
     /**
@@ -274,20 +280,12 @@ public class GridCacheEntryMemorySizeSelfTest extends GridCommonAbstractTest
{
      * @return Extras size.
      * @throws Exception If failed.
      */
-    private int extrasSize(Cache.Entry entry) throws Exception {
-        assert false : "ignite-96";
-
-        return -1;
-
-//        Method mthd = GridCacheMapEntry.class.getDeclaredMethod("extrasSize");
-//
-//        mthd.setAccessible(true);
-//
-//        GridCacheContext ctx = U.field(entry, "ctx");
-//
-//        GridCacheEntryEx entry0 = ((GridCacheEntryImpl)entry).entryEx(false, ctx.discovery().topologyVersion());
-//
-//        return (Integer)mthd.invoke(entry0);
+    private int extrasSize(GridCacheEntryEx<?, ?> entry) throws Exception {
+        Method mthd = GridCacheMapEntry.class.getDeclaredMethod("extrasSize");
+
+        mthd.setAccessible(true);
+
+        return (Integer)mthd.invoke(entry);
     }
 
     /** Value. */


Mime
View raw message