ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # sprint-45 avoid starting two timer threads in tests
Date Mon, 23 Mar 2015 13:36:52 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 c1c464bd7 -> 6e2dbd9c6


# sprint-45 avoid starting two timer threads in tests


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

Branch: refs/heads/ignite-45
Commit: 6e2dbd9c6bcb7e8f14a834d18294ef63cd853693
Parents: c1c464b
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Mar 23 16:25:16 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Mar 23 16:25:16 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/IgniteKernal.java   |  8 +++++++-
 .../apache/ignite/internal/util/IgniteUtils.java   | 17 ++++++++++++-----
 .../ignite/internal/util/GridTestClockTimer.java   | 11 +++++++++++
 .../testframework/junits/GridAbstractTest.java     |  3 +++
 4 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6e2dbd9c/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 41cceac..a0da259 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1867,7 +1867,13 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
                         NL);
                 }
 
-            U.onGridStop();
+            try {
+                U.onGridStop();
+            }
+            catch (InterruptedException e) {
+                // Preserve interrupt status.
+                Thread.currentThread().interrupt();
+            }
         }
         else {
             // Proper notification.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6e2dbd9c/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index c2cbabf..7d2b646 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -289,10 +289,10 @@ public abstract class IgniteUtils {
     private static Thread timer;
 
     /** Grid counter. */
-    private static int gridCnt;
+    static int gridCnt;
 
     /** Mutex. */
-    private static final Object mux = new Object();
+    static final Object mux = new Object();
 
     /** Exception converters. */
     private static final Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException,
IgniteException>>
@@ -2784,6 +2784,8 @@ public abstract class IgniteUtils {
     public static void onGridStart() {
         synchronized (mux) {
             if (gridCnt == 0) {
+                assert timer == null;
+
                 timer = new Thread(new Runnable() {
                     @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"})
                     @Override public void run() {
@@ -2813,8 +2815,9 @@ public abstract class IgniteUtils {
 
     /**
      * Stops clock timer if all nodes into JVM were stopped.
+     * @throws InterruptedException If interrupted.
      */
-    public static void onGridStop(){
+    public static void onGridStop() throws InterruptedException {
         synchronized (mux) {
             // Grid start may fail and onGridStart() does not get called.
             if (gridCnt == 0)
@@ -2822,10 +2825,14 @@ public abstract class IgniteUtils {
 
             --gridCnt;
 
-            if (gridCnt == 0 && timer != null) {
-                timer.interrupt();
+            Thread timer0 = timer;
 
+            if (gridCnt == 0 && timer0 != null) {
                 timer = null;
+
+                timer0.interrupt();
+
+                timer0.join();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6e2dbd9c/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java
index 079185d..834914b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java
@@ -21,6 +21,17 @@ package org.apache.ignite.internal.util;
  * Clock timer for tests.
  */
 public class GridTestClockTimer implements Runnable {
+    /**
+     * Constructor.
+     */
+    public GridTestClockTimer() {
+        synchronized (IgniteUtils.mux) {
+            assert IgniteUtils.gridCnt == 0 : IgniteUtils.gridCnt;
+
+            IgniteUtils.gridCnt++; // To prevent one more timer thread start from IgniteUtils.onGridStart.
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public void run() {
         while (true) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6e2dbd9c/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 546cae3..29b832e 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -96,6 +96,9 @@ public abstract class GridAbstractTest extends TestCase {
     /** Starting grid name. */
     protected static ThreadLocal<String> startingGrid = new ThreadLocal<>();
 
+    /**
+     *
+     */
     static {
         System.setProperty(IgniteSystemProperties.IGNITE_ATOMIC_CACHE_DELETE_HISTORY_SIZE,
"10000");
         System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false");


Mime
View raw message