You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by yz...@apache.org on 2015/11/18 14:40:54 UTC

[38/50] [abbrv] 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-638
Commit: d54fcbedf9fdc110de8e73387a6796852b0ff42c
Parents: 8014712
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue Nov 17 11:56:01 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
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<Integer, String, String> {
+        /** */
+        private final int inputSize;
+
+        /**
+         * @param inputSize Input size.
+         */
+        public TestStore(int inputSize) {
+            this.inputSize = inputSize;
+        }
+
         /** {@inheritDoc} */
         @Override protected Iterator<String> 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<Integer, String, String> {
+        /** */
+        private final int inputSize;
+
+        /**
+         * @param inputSize Input size.
+         */
+        public ParallelTestStore(int inputSize) {
+            this.inputSize = inputSize;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected Iterator<String> inputIterator(@Nullable Object... args) throws CacheLoaderException {
+            return new Iterator<String>() {
+                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<Integer, String> parse(String rec, @Nullable Object... args) {
+            String[] p = rec.split("=");
+
+            return new T2<>(Integer.parseInt(p[0]), p[1]);
+        }
+    }
+}