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/12/07 11:21:07 UTC

[sling-org-apache-sling-testing-osgi-mock] branch experimental/WTES-69-diagnosis updated (0a0f16b -> 142b2c7)

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

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


    from 0a0f16b  add service class
     new ffcb027  reuse comparator instance for comparing service references
     new 142b2c7  ensure generated service IDs are unique accross threads

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../sling/testing/mock/osgi/MockBundleContext.java       | 16 +++++++++-------
 .../sling/testing/mock/osgi/MockServiceRegistration.java |  5 ++++-
 2 files changed, 13 insertions(+), 8 deletions(-)

[sling-org-apache-sling-testing-osgi-mock] 02/02: ensure generated service IDs are unique accross threads

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 142b2c7bf0bab8c42d3e1a6218dd5cdf338b5a85
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:20:35 2021 +0100

    ensure generated service IDs are unique accross threads
---
 .../org/apache/sling/testing/mock/osgi/MockServiceRegistration.java  | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
index 2294611..96ecc7d 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockServiceRegistration.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.felix.framework.FilterImpl;
@@ -51,10 +52,12 @@ class MockServiceRegistration<T> implements ServiceRegistration<T>, Comparable<M
     private final ServiceReference<T> serviceReference;
     private final MockBundleContext bundleContext;
 
+    private static final AtomicLong SERVICE_ID_COUNTER = new AtomicLong();
+
     @SuppressWarnings("unchecked")
     public MockServiceRegistration(final Bundle bundle, final String[] clazzes, final T service,
             final Dictionary<String, Object> properties, MockBundleContext bundleContext) {
-        this.serviceId = ++serviceCounter;
+        this.serviceId = SERVICE_ID_COUNTER.incrementAndGet();
         this.clazzes = new HashSet<String>(Arrays.asList(clazzes));
 
         if (service instanceof ServiceFactory) {

[sling-org-apache-sling-testing-osgi-mock] 01/02: reuse comparator instance for comparing service references

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ffcb027cb7431a3b74f083a1ea0ece7a7688c71f
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:16:50 2021 +0100

    reuse comparator instance for comparing service references
---
 .../sling/testing/mock/osgi/MockBundleContext.java       | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index 4f4620e..df35c6a 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -82,6 +82,14 @@ class MockBundleContext implements BundleContext {
 
     private static final Logger log = LoggerFactory.getLogger(MockBundleContext.class);
 
+    private static final Comparator<ServiceReference> SR_COMPARATOR_HIGHEST_RANKING_FIRST = new Comparator<ServiceReference>() {
+        @Override
+        public int compare(ServiceReference o1, ServiceReference o2) {
+            // reverse sort order to get highest ranking first
+            return o2.compareTo(o1);
+        }
+    };
+
     public MockBundleContext() {
         log.debug("Creating MockBundleContext, bundleContext={}", this);
 
@@ -321,13 +329,7 @@ class MockBundleContext implements BundleContext {
          * https://docs.osgi.org/specification/osgi.core/7.0.0/framework.api.html#org.osgi.framework.BundleContext.getServiceReferences-String-String-
          * for backward compatibility with previous implementation of osgi-mock we stick with highest-ranking first here
          */
-        Set<ServiceReference> result = new TreeSet<>(new Comparator<ServiceReference>() {
-            @Override
-            public int compare(ServiceReference o1, ServiceReference o2) {
-                // reverse sort order to get highest ranking first
-                return o2.compareTo(o1);
-            }
-        });
+        Set<ServiceReference> result = new TreeSet<>(SR_COMPARATOR_HIGHEST_RANKING_FIRST);
         for (MockServiceRegistration serviceRegistration : this.registeredServices) {
             if (serviceRegistration.matches(clazz, filter)) {
                 result.add(serviceRegistration.getReference());