This is an automated email from the ASF dual-hosted git repository.

stefanegli pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-oak.git


The following commit(s) were added to refs/heads/master by this push:
     new f0f1614  SLING-11805 : Don't stop slingId cleanup upon 
PROPERTIES_CHANGED (#14)
f0f1614 is described below

commit f0f16146066af3d2f9b5570f8f50b80aa4174706
Author: stefan-egli <[email protected]>
AuthorDate: Mon Mar 20 09:56:05 2023 +0100

    SLING-11805 : Don't stop slingId cleanup upon PROPERTIES_CHANGED (#14)
    
    * SLING-11805 : added test to reproduce the current restricted behaviour
    
    * SLING-11805 : PROPERTIES_CHANGED should not stop slingId cleanup
---
 .../sling/discovery/oak/SlingIdCleanupTask.java     | 14 +++++++++++---
 .../sling/discovery/oak/TestSlingIdCleanupTask.java | 21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/discovery/oak/SlingIdCleanupTask.java 
b/src/main/java/org/apache/sling/discovery/oak/SlingIdCleanupTask.java
index 3316cbc..fb51070 100644
--- a/src/main/java/org/apache/sling/discovery/oak/SlingIdCleanupTask.java
+++ b/src/main/java/org/apache/sling/discovery/oak/SlingIdCleanupTask.java
@@ -273,12 +273,16 @@ public class SlingIdCleanupTask implements 
TopologyEventListener, Runnable {
             return;
         }
         final TopologyView newView = event.getNewView();
-        if (newView == null || event.getType() == Type.PROPERTIES_CHANGED) {
+        if (event.getType() == Type.PROPERTIES_CHANGED) {
+            // ignore those
+        } else if (newView == null) {
+            // that's a TOPOLOGY_CHANGING
             hasTopology = false; // stops potentially ongoing deletion
             currentView = null;
             // cancel cleanup schedule
             stop();
         } else {
+            // that's TOPOLOGY_INIT or TOPOLOGY_CHANGED
             hasTopology = true;
             currentView = newView;
             seenInstances.addAll(getActiveSlingIds(newView));
@@ -303,7 +307,11 @@ public class SlingIdCleanupTask implements 
TopologyEventListener, Runnable {
             return;
         }
         final boolean unscheduled = localScheduler.unschedule(SCHEDULE_NAME);
-        logger.debug("stop: unschedule result={}", unscheduled);
+        if (unscheduled) {
+            logger.info("stop: unscheduled");
+        } else {
+            logger.debug("stop: unschedule was not necessary");
+        }
     }
 
     /**
@@ -340,7 +348,7 @@ public class SlingIdCleanupTask implements 
TopologyEventListener, Runnable {
         }
         cal.add(Calendar.MILLISECOND, delayMillis);
         final Date scheduledDate = cal.getTime();
-        logger.debug(
+        logger.info(
                 "recreateSchedule: scheduling a cleanup in {} milliseconds 
from now, which is: {}",
                 delayMillis, scheduledDate);
         ScheduleOptions options = localScheduler.AT(scheduledDate);
diff --git 
a/src/test/java/org/apache/sling/discovery/oak/TestSlingIdCleanupTask.java 
b/src/test/java/org/apache/sling/discovery/oak/TestSlingIdCleanupTask.java
index 01ed7b9..0a95df4 100644
--- a/src/test/java/org/apache/sling/discovery/oak/TestSlingIdCleanupTask.java
+++ b/src/test/java/org/apache/sling/discovery/oak/TestSlingIdCleanupTask.java
@@ -426,6 +426,27 @@ public class TestSlingIdCleanupTask {
         assertEquals(10, cleanupTask.getDeleteCount());
     }
 
+    @Test
+    public void testTopologyThenPropertiesChanged() throws Exception {
+        createCleanupTask(1000, 86400000);
+        assertEquals(0, cleanupTask.getDeleteCount());
+        createSlingIds(5, 10, 0);
+
+        TopologyView view1 = newView();
+        cleanupTask.handleTopologyEvent(newInitEvent(view1));
+        cleanupTask.handleTopologyEvent(newChangingEvent(view1));
+        assertEquals(0, cleanupTask.getDeleteCount());
+
+        TopologyView view2 = newView();
+        cleanupTask.handleTopologyEvent(newChangedEvent(view1, view2));
+        // below properties changed event must not stop the cleanup
+        cleanupTask.handleTopologyEvent(newPropertiesChangedEvent(view1, 
view2));
+        Thread.sleep(500);
+        assertEquals(0, cleanupTask.getDeleteCount());
+        waitForRunCount(cleanupTask, 1, 5000);
+        assertEquals(10, cleanupTask.getDeleteCount());
+    }
+
     @Test
     public void testRepetitionDelay() throws Exception {
         createCleanupTask(1000, 86400000);

Reply via email to