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 2021/06/25 14:54:21 UTC
[sling-org-apache-sling-distribution-journal] 01/01: SLING-10314 -
PubQueueProviderImpl close may throw IllegalStateException
This is an automated email from the ASF dual-hosted git repository.
tmaret pushed a commit to branch SLING-10314
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git
commit 8957db47f3a482b311dfca25571d97df8bceb925
Author: tmaret <tm...@adobe.com>
AuthorDate: Fri Jun 25 16:53:55 2021 +0200
SLING-10314 - PubQueueProviderImpl close may throw IllegalStateException
---
pom.xml | 5 +++++
.../journal/queue/impl/PubQueueProviderImpl.java | 1 +
.../journal/queue/impl/PubQueueProviderTest.java | 13 ++++++++++---
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index a564c59..5b2b330 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,6 +216,11 @@
<version>1.3.2</version>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+ <version>3.1.2</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderImpl.java b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderImpl.java
index 20e11f0..6ee5c31 100644
--- a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderImpl.java
+++ b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderImpl.java
@@ -100,6 +100,7 @@ public class PubQueueProviderImpl implements PubQueueProvider, Runnable {
if (reg != null) {
try {
reg.unregister();
+ reg = null;
} catch (Exception e) {
LOG.info(e.getMessage(), e);
}
diff --git a/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderTest.java b/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderTest.java
index 85e6d24..fbaa44b 100644
--- a/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueProviderTest.java
@@ -20,6 +20,7 @@ package org.apache.sling.distribution.journal.queue.impl;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -58,6 +59,7 @@ import org.apache.sling.distribution.journal.shared.Topics;
import org.apache.sling.distribution.queue.DistributionQueueEntry;
import org.apache.sling.distribution.queue.DistributionQueueItem;
import org.apache.sling.distribution.queue.spi.DistributionQueue;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -102,8 +104,7 @@ public class PubQueueProviderTest {
@Mock
private CacheCallback callback;
- @Mock
- private BundleContext context;
+ private final BundleContext context = MockOsgi.newBundleContext();
private MessageHandler<PackageMessage> handler;
@@ -117,7 +118,7 @@ public class PubQueueProviderTest {
.thenReturn(poller);
when(clientProvider.createPoller(
Mockito.eq(Topics.STATUS_TOPIC),
- Mockito.any(Reset.class),
+ any(Reset.class),
statHandlerCaptor.capture()))
.thenReturn(statPoller);
QueueErrors queueErrors = mock(QueueErrors.class);
@@ -186,6 +187,12 @@ public class PubQueueProviderTest {
DistributionQueueItem item = head.getItem();
assertThat(item.getPackageId(), equalTo("packageid1"));
}
+
+ @Test
+ public void testMultipleCloseInvocations() {
+ queueProvider.close();
+ queueProvider.close();
+ }
@Test
public void testCleanUp() {