sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-testing-sling-mock-oak] 03/07: SLING-5547 Update sling-mock-oak to Sling API 2.11 and Oak 1.3.15
Date Tue, 07 Nov 2017 10:24:09 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-oak-2.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock-oak.git

commit 7985024037618c3630a49748451663f743931619
Author: Stefan Seifert <sseifert@apache.org>
AuthorDate: Tue Feb 23 02:06:41 2016 +0000

    SLING-5547 Update sling-mock-oak to Sling API 2.11 and Oak 1.3.15
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock-oak@1731778
13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/oak/OakMockSlingRepository.java     | 25 +++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java
b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java
index cd6133a..45f7094 100644
--- a/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java
+++ b/src/main/java/org/apache/sling/testing/mock/sling/oak/OakMockSlingRepository.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.testing.mock.sling.oak;
 
+import java.lang.reflect.Field;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -42,6 +43,8 @@ import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Component
 @Service(SlingRepository.class)
@@ -54,6 +57,8 @@ public final class OakMockSlingRepository implements SlingRepository {
     private ExecutorService executor;
     private ScheduledExecutorService scheduledExecutor;
     
+    private static final Logger log = LoggerFactory.getLogger(OakMockSlingRepository.class);
+    
     @Activate
     protected void activate(BundleContext bundleContext) {
         executor = Executors.newSingleThreadExecutor();
@@ -77,12 +82,26 @@ public final class OakMockSlingRepository implements SlingRepository {
 
     @Deactivate
     protected void deactivate(ComponentContext componentContext) {
-        // shutdown OAK JCR repository
-        ((JackrabbitRepository)repository).shutdown();
-        
         // shutdown executors
+        // force immediate shutdown for all executors without waiting for tasks for completion
- we're only in unit tests! 
         executor.shutdownNow();
         scheduledExecutor.shutdownNow();
+        shutdownExecutorService(repository, "scheduledExecutor");
+
+        // shutdown OAK JCR repository
+        ((JackrabbitRepository)repository).shutdown();
+    }
+
+    private void shutdownExecutorService(Object instance, String fieldName) {
+        try {
+            Field executorField = instance.getClass().getDeclaredField(fieldName); 
+            executorField.setAccessible(true);
+            ExecutorService executor = (ExecutorService)executorField.get(instance);
+            executor.shutdownNow();
+        }
+        catch (Throwable ex) {
+            log.error("Potential Memory leak: Unable to shutdown executor service from field
'" + fieldName + "' in " + instance, ex);
+        }
     }
     
     public String getDescriptor(String key) {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message