You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2017/02/16 14:41:07 UTC

[15/17] ignite git commit: ignite-4652 - invoke tests

ignite-4652 - invoke tests


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

Branch: refs/heads/ignite-4652
Commit: 00820a94e02ab8991a4eb6f3f4719be7eed692e5
Parents: a6e2569
Author: Sergi Vladykin <se...@gmail.com>
Authored: Wed Feb 15 20:34:14 2017 +0300
Committer: Sergi Vladykin <se...@gmail.com>
Committed: Wed Feb 15 20:34:14 2017 +0300

----------------------------------------------------------------------
 .../cache/database/tree/BPlusTree.java          |   3 +
 .../processors/database/BPlusTreeSelfTest.java  | 153 +++++++++++++++++--
 2 files changed, 144 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/00820a94/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
index 5971844..20860f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
@@ -2757,6 +2757,9 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
 
                     assert newRow != null;
 
+                    // Row key must be equal to the old one.
+                    assert !rowFound || compare(io, pageAddr, idx, newRow) == 0;
+
                     op = new Put(newRow, false);
 
                     break;

http://git-wip-us.apache.org/repos/asf/ignite/blob/00820a94/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
index 2d9c693..e0a521a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
@@ -50,17 +50,22 @@ import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList
 import org.apache.ignite.internal.util.GridConcurrentHashSet;
 import org.apache.ignite.internal.util.GridRandom;
 import org.apache.ignite.internal.util.GridStripedLock;
+import org.apache.ignite.internal.util.IgniteTree;
 import org.apache.ignite.internal.util.lang.GridCursor;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 import org.jsr166.ConcurrentLinkedHashMap;
 
 import static org.apache.ignite.internal.pagemem.PageIdUtils.effectivePageId;
 import static org.apache.ignite.internal.processors.cache.database.tree.BPlusTree.rnd;
+import static org.apache.ignite.internal.util.IgniteTree.OperationType.NOOP;
+import static org.apache.ignite.internal.util.IgniteTree.OperationType.PUT;
+import static org.apache.ignite.internal.util.IgniteTree.OperationType.REMOVE;
 
 /**
  */
@@ -561,6 +566,122 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
     /**
      * @throws IgniteCheckedException If failed.
      */
+    public void testRandomInvoke_1_30_1() throws IgniteCheckedException {
+        MAX_PER_PAGE = 1;
+        CNT = 30;
+
+        doTestRandomInvoke(true);
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testRandomInvoke_1_30_0() throws IgniteCheckedException {
+        MAX_PER_PAGE = 1;
+        CNT = 30;
+
+        doTestRandomInvoke(false);
+    }
+
+    /**
+     * @param canGetRow Can get row from inner page.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void doTestRandomInvoke(boolean canGetRow) throws IgniteCheckedException {
+        TestTree tree = createTestTree(canGetRow);
+
+        Map<Long,Long> map = new HashMap<>();
+
+        int loops = reuseList == null ? 100_000 : 300_000;
+
+        for (int i = 0 ; i < loops; i++) {
+            final Long x = (long)BPlusTree.randomInt(CNT);
+            final int rnd = BPlusTree.randomInt(11);
+
+            // Update map.
+            if (!map.containsKey(x)) {
+                if (rnd % 2 == 0) {
+                    map.put(x, x);
+
+                    X.println("put0: " + x);
+                }
+                else {
+                    X.println("noop0: " + x);
+                }
+            }
+            else {
+                if (rnd % 2 == 0) {
+                    X.println("put1: " + x);
+                }
+                else if (rnd % 3 == 0) {
+                    map.remove(x);
+
+                    X.println("rmv1: " + x);
+                }
+                else {
+                    X.println("noop1: " + x);
+                }
+            }
+
+            // Consistently update tree.
+            tree.invoke(x, new IgniteTree.InvokeClosure<Long>() {
+
+                IgniteTree.OperationType op;
+
+                Long newRow;
+
+                @Override public void call(@Nullable Long row) throws IgniteCheckedException {
+                    if (row == null) {
+                        if (rnd % 2 == 0) {
+                            op = PUT;
+                            newRow = x;
+                        }
+                        else {
+                            op = NOOP;
+                            newRow = null;
+                        }
+                    }
+                    else {
+                        assertEquals(x, row);
+
+                        if (rnd % 2 == 0) {
+                            op = PUT;
+                            newRow = x; // We can not replace x with y here, because keys must be equal.
+                        }
+                        else if (rnd % 3 == 0) {
+                            op = REMOVE;
+                            newRow = null;
+                        }
+                        else {
+                            op = NOOP;
+                            newRow = null;
+                        }
+                    }
+                }
+
+                @Override public Long newRow() {
+                    return newRow;
+                }
+
+                @Override public IgniteTree.OperationType operationType() {
+                    return op;
+                }
+            });
+
+            assertNoLocks();
+
+            X.println(tree.printTree());
+
+            tree.validateTree();
+
+//            if (i % 100 == 0)
+                assertEqualContents(tree, map);
+        }
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
     public void testRandomPutRemove_1_30_0() throws IgniteCheckedException {
         MAX_PER_PAGE = 1;
         CNT = 30;
@@ -840,24 +961,32 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
 //            X.println(tree.printTree());
             tree.validateTree();
 
-            if (i % 100 == 0) {
-                GridCursor<Long> cursor = tree.find(null, null);
-
-                while (cursor.next()) {
-                    x = cursor.get();
+            if (i % 100 == 0)
+                assertEqualContents(tree, map);
+        }
+    }
 
-                    assert x != null;
+    /**
+     * @param tree Tree.
+     * @param map Map.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void assertEqualContents(IgniteTree<Long, Long> tree, Map<Long,Long> map) throws IgniteCheckedException {
+        GridCursor<Long> cursor = tree.find(null, null);
 
-                    assertEquals(map.get(x), x);
+        while (cursor.next()) {
+            Long x = cursor.get();
 
-                    assertNoLocks();
-                }
+            assert x != null;
 
-                assertEquals(map.size(), tree.size());
+            assertEquals(map.get(x), x);
 
-                assertNoLocks();
-            }
+            assertNoLocks();
         }
+
+        assertEquals(map.size(), tree.size());
+
+        assertNoLocks();
     }
 
     /**