You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2020/01/30 10:41:19 UTC
[sling-org-apache-sling-distribution-journal] branch master
updated: SLING-9029 Warning logged by PackageQueuedNotifier if a
DistributionPackage does not exist in the callback map (#23)
This is an automated email from the ASF dual-hosted git repository.
tmaret pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git
The following commit(s) were added to refs/heads/master by this push:
new 6c1ac99 SLING-9029 Warning logged by PackageQueuedNotifier if a DistributionPackage does not exist in the callback map (#23)
6c1ac99 is described below
commit 6c1ac9980363ef420591c3f0784e8780b104d3fd
Author: Mohit Arora <mo...@adobe.com>
AuthorDate: Thu Jan 30 16:11:10 2020 +0530
SLING-9029 Warning logged by PackageQueuedNotifier if a DistributionPackage does not exist in the callback map (#23)
SLING-9029 - PackageQueuedNotifier throws NPE for packages managed by an other type of agents
---
.../journal/impl/publisher/PackageQueuedNotifier.java | 5 ++++-
.../impl/publisher/PackageQueuedNotifierTest.java | 17 ++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifier.java b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifier.java
index 29c559e..8899397 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifier.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifier.java
@@ -63,7 +63,10 @@ public class PackageQueuedNotifier implements EventHandler {
public void handleEvent(Event event) {
String packageId = (String) event.getProperty(DistributionEvent.PACKAGE_ID);
LOG.debug("Handling event for packageId {}", packageId);
- CompletableFuture<Void> callback = receiveCallbacks.remove(packageId);
+ CompletableFuture<Void> callback = null;
+ if (packageId != null) {
+ callback = receiveCallbacks.remove(packageId);
+ }
if (callback != null) {
callback.complete(null);
}
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifierTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifierTest.java
index 5cb45f0..2444d21 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifierTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/PackageQueuedNotifierTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.distribution.journal.impl.publisher;
+import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -25,10 +26,11 @@ import java.util.concurrent.TimeoutException;
import org.junit.Assert;
import org.junit.Test;
-
+import org.osgi.service.event.Event;
import org.apache.sling.distribution.journal.impl.event.DistributionEvent;
import org.apache.sling.distribution.journal.messages.Messages.PackageMessage;
import org.apache.sling.distribution.journal.messages.Messages.PackageMessage.ReqType;
+import static org.apache.sling.distribution.event.DistributionEventTopics.AGENT_PACKAGE_QUEUED;
public class PackageQueuedNotifierTest {
@@ -50,6 +52,19 @@ public class PackageQueuedNotifierTest {
arrived.get(1, TimeUnit.SECONDS);
}
+ @Test
+ public void testForNullPackage() throws InterruptedException, ExecutionException, TimeoutException {
+ notifier = new PackageQueuedNotifier();
+ CompletableFuture<Void> arrived = notifier.registerWait("1");
+ notifier.handleEvent(new Event(AGENT_PACKAGE_QUEUED, new HashMap<>()));
+ try {
+ arrived.get(100,TimeUnit.MILLISECONDS);
+ Assert.fail("Expected TimeoutException as package ID is null");
+ } catch (TimeoutException e) {
+ // Expected
+ }
+ }
+
private PackageMessage pkgMsg(String packageId) {
return PackageMessage.newBuilder()
.addPaths("/test")