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:27:10 UTC
[sling-org-apache-sling-discovery-commons] 03/07: SLING-5592 :
cancel backgroundCheck thread in deactivate for rare cases where it is
still running
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.12
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-commons.git
commit 1e2a10d534679543ad5629381abd94c517c9cac9
Author: Stefan Egli <st...@apache.org>
AuthorDate: Tue Mar 8 10:15:57 2016 +0000
SLING-5592 : cancel backgroundCheck thread in deactivate for rare cases where it is still running
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/commons@1734045 13f79535-47bb-0310-9956-ffa450edef68
---
.../commons/providers/spi/base/IdMapService.java | 2 ++
.../providers/spi/base/TestOakSyncTokenService.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/IdMapService.java b/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/IdMapService.java
index 947e587..7828103 100644
--- a/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/IdMapService.java
+++ b/src/main/java/org/apache/sling/discovery/commons/providers/spi/base/IdMapService.java
@@ -120,6 +120,8 @@ public class IdMapService extends AbstractServiceWithBackgroundCheck implements
eventHandlerRegistration.unregister();
eventHandlerRegistration = null;
}
+ // SLING-5592: cancel the potentially running background thread
+ cancelPreviousBackgroundCheck();
}
private void registerEventHandler() {
diff --git a/src/test/java/org/apache/sling/discovery/commons/providers/spi/base/TestOakSyncTokenService.java b/src/test/java/org/apache/sling/discovery/commons/providers/spi/base/TestOakSyncTokenService.java
index e767571..c692b50 100644
--- a/src/test/java/org/apache/sling/discovery/commons/providers/spi/base/TestOakSyncTokenService.java
+++ b/src/test/java/org/apache/sling/discovery/commons/providers/spi/base/TestOakSyncTokenService.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Field;
import java.util.UUID;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -38,6 +39,7 @@ import org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWith
import org.apache.sling.jcr.api.SlingRepository;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -242,4 +244,22 @@ public class TestOakSyncTokenService {
assertEquals(3, l.countEvents());
}
+ @Test
+ public void testRapidIdMapServiceActivateDeactivate() throws Exception {
+ BackgroundCheckRunnable bgCheckRunnable = getBackgroundCheckRunnable(idMapService1);
+ assertNotNull(bgCheckRunnable);
+ assertFalse(bgCheckRunnable.isDone());
+ idMapService1.deactivate();
+ assertFalse(idMapService1.waitForInit(2500));
+ bgCheckRunnable = getBackgroundCheckRunnable(idMapService1);
+ assertNotNull(bgCheckRunnable);
+ assertTrue(bgCheckRunnable.isDone());
+ }
+
+ private BackgroundCheckRunnable getBackgroundCheckRunnable(IdMapService idMapService) throws NoSuchFieldException, IllegalAccessException {
+ Field field = idMapService.getClass().getSuperclass().getDeclaredField("backgroundCheckRunnable");
+ field.setAccessible(true);
+ Object backgroundCheckRunnable = field.get(idMapService);
+ return (BackgroundCheckRunnable) backgroundCheckRunnable;
+ }
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.