You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2016/12/29 09:37:49 UTC
[45/50] [abbrv] ignite git commit: ignite-gg-11842 Add reproducer
test.
ignite-gg-11842 Add reproducer test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2999ffd5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2999ffd5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2999ffd5
Branch: refs/heads/ignite-3477
Commit: 2999ffd5646e608a20080b758f65e0e816343c77
Parents: 893cd90
Author: Dmitriy Govorukhin <dg...@gridgain.com>
Authored: Wed Dec 28 18:53:36 2016 +0300
Committer: Dmitriy Govorukhin <dg...@gridgain.com>
Committed: Wed Dec 28 18:53:36 2016 +0300
----------------------------------------------------------------------
.../GridCacheConcurrentGetCacheOnClient.java | 129 +++++++++++++++++++
.../ignite/testframework/GridTestUtils.java | 80 ++++++++++--
2 files changed, 197 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/2999ffd5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentGetCacheOnClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentGetCacheOnClient.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentGetCacheOnClient.java
new file mode 100644
index 0000000..3a97964
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentGetCacheOnClient.java
@@ -0,0 +1,129 @@
+/*
+ * 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.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+
+/**
+ *
+ */
+public class GridCacheConcurrentGetCacheOnClient extends GridCommonAbstractTest{
+ /** Ip finder. */
+ private final static TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /**
+ * @param gridName Grid name.
+ */
+ @Override protected IgniteConfiguration getConfiguration(final String gridName) throws Exception {
+ final IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ return cfg;
+ }
+
+ /**
+ *
+ */
+ public void test() throws Exception {
+ IgniteConfiguration node1cfg = getConfiguration("node1");
+ IgniteConfiguration node2cfg = getConfiguration("node2");
+
+ Ignite node1 = startGrid("node1", node1cfg);
+ Ignite node2 = startGrid("node2", node2cfg);
+
+ IgniteConfiguration clientCfg1 = getConfiguration("client");
+ clientCfg1.setClientMode(true);
+
+ IgniteConfiguration clientCfg2 = getConfiguration("client");
+ clientCfg2.setClientMode(true);
+
+ final IgniteEx client1 = (IgniteEx)startGrid("client1", clientCfg1);
+ final IgniteEx client2 = (IgniteEx)startGrid("client2", clientCfg2);
+
+ final CountDownLatch startLatch = new CountDownLatch(1);
+
+ final CountDownLatch stopLatch = new CountDownLatch(2);
+
+ final AtomicInteger countFails = new AtomicInteger();
+
+ final AtomicInteger exceptionFails = new AtomicInteger();
+
+ final String cacheName = "TEST_CACHE";
+
+ runAsync(new Runnable() {
+ @Override public void run() {
+ try {
+ startLatch.await();
+
+ IgniteCache<Object, Object> cache = client2.cache(cacheName);
+
+ if (cache == null)
+ countFails.incrementAndGet();
+
+ stopLatch.countDown();
+ }
+ catch (Exception e) {
+ exceptionFails.incrementAndGet();
+ }
+ }
+ });
+
+ runAsync(new Runnable() {
+ @Override public void run() {
+ try {
+ startLatch.await();
+
+ IgniteCache<Object, Object> cache = client2.cache(cacheName);
+
+ if (cache == null)
+ countFails.incrementAndGet();
+
+ stopLatch.countDown();
+ }
+ catch (Exception e) {
+ exceptionFails.incrementAndGet();
+ }
+ }
+ });
+
+ client1.getOrCreateCache(cacheName);
+
+ startLatch.countDown();
+
+ IgniteCache<Object, Object> cache = client2.cache(cacheName);
+
+ if (cache == null)
+ countFails.incrementAndGet();
+
+ stopLatch.await();
+
+ if (countFails.get() != 0 || exceptionFails.get() != 0)
+ fail("Cache return null in " + countFails.get() + " of 3 cases. Total exception: " + exceptionFails.get());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/2999ffd5/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 218f658..065147e 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
@@ -755,6 +755,72 @@ public final class GridTestUtils {
}
/**
+ * Create future async result.
+ *
+ * @param thrFactory Thr factory.
+ */
+ private static<T> GridFutureAdapter<T> createFutureAdapter(final GridTestSafeThreadFactory thrFactory){
+ return new GridFutureAdapter<T>() {
+ @Override public boolean cancel() throws IgniteCheckedException {
+ super.cancel();
+
+ thrFactory.interruptAllThreads();
+
+ onCancelled();
+
+ return true;
+ }
+ };
+ }
+
+ /**
+ * Runs runnable task asyncronously.
+ *
+ * @param task Runnable.
+ * @return Future with task result.
+ */
+ @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
+ public static IgniteInternalFuture runAsync(final Runnable task) {
+ return runAsync(task,"async-runnable-runner");
+ }
+
+ /**
+ * Runs runnable task asyncronously.
+ *
+ * @param task Runnable.
+ * @return Future with task result.
+ */
+ @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
+ public static IgniteInternalFuture runAsync(final Runnable task, String threadName) {
+ if (!busyLock.enterBusy())
+ throw new IllegalStateException("Failed to start new threads (test is being stopped).");
+
+ try {
+ final GridTestSafeThreadFactory thrFactory = new GridTestSafeThreadFactory(threadName);
+
+ final GridFutureAdapter fut = createFutureAdapter(thrFactory);
+
+ thrFactory.newThread(new Runnable() {
+ @Override public void run() {
+ try {
+ task.run();
+
+ fut.onDone();
+ }
+ catch (Throwable e) {
+ fut.onDone(e);
+ }
+ }
+ }).start();
+
+ return fut;
+ }
+ finally {
+ busyLock.leaveBusy();
+ }
+ }
+
+ /**
* Runs callable task asyncronously.
*
* @param task Callable.
@@ -762,7 +828,7 @@ public final class GridTestUtils {
*/
@SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
public static <T> IgniteInternalFuture<T> runAsync(final Callable<T> task) {
- return runAsync(task, "async-runner");
+ return runAsync(task, "async-callable-runner");
}
/**
@@ -780,17 +846,7 @@ public final class GridTestUtils {
try {
final GridTestSafeThreadFactory thrFactory = new GridTestSafeThreadFactory(threadName);
- final GridFutureAdapter<T> fut = new GridFutureAdapter<T>() {
- @Override public boolean cancel() throws IgniteCheckedException {
- super.cancel();
-
- thrFactory.interruptAllThreads();
-
- onCancelled();
-
- return true;
- }
- };
+ final GridFutureAdapter<T> fut = createFutureAdapter(thrFactory);
thrFactory.newThread(new Runnable() {
@Override public void run() {