ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [5/7] ignite git commit: Test for ignite-973.
Date Thu, 17 Sep 2015 18:54:54 GMT
Test for ignite-973.


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

Branch: refs/heads/ignite-1171
Commit: 3676cbe7f5f5f73199487318d6841e50a1f73496
Parents: 585761f
Author: sboikov <sboikov@gridgain.com>
Authored: Thu Sep 17 17:52:24 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Sep 17 17:52:24 2015 +0300

----------------------------------------------------------------------
 .../ignite/testframework/GridTestUtils.java     |  14 +-
 .../cache/CacheIndexStreamerTest.java           | 137 +++++++++++++++++++
 2 files changed, 150 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3676cbe7/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index edf7c52..be3f0e4 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -633,11 +633,23 @@ public final class GridTestUtils {
      */
     @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
     public static <T> IgniteInternalFuture<T> runAsync(final Callable<T>
task) {
+        return runAsync(task, "async-runner");
+    }
+
+    /**
+     * Runs callable task asyncronously.
+     *
+     * @param task Callable.
+     * @param threadName Thread name.
+     * @return Future with task result.
+     */
+    @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
+    public static <T> IgniteInternalFuture<T> runAsync(final Callable<T>
task, String threadName) {
         if (!busyLock.enterBusy())
             throw new IllegalStateException("Failed to start new threads (test is being stopped).");
 
         try {
-            final GridTestSafeThreadFactory thrFactory = new GridTestSafeThreadFactory("async-runner");
+            final GridTestSafeThreadFactory thrFactory = new GridTestSafeThreadFactory(threadName);
 
             final GridFutureAdapter<T> fut = new GridFutureAdapter<T>() {
                 @Override public boolean cancel() throws IgniteCheckedException {

http://git-wip-us.apache.org/repos/asf/ignite/blob/3676cbe7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexStreamerTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexStreamerTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexStreamerTest.java
new file mode 100644
index 0000000..25c3b81
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheIndexStreamerTest.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheMemoryMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class CacheIndexStreamerTest extends GridCommonAbstractTest {
+    /** */
+    private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStreamer() throws Exception {
+        final Ignite ignite = startGrid(0);
+
+        final IgniteCache<Integer, String> cache = ignite.createCache(cacheConfiguration());
+
+        final AtomicBoolean stop = new AtomicBoolean();
+
+        final int KEYS= 10_000;
+
+        try {
+            IgniteInternalFuture streamerFut = GridTestUtils.runAsync(new Callable() {
+                @Override public Void call() throws Exception {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    while (!stop.get()) {
+                        try (IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(null))
{
+                            for (int i = 0; i < 1; i++)
+                                streamer.addData(rnd.nextInt(KEYS), String.valueOf(i));
+                        }
+                    }
+
+                    return null;
+                }
+            }, "streamer-thread");
+
+            IgniteInternalFuture updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>()
{
+                @Override public Void call() throws Exception {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    while (!stop.get()) {
+                        for (int i = 0; i < 100; i++) {
+                            Integer key = rnd.nextInt(KEYS);
+
+                            cache.put(key, String.valueOf(key));
+
+                            cache.remove(key);
+                        }
+                    }
+
+                    return null;
+                }
+            }, 1, "update-thread");
+
+            U.sleep(30_000);
+
+            stop.set(true);
+
+            streamerFut.get();
+            updateFut.get();
+        }
+        finally {
+            stop.set(true);
+
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration() {
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setAtomicityMode(ATOMIC);
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED);
+        ccfg.setOffHeapMaxMemory(0);
+        ccfg.setBackups(1);
+        ccfg.setIndexedTypes(Integer.class, String.class);
+
+        return ccfg;
+    }
+
+
+}


Mime
View raw message