You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/11/26 18:33:56 UTC

[sling-org-apache-sling-testing-sling-mock] 02/02: WTES-69 add logging

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch experimental/WTES-69-debug-logging
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit b3bae3b63ff8f88bfdd5c8649e92818ba9f8baaa
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Fri Nov 26 19:33:23 2021 +0100

    WTES-69 add logging
---
 .../mock/sling/ThreadsafeMockAdapterManagerWrapper.java       | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java b/core/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
index 0342108..ee5fc54 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapper.java
@@ -26,6 +26,8 @@ import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Wrapper for {@link MockAdapterManager} which makes sure multiple unit tests
@@ -34,6 +36,8 @@ import org.osgi.framework.ServiceReference;
  */
 class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
 
+    private static final Logger log = LoggerFactory.getLogger(ThreadsafeMockAdapterManagerWrapper.class);
+
     private static final ThreadLocal<AdapterManagerBundleContextFactory> THREAD_LOCAL = new ThreadLocal<AdapterManagerBundleContextFactory>() {
         @Override
         protected AdapterManagerBundleContextFactory initialValue() {
@@ -71,6 +75,7 @@ class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
         private BundleContext bundleContext;
 
         public void setBundleContext(@NotNull final BundleContext bundleContext) {
+            log.info("Set bundle context for AdapterManager, bundleContext=" + bundleContext);
             this.bundleContext = bundleContext;
 
             // register adapter manager
@@ -88,11 +93,13 @@ class ThreadsafeMockAdapterManagerWrapper implements AdapterManager {
         @SuppressWarnings("null")
         public synchronized AdapterManager getAdapterManager() {
             if (bundleContext == null) {
-                setBundleContext(MockOsgi.newBundleContext());
+                BundleContext newBundleContext = MockOsgi.newBundleContext();
+                log.warn("Create new bundle context for adapter manager because it was null, bundleContext=" + bundleContext);
+                setBundleContext(newBundleContext);
             }
             ServiceReference<AdapterManager> serviceReference = bundleContext.getServiceReference(AdapterManager.class);
             if (serviceReference != null) {
-                return (AdapterManager)bundleContext.getService(serviceReference);
+                return bundleContext.getService(serviceReference);
             }
             else {
                 throw new RuntimeException("AdapterManager not registered in bundle context.");