You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2021/09/07 18:32:01 UTC
[sling-org-apache-sling-app-cms] branch master updated: SLING-10653
- make sure agent target is set
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new 82febd5 SLING-10653 - make sure agent target is set
82febd5 is described below
commit 82febd5900817448b012018f3e9d31bceb5e2088
Author: Dan Klco <kl...@adobe.com>
AuthorDate: Tue Sep 7 14:31:53 2021 -0400
SLING-10653 - make sure agent target is set
---
.../ForwardAgentEndpointSynchronization.java | 13 ++++++-
.../ForwardAgentEndpointSynchronizationTest.java | 40 ++++++++++++++++++----
2 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/core/src/main/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronization.java b/core/src/main/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronization.java
index cef9cd0..c147419 100644
--- a/core/src/main/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronization.java
+++ b/core/src/main/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronization.java
@@ -22,6 +22,7 @@ import java.util.Dictionary;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.cms.publication.INSTANCE_TYPE;
import org.apache.sling.discovery.InstanceDescription;
import org.apache.sling.discovery.TopologyEvent;
@@ -56,7 +57,7 @@ public class ForwardAgentEndpointSynchronization implements TopologyEventListene
}
private void updateInstances(Set<InstanceDescription> instances) {
- log.info("updateInstances");
+ log.trace("updateInstances");
String[] endpoints = instances.stream().map(id -> {
String endpointBase = id.getProperty(InstanceDescription.PROPERTY_ENDPOINTS).split("\\,")[0];
@@ -90,8 +91,18 @@ public class ForwardAgentEndpointSynchronization implements TopologyEventListene
}
}
+ private boolean agentTargetSet() {
+ return StringUtils.isNotBlank(config.agentTarget());
+ }
+
@Override
public void handleTopologyEvent(TopologyEvent event) {
+
+ if (!agentTargetSet()) {
+ log.debug("Agent targets not set, skipping update");
+ return;
+ }
+
Set<InstanceDescription> renderers = event.getNewView().findInstances(id -> INSTANCE_TYPE.RENDERER.toString()
.equals(id.getProperty(PublicationPropertyProvider.INSTANCE_TYPE)));
updateInstances(renderers);
diff --git a/core/src/test/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronizationTest.java b/core/src/test/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronizationTest.java
index 95afcae..92e8c0f 100644
--- a/core/src/test/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronizationTest.java
+++ b/core/src/test/java/org/apache/sling/cms/core/publication/ForwardAgentEndpointSynchronizationTest.java
@@ -16,8 +16,11 @@
*/
package org.apache.sling.cms.core.publication;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -54,10 +57,10 @@ public class ForwardAgentEndpointSynchronizationTest {
ConfigurationAdmin configAdmin = Mockito.mock(ConfigurationAdmin.class);
Configuration sampleConfig = Mockito.mock(Configuration.class);
- Dictionary<String,Object> properties = new Hashtable<>();
+ Dictionary<String, Object> properties = new Hashtable<>();
Mockito.when(sampleConfig.getPid()).thenReturn("org.apache.sling");
Mockito.when(sampleConfig.getProperties()).thenReturn(properties);
-
+
Mockito.when(configAdmin.listConfigurations(Mockito.any())).thenReturn(new Configuration[] { sampleConfig });
ForwardAgentEndpointSynchronization sync = new ForwardAgentEndpointSynchronization(configAdmin,
@@ -70,7 +73,7 @@ public class ForwardAgentEndpointSynchronizationTest {
@Override
public String agentTarget() {
- return null;
+ return "(thing=1)";
}
});
@@ -80,6 +83,30 @@ public class ForwardAgentEndpointSynchronizationTest {
}
@Test
+ public void testNoTarget() throws IOException, InvalidSyntaxException {
+ TopologyEvent event = Mockito.mock(TopologyEvent.class);
+ ConfigurationAdmin configAdmin = Mockito.mock(ConfigurationAdmin.class);
+
+ ForwardAgentEndpointSynchronization sync = new ForwardAgentEndpointSynchronization(configAdmin,
+ new ForwardAgentEndpointSynchronizationConfig() {
+
+ @Override
+ public Class<? extends Annotation> annotationType() {
+ return null;
+ }
+
+ @Override
+ public String agentTarget() {
+ return null;
+ }
+
+ });
+ sync.handleTopologyEvent(event);
+ verify(event, never()).getNewView();
+
+ }
+
+ @Test
public void testNoConfigurations() throws IOException, InvalidSyntaxException {
TopologyEvent event = Mockito.mock(TopologyEvent.class);
@@ -99,12 +126,13 @@ public class ForwardAgentEndpointSynchronizationTest {
@Override
public String agentTarget() {
- return null;
+ return "(thing=1)";
}
});
sync.handleTopologyEvent(event);
- assertFalse(false);
+ verify(event, times(1)).getNewView();
+ verify(configAdmin, times(1)).listConfigurations(anyString());
}
}