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-commons] 06/24: SLING-5256 : change in localClusterSyncTokenId should always trigger a TOPOLOGY_CHANGED - ensured by adjusting ViewStateManager.onlyDiffersInProperties and DefaultTopologyView.compareTopology accordingly including new tests for both - plus added OakDiscoveryServiceTest.testDescriptorSeqNumChange to verify that discovery.oak now properly detects otherwise-equal topologies when their sequence_number==localClusterSyncTokenId differs (unlikely to happen under normal load situations though)
Date Tue, 07 Nov 2017 09:26:48 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit d71490a407dc42fd96ab6a6f08b3c1b87b3a9a11
Author: Stefan Egli <stefanegli@apache.org>
AuthorDate: Wed Nov 4 10:37:59 2015 +0000

    SLING-5256 : change in localClusterSyncTokenId should always trigger a TOPOLOGY_CHANGED
- ensured by adjusting ViewStateManager.onlyDiffersInProperties and DefaultTopologyView.compareTopology
accordingly including new tests for both - plus added OakDiscoveryServiceTest.testDescriptorSeqNumChange
to verify that discovery.oak now properly detects otherwise-equal topologies when their sequence_number==localClusterSyncTokenId
differs (unlikely to happen under normal load situations though)
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/commons@1712527
13f79535-47bb-0310-9956-ffa450edef68
---
 .../providers/base/ViewStateManagerImpl.java       |  17 ++++
 .../commons/providers/DummyTopologyView.java       |  11 ++-
 .../providers/base/TestViewStateManager.java       | 100 ++++++++++++++++++++-
 3 files changed, 125 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/discovery/commons/providers/base/ViewStateManagerImpl.java
