sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stefane...@apache.org
Subject svn commit: r1686851 - /sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java
Date Mon, 22 Jun 2015 12:37:20 GMT
Author: stefanegli
Date: Mon Jun 22 12:37:19 2015
New Revision: 1686851

URL: http://svn.apache.org/r1686851
Log:
SLING-4385 : TopologyEventTest was failing due to listeners of earlier LargeTopologyWithHubTest
test still having events enqueued, thus causing a backlog of events, thus the tests own listener
would not be served within reasonable amount of time, thus the voting would not conclude.
Fixed by making sure a test Instance, when stopped, actually stops handling any subsequent
events. This should help avoid any event backlogs. Could also fix other intermittent test
failures

Modified:
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java

Modified: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java?rev=1686851&r1=1686850&r2=1686851&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java
(original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/setup/Instance.java
Mon Jun 22 12:37:19 2015
@@ -214,7 +214,7 @@ public class Instance {
 
     private MyConfig config;
 
-    private EventListener observationListener;
+    private MyEventListener observationListener;
 
     private ObservationManager observationManager;
 
@@ -258,6 +258,63 @@ public class Instance {
             throws Exception {
     	this("/var/discovery/impl/", debugName, resourceResolverFactory, resetRepo, 20, 20,
1, UUID.randomUUID().toString(), false);
     }
+    
+    private class MyEventListener implements EventListener {
+        
+        volatile boolean stopped = false;
+        private final String slingId;
+        
+        public MyEventListener(String slingId) {
+            this.slingId = slingId;
+        }
+        
+        public void stop() {
+            logger.debug("stop: stopping listener for slingId: "+slingId);
+            stopped = true;
+        }
+
+        public void onEvent(EventIterator events) {
+            if (stopped) {
+                logger.info("onEvent: listener: "+slingId+" getting late events even though
stopped: "+events.hasNext());
+                return;
+            }
+            try {
+                while (!stopped && events.hasNext()) {
+                    Event event = events.nextEvent();
+                    Properties properties = new Properties();
+                    String topic;
+                    if (event.getType() == Event.NODE_ADDED) {
+                        topic = SlingConstants.TOPIC_RESOURCE_ADDED;
+                    } else if (event.getType() == Event.NODE_MOVED) {
+                        topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
+                    } else if (event.getType() == Event.NODE_REMOVED) {
+                        topic = SlingConstants.TOPIC_RESOURCE_REMOVED;
+                    } else {
+                        topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
+                    }
+                    try {
+                        properties.put("path", event.getPath());
+                        org.osgi.service.event.Event osgiEvent = new org.osgi.service.event.Event(
+                                topic, properties);
+                        votingHandler.handleEvent(osgiEvent);
+                    } catch (RepositoryException e) {
+                        logger.warn("RepositoryException: " + e, e);
+                    }
+                }
+                if (stopped) {
+                    logger.info("onEvent: listener stopped: "+slingId+", pending events:
"+events.hasNext());
+                }
+            } catch (Throwable th) {
+                try {
+                    dumpRepo();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                logger.error(
+                        "Throwable occurred in onEvent: " + th, th);
+            }
+        }
+    }
 
     private Instance(String discoveryResourcePath, String debugName,
             ResourceResolverFactory resourceResolverFactory, boolean resetRepo,
@@ -312,44 +369,7 @@ public class Instance {
         observationManager = session.getWorkspace()
                 .getObservationManager();
 
-        observationListener =
-                new EventListener() {
-
-                    public void onEvent(EventIterator events) {
-                        try {
-                            while (events.hasNext()) {
-                                Event event = events.nextEvent();
-                                Properties properties = new Properties();
-                                String topic;
-                                if (event.getType() == Event.NODE_ADDED) {
-                                    topic = SlingConstants.TOPIC_RESOURCE_ADDED;
-                                } else if (event.getType() == Event.NODE_MOVED) {
-                                    topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
-                                } else if (event.getType() == Event.NODE_REMOVED) {
-                                    topic = SlingConstants.TOPIC_RESOURCE_REMOVED;
-                                } else {
-                                    topic = SlingConstants.TOPIC_RESOURCE_CHANGED;
-                                }
-                                try {
-                                    properties.put("path", event.getPath());
-                                    org.osgi.service.event.Event osgiEvent = new org.osgi.service.event.Event(
-                                            topic, properties);
-                                    votingHandler.handleEvent(osgiEvent);
-                                } catch (RepositoryException e) {
-                                    logger.warn("RepositoryException: " + e, e);
-                                }
-                            }
-                        } catch (Throwable th) {
-                            try {
-                                dumpRepo();
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                            }
-                            logger.error(
-                                    "Throwable occurred in onEvent: " + th, th);
-                        }
-                    }
-        };
+        observationListener = new MyEventListener(slingId);
         observationManager.addEventListener(
                 observationListener
                 , Event.NODE_ADDED | Event.NODE_REMOVED | Event.NODE_MOVED
@@ -629,6 +649,9 @@ public class Instance {
     	} else {
     	    logger.warn("stop: could not remove listener for slingId="+slingId+", debugName="+debugName+",
observationManager="+observationManager+", observationListener="+observationListener);
     	}
+    	if (observationListener!=null) {
+    	    observationListener.stop();
+    	}
 
         if (resourceResolver != null) {
             resourceResolver.close();



Mime
View raw message