sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-discovery-base] 10/20: SLING-5279 : tests made more stable wrt stopping a VirtualInstance that was likely not done yet and interfered with subsequent test runs
Date Tue, 07 Nov 2017 09:26:07 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.discovery.base-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-base.git

commit 37ae575d43ba65bd2340da4703d8d433116d46b5
Author: Stefan Egli <stefanegli@apache.org>
AuthorDate: Mon Nov 9 10:13:58 2015 +0000

    SLING-5279 : tests made more stable wrt stopping a VirtualInstance that was likely not
done yet and interfered with subsequent test runs
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/base@1713364
13f79535-47bb-0310-9956-ffa450edef68
---
 .../discovery/base/its/setup/VirtualInstance.java  | 41 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
index 2a12483..0309d91 100644
--- a/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
+++ b/src/test/java/org/apache/sling/discovery/base/its/setup/VirtualInstance.java
@@ -105,21 +105,37 @@ public class VirtualInstance {
 
     	private final int intervalInSeconds;
 
-    	private boolean stopped_ = false;
+    	private boolean stopping_ = false;
 
-		public ViewCheckerRunner(int intervalInSeconds) {
+        private volatile boolean stopped_ = false;
+
+        public ViewCheckerRunner(int intervalInSeconds) {
     		this.intervalInSeconds = intervalInSeconds;
     	}
 
 		public synchronized void stop() {
 			logger.info("Stopping Instance ["+slingId+"]");
-			stopped_ = true;
+			stopping_ = true;
+			this.notifyAll();
+		}
+		
+		public boolean hasStopped() {
+		    return stopped_;
 		}
 
 		public void run() {
+		    try{
+		        doRun();
+		    } finally {
+		        stopped_ = true;
+                logger.info("Instance ["+slingId+"] stopped.");
+		    }
+		}
+		
+		public void doRun() {
 			while(true) {
 				synchronized(this) {
-					if (stopped_) {
+					if (stopping_) {
 						logger.info("Instance ["+slingId+"] stopps.");
 						return;
 					}
@@ -129,11 +145,13 @@ public class VirtualInstance {
 				} catch(Exception e) {
 				    logger.error("run: ping connector for slingId="+slingId+" threw exception: "+e, e);
 				}
-				try {
-					Thread.sleep(intervalInSeconds*1000);
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-					return;
+				synchronized(this) {
+    				try {
+    					this.wait(intervalInSeconds*1000);
+    				} catch (InterruptedException e) {
+    					e.printStackTrace();
+    					return;
+    				}
 				}
 			}
 		}
@@ -318,6 +336,11 @@ public class VirtualInstance {
     public void stopViewChecker() throws Throwable {
     	if (viewCheckerRunner!=null) {
     		viewCheckerRunner.stop();
+    		while(!viewCheckerRunner.hasStopped()) {
+    		    logger.info("stopViewChecker: ["+getDebugName()+"] waiting for viewCheckerRunner
to stop");
+    		    Thread.sleep(500);
+    		}
+            logger.info("stopViewChecker: ["+getDebugName()+"] viewCheckerRunner stopped");
     		viewCheckerRunner = null;
     	}
         try{

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message