b/src/main/java/org/apache/sling/discovery/commons/providers/base/ViewStateManagerImpl.java
index 5930022..e5c4e4b 100644
--- a/src/main/java/org/apache/sling/discovery/commons/providers/base/ViewStateManagerImpl.java
+++ b/src/main/java/org/apache/sling/discovery/commons/providers/base/ViewStateManagerImpl.java
@@ -589,6 +589,23 @@ public class ViewStateManagerImpl implements ViewStateManager {
         if (newView==null) {
             throw new IllegalArgumentException("newView must not be null");
         }
+        String previousSyncTokenId = null;
+        String newSyncTokenId = null;
+        try{
+            previousSyncTokenId = previousView.getLocalClusterSyncTokenId();
+        } catch(IllegalStateException re) {
+            previousSyncTokenId = null;
+        }
+        try{
+            newSyncTokenId = newView.getLocalClusterSyncTokenId();
+        } catch(IllegalStateException re) {
+            newSyncTokenId = null;
+        }
+        if ((previousSyncTokenId == null && newSyncTokenId != null)
+                || (newSyncTokenId == null && previousSyncTokenId != null)
+                || (previousSyncTokenId!=null && !previousSyncTokenId.equals(newSyncTokenId)))
{
+            return false;
+        }
         if (previousView.getInstances().size()!=newView.getInstances().size()) {
             return false;
         }
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/DummyTopologyView.java
b/src/test/java/org/apache/sling/discovery/commons/providers/DummyTopologyView.java
index b5314ad..e12b24d 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/DummyTopologyView.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/DummyTopologyView.java
@@ -35,7 +35,7 @@ public class DummyTopologyView extends BaseTopologyView {
 
     private List<InstanceDescription> instances = new LinkedList<InstanceDescription>();
 
-    private final String id;
+    private String id;
 
     public DummyTopologyView() {
         id = UUID.randomUUID().toString();
@@ -45,6 +45,10 @@ public class DummyTopologyView extends BaseTopologyView {
         this.id = id;
     }
     
+    public void setId(String id) {
+        this.id = id;
+    }
+    
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof DummyTopologyView)) {
@@ -54,7 +58,9 @@ public class DummyTopologyView extends BaseTopologyView {
         if (this==other) {
             return true;
         }
-        if (!id.equals(other.id)) {
+        if ((id == null && other.id != null)
+                || (other.id == null && id != null)
+                || (id != null && !id.equals(other.id))) {
             return false;
         }
         if (this.instances.size()!=other.instances.size()) {
@@ -212,4 +218,5 @@ public class DummyTopologyView extends BaseTopologyView {
     public DummyTopologyView clone() {
         return DummyTopologyView.clone(this);
     }
+
 }
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/base/TestViewStateManager.java
b/src/test/java/org/apache/sling/discovery/commons/providers/base/TestViewStateManager.java
index 048b0cd..e7cbcc5 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/base/TestViewStateManager.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/base/TestViewStateManager.java
@@ -86,6 +86,8 @@ public class TestViewStateManager {
     
     private Random defaultRandom;
 
+    private Level logLevel;
+
     @Before
     public void setup() throws Exception {
         mgr = new ViewStateManagerImpl(new ReentrantLock(), new ClusterSyncService() {
@@ -100,6 +102,9 @@ public class TestViewStateManager {
             }
         });
         defaultRandom = new Random(1234123412); // I want randomness yes, but deterministic,
for some methods at least
+        final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+        logLevel = discoveryLogger.getLevel();
+        discoveryLogger.setLevel(Level.INFO);
     }
     
     @After
@@ -110,6 +115,8 @@ public class TestViewStateManager {
         }
         mgr = null;
         defaultRandom= null;
+        final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+        discoveryLogger.setLevel(logLevel);
     }
     
     void assertEvents(DummyListener listener, TopologyEvent... events) {
@@ -683,4 +690,95 @@ public class TestViewStateManager {
         commonsLogger.setLevel(Level.INFO); // back to default
     }
 
-}
+    @Test
+    public void testOnlyDiffersInProperties() throws Exception {
+        final org.apache.log4j.Logger discoveryLogger = LogManager.getRootLogger().getLogger("org.apache.sling.discovery");
+        discoveryLogger.setLevel(Level.DEBUG);
+        logger.info("testOnlyDiffersInProperties: start");
+        final String slingId1 = UUID.randomUUID().toString();
+        final String slingId2 = UUID.randomUUID().toString();
+        final String slingId3 = UUID.randomUUID().toString();
+        final String clusterId = UUID.randomUUID().toString();
+        final DefaultClusterView cluster = new DefaultClusterView(clusterId);
+        final DummyTopologyView view1 = new DummyTopologyView()
+                .addInstance(slingId1, cluster, true, true)
+                .addInstance(slingId2, cluster, false, false)
+                .addInstance(slingId3, cluster, false, false);
+        final DummyTopologyView view2 = DummyTopologyView.clone(view1).removeInstance(slingId2);
+        final DummyTopologyView view3 = DummyTopologyView.clone(view1).removeInstance(slingId2).removeInstance(slingId3);
+        DummyTopologyView view1Cloned = DummyTopologyView.clone(view1);
+        
+        logger.info("testOnlyDiffersInProperties: handleNewView(view1)");
+        mgr.handleNewView(view1);
+        logger.info("testOnlyDiffersInProperties: handleActivated()");
+        mgr.handleActivated();
+        assertEquals(0, mgr.waitForAsyncEvents(5000));
+        assertFalse(mgr.onlyDiffersInProperties(view1));
+        assertFalse(mgr.onlyDiffersInProperties(view2));
+        assertFalse(mgr.onlyDiffersInProperties(view3));
+        logger.info("testOnlyDiffersInProperties: handleNewView(view2)");
+        mgr.handleNewView(view2);
+        assertEquals(0, mgr.waitForAsyncEvents(5000));
+        assertFalse(mgr.onlyDiffersInProperties(view1));
+        assertFalse(mgr.onlyDiffersInProperties(view2));
+        assertFalse(mgr.onlyDiffersInProperties(view3));
+        logger.info("testOnlyDiffersInProperties: handleNewView(view3)");
+        mgr.handleNewView(view3);
+        assertEquals(0, mgr.waitForAsyncEvents(5000));
+        assertFalse(mgr.onlyDiffersInProperties(view1));
+        assertFalse(mgr.onlyDiffersInProperties(view2));
+        assertFalse(mgr.onlyDiffersInProperties(view3));
+
+        final DummyTopologyView view4 = DummyTopologyView.clone(view1Cloned);
+        final DummyTopologyView view5 = DummyTopologyView.clone(view1Cloned);
+        final DummyTopologyView view6 = DummyTopologyView.clone(view1Cloned);
+        logger.info("testOnlyDiffersInProperties: handleNewView(view1cloned)");
+        mgr.handleNewView(view1Cloned);
+        assertEquals(0, mgr.waitForAsyncEvents(5000));
+        DefaultInstanceDescription i4_1 = (DefaultInstanceDescription) view4.getInstance(slingId1);
+        i4_1.setProperty("a", "b");
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view4)");
+        assertTrue(mgr.onlyDiffersInProperties(view4));
+    
+        DefaultInstanceDescription i5_1 = (DefaultInstanceDescription) view5.getInstance(slingId1);
+        i5_1.setProperty("a", "b");
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view5)");
+        assertTrue(mgr.onlyDiffersInProperties(view5));
+        DummyTopologyView view4Cloned = DummyTopologyView.clone(view4);
+        mgr.handleNewView(view4);
+        assertEquals(0, mgr.waitForAsyncEvents(5000));
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view4Cloned)");
+        assertFalse(mgr.onlyDiffersInProperties(view4Cloned));
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view5)");
+        assertFalse(mgr.onlyDiffersInProperties(view5));
+
+        DefaultInstanceDescription i6_1 = (DefaultInstanceDescription) view6.getInstance(slingId1);
+        i6_1.setProperty("a", "c");
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6)");
+        assertTrue(mgr.onlyDiffersInProperties(view6));
+        String originalId = view6.getLocalClusterSyncTokenId();
+        view6.setId(UUID.randomUUID().toString());
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [2]");
+        assertFalse(mgr.onlyDiffersInProperties(view6));
+        view6.setId(originalId);
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [3]");
+        assertTrue(mgr.onlyDiffersInProperties(view6));
+        view6.setId(null);
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [4]");
+        assertFalse(mgr.onlyDiffersInProperties(view6));
+        view6.setId(originalId);
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [5]");
+        assertTrue(mgr.onlyDiffersInProperties(view6));
+        
+        // hack: we're modifying the view *in the ViewStateManagerImpl* here!!:
+        view4.setId(null);
+
+        view6.setId(null);
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [6]");
+        assertTrue(mgr.onlyDiffersInProperties(view6));
+        view6.setId(originalId);
+        logger.info("testOnlyDiffersInProperties: onlyDiffersInProperties(view6) [7]");
+        assertFalse(mgr.onlyDiffersInProperties(view6));
+    }
+
+}
\ No newline at end of file

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

Mime
View raw message