addy0001 closed pull request #9: SLING-7902 Reading the http.conn.timeout
values from the config.
URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/9
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
b/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
index 5473ed7..8705e2b 100644
---
a/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
+++
b/src/main/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactory.java
@@ -237,7 +237,6 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
String serviceName =
SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(SERVICE_NAME),
null));
String[] allowedRoots =
PropertiesUtil.toStringArray(config.get(ALLOWED_ROOTS), null);
allowedRoots = SettingsUtils.removeEmptyEntries(allowedRoots);
-
boolean queueProcessingEnabled =
PropertiesUtil.toBoolean(config.get(QUEUE_PROCESSING_ENABLED), true);
String[] passiveQueues =
PropertiesUtil.toStringArray(config.get(PASSIVE_QUEUES), new String[0]);
@@ -246,13 +245,28 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
Map<String, String> priorityQueues =
PropertiesUtil.toMap(config.get(PRIORITY_QUEUES), new String[0]);
priorityQueues = SettingsUtils.removeEmptyEntries(priorityQueues);
- Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
+ Integer timeout = PropertiesUtil.toInteger(config.get(HTTP), 10) *
1000;
+
+ String queueProviderName =
PropertiesUtil.toString(config.get(QUEUE_PROVIDER),
JobHandlingDistributionQueueProvider.TYPE);
+ boolean asyncDelivery =
PropertiesUtil.toBoolean(config.get(ASYNC_DELIVERY), false);
+ String retryStrategy =
SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(RETRY_STRATEGY),
null));
+ int retryAttempts =
PropertiesUtil.toInteger(config.get(RETRY_ATTEMPTS), 100);
+ Map<String, String> importerEndpointsMap =
SettingsUtils.toUriMap(config.get(IMPORTER_ENDPOINTS));
+
+
+ return createAgent(agentName, context, distributionLog, serviceName,
allowedRoots, queueProcessingEnabled, passiveQueues, priorityQueues, timeout,
+ queueProviderName, asyncDelivery, retryStrategy,
retryAttempts, importerEndpointsMap);
+ }
+
+ protected SimpleDistributionAgent createAgent(String agentName,
BundleContext context, DefaultDistributionLog distributionLog,
+ String serviceName, String[]
allowedRoots, boolean queueProcessingEnabled, String[] passiveQueues,
Map<String, String> priorityQueues, Integer timeout,
+ String queueProviderName,
boolean asyncDelivery, String retryStrategy, int retryAttempts, Map<String,
String> importerEndpointsMap) {
+
HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
DistributionPackageExporter packageExporter = new
LocalDistributionPackageExporter(packageBuilder);
DistributionQueueProvider queueProvider;
- String queueProviderName =
PropertiesUtil.toString(config.get(QUEUE_PROVIDER),
JobHandlingDistributionQueueProvider.TYPE);
if
(JobHandlingDistributionQueueProvider.TYPE.equals(queueProviderName)) {
queueProvider = new
JobHandlingDistributionQueueProvider(agentName, jobManager, context,
configAdmin);
} else if
(SimpleDistributionQueueProvider.TYPE.equals(queueProviderName)) {
@@ -266,7 +280,6 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
DistributionQueueDispatchingStrategy errorQueueStrategy = null;
DistributionPackageImporter packageImporter;
- Map<String, String> importerEndpointsMap =
SettingsUtils.toUriMap(config.get(IMPORTER_ENDPOINTS));
Set<String> processingQueues = new HashSet<String>();
Set<String> endpointNames = importerEndpointsMap.keySet();
@@ -285,7 +298,6 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
exportQueueStrategy = dispatchingStrategy;
endpointNames = importerEndpointsMap.keySet();
} else {
- boolean asyncDelivery =
PropertiesUtil.toBoolean(config.get(ASYNC_DELIVERY), false);
if (asyncDelivery) {
// delivery queues' names
Map<String, String> deliveryQueues = new HashMap<String,
String>();
@@ -308,9 +320,6 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
DistributionRequestType[] allowedRequests = new
DistributionRequestType[]{DistributionRequestType.ADD,
DistributionRequestType.DELETE};
- String retryStrategy =
SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(RETRY_STRATEGY),
null));
- int retryAttepts =
PropertiesUtil.toInteger(config.get(RETRY_ATTEMPTS), 100);
-
if ("errorQueue".equals(retryStrategy)) {
errorQueueStrategy = new
ErrorQueueDispatchingStrategy(processingQueues.toArray(new
String[processingQueues.size()]));
}
@@ -318,9 +327,7 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
return new SimpleDistributionAgent(agentName, queueProcessingEnabled,
processingQueues,
serviceName, packageImporter, packageExporter,
requestAuthorizationStrategy,
queueProvider, exportQueueStrategy, errorQueueStrategy,
distributionEventFactory, resourceResolverFactory, slingRepository,
- distributionLog, allowedRequests, allowedRoots, retryAttepts);
-
-
+ distributionLog, allowedRequests, allowedRoots, retryAttempts);
}
@Override
@@ -328,4 +335,4 @@ protected ForwardDistributionAgentMBean
createMBeanAgent(DistributionAgent agent
return new ForwardDistributionAgentMBeanImpl(agent, osgiConfiguration);
}
-}
+}
\ No newline at end of file
diff --git
a/src/main/java/org/apache/sling/distribution/agent/impl/ReverseDistributionAgentFactory.java
b/src/main/java/org/apache/sling/distribution/agent/impl/ReverseDistributionAgentFactory.java
index 31f2ad2..49db09c 100644
---
a/src/main/java/org/apache/sling/distribution/agent/impl/ReverseDistributionAgentFactory.java
+++
b/src/main/java/org/apache/sling/distribution/agent/impl/ReverseDistributionAgentFactory.java
@@ -194,7 +194,7 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
int pullItems = PropertiesUtil.toInteger(config.get(PULL_ITEMS),
Integer.MAX_VALUE);
- Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
+ Integer timeout = PropertiesUtil.toInteger(config.get(HTTP), 10) *
1000;
HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
DistributionPackageExporter packageExporter = new
RemoteDistributionPackageExporter(distributionLog, packageBuilder,
diff --git
a/src/main/java/org/apache/sling/distribution/agent/impl/SyncDistributionAgentFactory.java
b/src/main/java/org/apache/sling/distribution/agent/impl/SyncDistributionAgentFactory.java
index 337b653..1aa283c 100644
---
a/src/main/java/org/apache/sling/distribution/agent/impl/SyncDistributionAgentFactory.java
+++
b/src/main/java/org/apache/sling/distribution/agent/impl/SyncDistributionAgentFactory.java
@@ -231,7 +231,7 @@ protected SimpleDistributionAgent createAgent(String
agentName, BundleContext co
String[] queueNames = queuesMap.toArray(new String[queuesMap.size()]);
exportQueueStrategy = new MultipleQueueDispatchingStrategy(queueNames);
- Integer timeout = PropertiesUtil.toInteger(HTTP, 10) * 1000;
+ Integer timeout = PropertiesUtil.toInteger(config.get(HTTP), 10) *
1000;
HttpConfiguration httpConfiguration = new HttpConfiguration(timeout);
packageImporter = new
RemoteDistributionPackageImporter(distributionLog, transportSecretProvider,
diff --git
a/src/test/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactoryTest.java
b/src/test/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactoryTest.java
new file mode 100644
index 0000000..6576f31
--- /dev/null
+++
b/src/test/java/org/apache/sling/distribution/agent/impl/ForwardDistributionAgentFactoryTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.distribution.agent.impl;
+
+import org.apache.sling.distribution.log.impl.DefaultDistributionLog;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ForwardDistributionAgentFactoryTest {
+
+ @Spy
+ @InjectMocks
+ ForwardDistributionAgentFactory forwardDistributionAgentFactory = new
ForwardDistributionAgentFactory();
+
+ @Captor
+ ArgumentCaptor<String> serviceNameCaptor;
+
+ @Captor
+ ArgumentCaptor<Boolean> queueProcessingEnabledCaptor;
+
+ @Captor
+ ArgumentCaptor<String[]> passiveQueuesCaptor;
+
+ @Captor
+ ArgumentCaptor<String> queueProviderCaptor;
+
+ @Captor
+ ArgumentCaptor<Boolean> asyncDeliveryCaptor;
+
+ @Captor
+ ArgumentCaptor<String> retryStrategyCaptor;
+
+ @Captor
+ ArgumentCaptor<Integer> timeoutCaptor;
+
+ @Captor
+ ArgumentCaptor<Integer> retryAttemptsCaptor;
+
+ @Captor
+ ArgumentCaptor<String[]> allowedRootsCaptor;
+
+ BundleContext bundleContext;
+ DefaultDistributionLog distributionLog;
+ SimpleDistributionAgent distributionAgent =
mock(SimpleDistributionAgent.class);
+
+ @Test
+ public void testConfigsBeingRead() {
+ Map<String, Object> config = new HashMap<String, Object>();
+ config.put(ForwardDistributionAgentFactory.HTTP, 20);
+ String[] allowedRoots = {"/home"};
+ String[] passiveQueues = {"queue1","queue2"};
+ config.put("allowed.roots",allowedRoots);
+ config.put("queue.processing.enabled",true);
+ config.put("serviceName","serviceName");
+ config.put("passiveQueues",passiveQueues);
+ config.put("queue.provider","simple");
+ config.put("async.delivery",true);
+ config.put("retry.strategy","retryStrategy");
+ config.put("retry.attempts",19);
+
+
doReturn(distributionAgent).when(forwardDistributionAgentFactory).createAgent(any(String.class),
any(BundleContext.class), any(DefaultDistributionLog.class),
any(String.class), allowedRootsCaptor.capture(), any(boolean.class),
any(String[].class),
+ any(Map.class), any(Integer.class), any(String.class),
any(boolean.class), any(String.class), any(int.class), any(Map.class));
+ forwardDistributionAgentFactory.createAgent("test", bundleContext,
config, distributionLog);
+
+ verify(forwardDistributionAgentFactory).createAgent(any(String.class),
any(BundleContext.class), any(DefaultDistributionLog.class),
serviceNameCaptor.capture(), allowedRootsCaptor.capture(),
queueProcessingEnabledCaptor.capture(), passiveQueuesCaptor.capture(),
+ any(Map.class), timeoutCaptor.capture(),
queueProviderCaptor.capture(), asyncDeliveryCaptor.capture(),
retryStrategyCaptor.capture(), retryAttemptsCaptor.capture(), any(Map.class));
+
+ assertEquals("serviceName",serviceNameCaptor.getValue().toString());
+ assertEquals(allowedRoots.length,
allowedRootsCaptor.getValue().length);
+ assertEquals(true,queueProcessingEnabledCaptor.getValue());
+
assertEquals(passiveQueues.length,passiveQueuesCaptor.getValue().length);
+ assertEquals(20000,timeoutCaptor.getValue().intValue());
+ assertEquals("simple",queueProviderCaptor.getValue().toString());
+ assertEquals(true, asyncDeliveryCaptor.getValue());
+ assertEquals("retryStrategy", retryStrategyCaptor.getValue());
+ assertEquals(19, retryAttemptsCaptor.getValue().intValue());
+ }
+}
\ No newline at end of file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services