You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:26:14 UTC
[sling-org-apache-sling-discovery-commons] 11/38: SLING-4697 :
support for PROPERTIES_CHANGED in ViewStateManagerImpl tested and thus
fixed
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.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-commons.git
commit bb3d20df478702bb2f5b50f25ba3eab0a72bfe0c
Author: Stefan Egli <st...@apache.org>
AuthorDate: Thu Oct 8 15:33:06 2015 +0000
SLING-4697 : support for PROPERTIES_CHANGED in ViewStateManagerImpl tested and thus fixed
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/commons@1707571 13f79535-47bb-0310-9956-ffa450edef68
---
.../providers/impl/ViewStateManagerImpl.java | 8 ++++---
.../providers/impl/SimpleInstanceDescription.java | 13 +++++++++--
.../commons/providers/impl/SimpleTopologyView.java | 5 +++-
.../providers/impl/TestViewStateManager.java | 27 +++++++++++++++++++++-
4 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/sling/discovery/commons/providers/impl/ViewStateManagerImpl.java b/src/main/java/org/apache/sling/discovery/commons/providers/impl/ViewStateManagerImpl.java
index 5462174..fe7e527 100644
--- a/src/main/java/org/apache/sling/discovery/commons/providers/impl/ViewStateManagerImpl.java
+++ b/src/main/java/org/apache/sling/discovery/commons/providers/impl/ViewStateManagerImpl.java
@@ -439,9 +439,11 @@ class ViewStateManagerImpl implements ViewStateManager {
logger.debug("handleNewViewNonDelayed: we were not in changing state and new view matches old, so - ignoring");
return false;
}
- logger.debug("handleNewViewNonDelayed: implicitly triggering a handleChanging as we were not in changing state");
- handleChanging();
- logger.debug("handleNewViewNonDelayed: implicitly triggering of a handleChanging done");
+ if (previousView==null || !isPropertiesDiff(newView)) {
+ logger.debug("handleNewViewNonDelayed: implicitly triggering a handleChanging as we were not in changing state");
+ handleChanging();
+ logger.debug("handleNewViewNonDelayed: implicitly triggering of a handleChanging done");
+ }
}
if (!activated) {
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleInstanceDescription.java b/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleInstanceDescription.java
index f5a485f..f6c8893 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleInstanceDescription.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleInstanceDescription.java
@@ -30,7 +30,7 @@ public class SimpleInstanceDescription implements InstanceDescription {
private final boolean isLeader;
private final boolean isLocal;
private final String slingId;
- private final Map<String, String> properties;
+ private Map<String, String> properties;
public SimpleInstanceDescription(boolean isLeader, boolean isLocal, String slingId,
Map<String, String> properties) {
@@ -65,7 +65,9 @@ public class SimpleInstanceDescription implements InstanceDescription {
if (isLocal!=other.isLocal) {
return false;
}
- return true;
+ Map<String, String> myProperties = getProperties();
+ Map<String, String> otherProperties = other.getProperties();
+ return (myProperties.equals(otherProperties));
}
public void setClusterView(ClusterView clusterView) {
@@ -105,4 +107,11 @@ public class SimpleInstanceDescription implements InstanceDescription {
return new HashMap<String,String>(properties);
}
+ public void setProperty(String key, String value) {
+ if (properties==null) {
+ properties = new HashMap<String, String>();
+ }
+ properties.put(key, value);
+ }
+
}
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleTopologyView.java b/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleTopologyView.java
index ac9e292..e0add44 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleTopologyView.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/impl/SimpleTopologyView.java
@@ -163,7 +163,7 @@ public class SimpleTopologyView extends BaseTopologyView {
final boolean isLeader = artefact.isLeader();
final boolean isLocal = artefact.isLocal();
SimpleClusterView cluster = (SimpleClusterView) artefact.getClusterView();
- final SimpleInstanceDescription instance = new SimpleInstanceDescription(isLeader, isLocal, slingId, null);
+ final SimpleInstanceDescription instance = new SimpleInstanceDescription(isLeader, isLocal, slingId, artefact.getProperties());
instance.setClusterView(cluster);
cluster.addInstanceDescription(instance);
instances.add(instance);
@@ -201,6 +201,9 @@ public class SimpleTopologyView extends BaseTopologyView {
clone.setClusterView(cluster);
result.addInstance(clone);
}
+ if (!view.isCurrent()) {
+ result.setNotCurrent();
+ }
return result;
}
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/impl/TestViewStateManager.java b/src/test/java/org/apache/sling/discovery/commons/providers/impl/TestViewStateManager.java
index 48f88fb..1ef9050 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/impl/TestViewStateManager.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/impl/TestViewStateManager.java
@@ -30,6 +30,7 @@ import java.util.concurrent.locks.ReentrantLock;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
+import org.apache.sling.discovery.InstanceDescription;
import org.apache.sling.discovery.TopologyEvent;
import org.apache.sling.discovery.commons.providers.BaseTopologyView;
import org.apache.sling.discovery.commons.providers.EventFactory;
@@ -219,6 +220,29 @@ public class TestViewStateManager {
}
@Test
+ public void testPropertiesChanged() throws Exception {
+ final Listener listener = new Listener();
+ mgr.handleActivated();
+ mgr.bind(listener);
+ mgr.handleChanging();
+ SimpleTopologyView oldView = new SimpleTopologyView().addInstance();
+ SimpleInstanceDescription localInstance =
+ (SimpleInstanceDescription) oldView.getLocalInstance();
+ localInstance.setProperty("foo", "bar1");
+ mgr.handleNewView(oldView);
+ TopologyEvent initEvent = EventFactory.newInitEvent(oldView.clone());
+ assertEvents(listener, initEvent);
+ SimpleTopologyView newView = oldView.clone();
+ oldView.setNotCurrent();
+ localInstance = (SimpleInstanceDescription) newView.getLocalInstance();
+ localInstance.setProperty("foo", "bar2");
+ mgr.handleNewView(newView);
+ Thread.sleep(2000);
+ TopologyEvent propertiesChangedEvent = EventFactory.newPropertiesChangedEvent(oldView.clone(), newView.clone());
+ assertEvents(listener, propertiesChangedEvent);
+ }
+
+ @Test
public void testActivateChangingBindChanged() throws Exception {
final Listener listener = new Listener();
// first activate
@@ -464,9 +488,10 @@ public class TestViewStateManager {
serviceSemaphore.release(1);
Thread.sleep(1000);
assertEvents(listener, EventFactory.newInitEvent(view1));
+ final SimpleTopologyView view2 = view1.clone();
mgr.handleChanging();
assertEvents(listener, EventFactory.newChangingEvent(view1));
- final SimpleTopologyView view2 = SimpleTopologyView.clone(view1).removeInstance(slingId2);
+ view2.removeInstance(slingId2);
async(new Runnable() {
public void run() {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.