Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D1AE517CB0 for ; Tue, 17 Nov 2015 12:54:08 +0000 (UTC) Received: (qmail 89727 invoked by uid 500); 17 Nov 2015 12:54:08 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 89630 invoked by uid 500); 17 Nov 2015 12:54:08 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 88393 invoked by uid 99); 17 Nov 2015 12:54:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Nov 2015 12:54:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F11DDE0B53; Tue, 17 Nov 2015 12:54:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agoncharuk@apache.org To: commits@ignite.apache.org Date: Tue, 17 Nov 2015 12:54:46 -0000 Message-Id: <51d5fc9a59b840229774acf499b3e542@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [41/45] ignite git commit: Added advanced tests for GridCacheLoadOnlyStoreAdapterSelfTest Added advanced tests for GridCacheLoadOnlyStoreAdapterSelfTest Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d54fcbed Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d54fcbed Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d54fcbed Branch: refs/heads/ignite-1282 Commit: d54fcbedf9fdc110de8e73387a6796852b0ff42c Parents: 8014712 Author: Denis Magda Authored: Tue Nov 17 11:56:01 2015 +0300 Committer: Denis Magda Committed: Tue Nov 17 11:56:01 2015 +0300 ---------------------------------------------------------------------- .../GridCacheLoadOnlyStoreAdapterSelfTest.java | 145 +++++++++++++++++-- 1 file changed, 135 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d54fcbed/modules/core/src/test/java/org/apache/ignite/cache/store/GridCacheLoadOnlyStoreAdapterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/GridCacheLoadOnlyStoreAdapterSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/GridCacheLoadOnlyStoreAdapterSelfTest.java index 70fae9c..461f562 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/GridCacheLoadOnlyStoreAdapterSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/GridCacheLoadOnlyStoreAdapterSelfTest.java @@ -20,6 +20,7 @@ package org.apache.ignite.cache.store; import java.util.Arrays; import java.util.Iterator; import java.util.NoSuchElementException; +import javax.cache.integration.CacheLoaderException; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; import org.apache.ignite.internal.util.typedef.T2; @@ -33,8 +34,8 @@ public class GridCacheLoadOnlyStoreAdapterSelfTest extends GridCacheAbstractSelf /** Expected loadAll arguments, hardcoded on call site for convenience. */ private static final Integer[] EXP_ARGS = {1, 2, 3}; - /** Test input size. */ - private static final int INPUT_SIZE = 100; + /** Store to use. */ + private CacheLoadOnlyStoreAdapter store; /** {@inheritDoc} */ @Override protected int gridCount() { @@ -42,11 +43,33 @@ public class GridCacheLoadOnlyStoreAdapterSelfTest extends GridCacheAbstractSelf } /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + + } + + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { CacheConfiguration cfg = super.cacheConfiguration(gridName); - cfg.setCacheStoreFactory(singletonFactory(new TestStore())); + assertNotNull(store); + + cfg.setCacheStoreFactory(singletonFactory(store)); cfg.setReadThrough(true); cfg.setWriteThrough(true); cfg.setLoadPreviousValue(true); @@ -58,20 +81,74 @@ public class GridCacheLoadOnlyStoreAdapterSelfTest extends GridCacheAbstractSelf * @throws Exception If failed. */ public void testStore() throws Exception { - jcache().localLoadCache(null, 1, 2, 3); + try { + int inputSize = 100; + + store = new TestStore(inputSize); + + startGrids(gridCount()); + + awaitPartitionMapExchange(); + + jcache().localLoadCache(null, 1, 2, 3); + + int cnt = 0; + + for (int i = 0; i < gridCount(); i++) + cnt += jcache(i).localSize(); + + assertEquals(inputSize - (inputSize / 10), cnt); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testStoreSmallQueueSize() throws Exception { + try { + int inputSize = 1500; + + store = new ParallelTestStore(inputSize); + + store.setBatchSize(1); + store.setBatchQueueSize(1); + store.setThreadsCount(2); + + startGrids(gridCount()); + + awaitPartitionMapExchange(); + + jcache().localLoadCache(null, 1, 2, 3); - int cnt = 0; + int cnt = 0; - for (int i = 0; i < gridCount(); i++) - cnt += jcache(i).localSize(); + for (int i = 0; i < gridCount(); i++) + cnt += jcache(i).localSize(); - assertEquals(INPUT_SIZE - (INPUT_SIZE/10), cnt); + assertEquals(inputSize, cnt); + } + finally { + stopAllGrids(); + } } /** * */ private static class TestStore extends CacheLoadOnlyStoreAdapter { + /** */ + private final int inputSize; + + /** + * @param inputSize Input size. + */ + public TestStore(int inputSize) { + this.inputSize = inputSize; + } + /** {@inheritDoc} */ @Override protected Iterator inputIterator(@Nullable Object... args) { assertNotNull(args); @@ -81,7 +158,7 @@ public class GridCacheLoadOnlyStoreAdapterSelfTest extends GridCacheAbstractSelf private int i = -1; @Override public boolean hasNext() { - return i < INPUT_SIZE; + return i < inputSize; } @Override public String next() { @@ -111,4 +188,52 @@ public class GridCacheLoadOnlyStoreAdapterSelfTest extends GridCacheAbstractSelf return i % 10 == 0 ? null : new T2<>(i, p[1]); } } -} \ No newline at end of file + + /** + * + */ + private static class ParallelTestStore extends CacheLoadOnlyStoreAdapter { + /** */ + private final int inputSize; + + /** + * @param inputSize Input size. + */ + public ParallelTestStore(int inputSize) { + this.inputSize = inputSize; + } + + /** {@inheritDoc} */ + @Override protected Iterator inputIterator(@Nullable Object... args) throws CacheLoaderException { + return new Iterator() { + private int i; + + @Override public boolean hasNext() { + return i < inputSize; + } + + @Override public String next() { + if (!hasNext()) + throw new NoSuchElementException(); + + String res = i + "=str" + i; + + i++; + + return res; + } + + @Override public void remove() { + // No-op. + } + }; + } + + /** {@inheritDoc} */ + @Nullable @Override protected IgniteBiTuple parse(String rec, @Nullable Object... args) { + String[] p = rec.split("="); + + return new T2<>(Integer.parseInt(p[0]), p[1]); + } + } +}