ignite-db - multithreaded tests
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/58ac7a0f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/58ac7a0f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/58ac7a0f Branch: refs/heads/ignite-db-x-gg-11124 Commit: 58ac7a0fae135308d080e9effc7585107f91bb3a Parents: 9a307f1 Author: S.Vladykin <[email protected]> Authored: Fri Apr 29 05:00:38 2016 +0300 Committer: S.Vladykin <[email protected]> Committed: Fri Apr 29 05:00:38 2016 +0300 ---------------------------------------------------------------------- .../database/BPlusTreeReuseSelfTest.java | 79 ++++++++++++++++++++ .../processors/database/BPlusTreeSelfTest.java | 18 ++--- 2 files changed, 88 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/58ac7a0f/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java index a70bb1d..c8a0907 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java @@ -17,10 +17,17 @@ package org.apache.ignite.internal.processors.database; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.locks.Lock; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.pagemem.PageMemory; import org.apache.ignite.internal.processors.cache.database.MetaStore; import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList; +import org.apache.ignite.internal.util.GridStripedLock; +import org.apache.ignite.internal.util.lang.GridCursor; +import org.apache.ignite.internal.util.typedef.X; +import org.jsr166.ConcurrentHashMap8; /** * Test with reuse. @@ -31,4 +38,76 @@ public class BPlusTreeReuseSelfTest extends BPlusTreeSelfTest { throws IgniteCheckedException { return new ReuseList(cacheId, pageMem, segments, metaStore); } + + /** + * @throws Exception If failed. + */ + public void testTestRandomPutRemoveMultithreaded_1_50_0() throws Exception { + doTestRandomPutRemoveMultithreaded(false); + } + + /** + * @throws Exception If failed. + */ + public void testTestRandomPutRemoveMultithreaded_1_50_1() throws Exception { + doTestRandomPutRemoveMultithreaded(true); + } + + /** + * @param canGetRow Can get row from inner page. + * @throws Exception If failed. + */ + private void doTestRandomPutRemoveMultithreaded(boolean canGetRow) throws Exception { + final TestTree tree = createTestTree(canGetRow); + + final Map<Long,Long> map = new ConcurrentHashMap8<>(); + + final int loops = 1000_000; + + final GridStripedLock lock = new GridStripedLock(64); + + multithreaded(new Callable<Object>() { + @Override public Object call() throws Exception { + for (int i = 0 ; i < loops; i++) { + Long x = (long)tree.randomInt(CNT); + + boolean put = tree.randomInt(2) == 0; + + if (i % 100_000 == 0) + X.println(" --> " + (put ? "put " : "rmv ") + i + " " + x); + + Lock l = lock.getLock(x.longValue()); + + l.lock(); + + try { + if (put) + assertEquals(map.put(x, x), tree.put(x)); + else { + if (map.remove(x) != null) + assertEquals(x, tree.remove(x)); + assertNull(tree.remove(x)); + } + } + finally { + l.unlock(); + } + } + + return null; + } + }, 10); + + GridCursor<Long> cursor = tree.find(null, null); + + while (cursor.next()) { + Long x = cursor.get(); + + assert x != null; + + assertEquals(map.get(x), x); + } + + assertEquals(map.size(), tree.size()); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/58ac7a0f/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java index 8917bf2..da709d2 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java @@ -65,7 +65,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { private static int MAX_PER_PAGE = 0; /** */ - private static int CNT = 10; + protected static int CNT = 10; /** */ private static int PUT_INC = 1; @@ -77,7 +77,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { private PageMemory pageMem; /** */ - private ReuseList reuseList; + protected ReuseList reuseList; // /** {@inheritDoc} */ // @Override protected long getTestTimeout() { @@ -469,28 +469,28 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { /** * @throws IgniteCheckedException If failed. */ - public void testRandomRemove_1_30_0() throws IgniteCheckedException { + public void testRandomPutRemove_1_30_0() throws IgniteCheckedException { MAX_PER_PAGE = 1; CNT = 30; - doTestRandomRemove(false); + doTestRandomPutRemove(false); } /** * @throws IgniteCheckedException If failed. */ - public void testRandomRemove_1_30_1() throws IgniteCheckedException { + public void testRandomPutRemove_1_30_1() throws IgniteCheckedException { MAX_PER_PAGE = 1; CNT = 30; - doTestRandomRemove(true); + doTestRandomPutRemove(true); } /** * @param canGetRow Can get row from inner page. * @throws IgniteCheckedException If failed. */ - private void doTestRandomRemove(boolean canGetRow) throws IgniteCheckedException { + private void doTestRandomPutRemove(boolean canGetRow) throws IgniteCheckedException { TestTree tree = createTestTree(canGetRow); Map<Long,Long> map = new HashMap<>(); @@ -536,7 +536,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { * @return Test tree instance. * @throws IgniteCheckedException If failed. */ - private TestTree createTestTree(boolean canGetRow) throws IgniteCheckedException { + protected TestTree createTestTree(boolean canGetRow) throws IgniteCheckedException { TestTree tree = new TestTree(reuseList, canGetRow, CACHE_ID, pageMem, allocateMetaPage()); assertEquals(0, tree.size()); @@ -556,7 +556,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest { /** * Test tree. */ - private static class TestTree extends BPlusTree<Long, Long> { + protected static class TestTree extends BPlusTree<Long, Long> { /** */ static Random rnd;
