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:23:08 UTC

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

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.


 discard 142b2c7  ensure generated service IDs are unique accross threads
     new 019f9b4  ensure generated service and bundle IDs are unique accross threads

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (142b2c7)
            \
             N -- N -- N   refs/heads/experimental/WTES-69-diagnosis (019f9b4)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 .../src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java | 5 +++--
 .../org/apache/sling/testing/mock/osgi/MockServiceRegistration.java  | 4 +---
 2 files changed, 4 insertions(+), 5 deletions(-)

[sling-org-apache-sling-testing-osgi-mock] 01/01: ensure generated service and bundle 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 019f9b4962281710ea24fddb47d1485bf8e7563e
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:20:35 2021 +0100

    ensure generated service and bundle IDs are unique accross threads
---
 .../src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java | 5 +++--
 .../org/apache/sling/testing/mock/osgi/MockServiceRegistration.java  | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
index 5e36191..f53abd4 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
@@ -29,6 +29,7 @@ import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -41,7 +42,7 @@ import org.osgi.framework.Version;
  */
 public final class MockBundle implements Bundle {
 
-    private static volatile long bundleCounter;
+    private static final AtomicLong BUNDLE_ID_COUNTER = new AtomicLong();
 
     private final long bundleId;
     private final BundleContext bundleContext;
@@ -65,7 +66,7 @@ public final class MockBundle implements Bundle {
      * @param bundleContext Bundle context
      */
     public MockBundle(BundleContext bundleContext) {
-        this(bundleContext, ++bundleCounter);
+        this(bundleContext, BUNDLE_ID_COUNTER.incrementAndGet());
     }
 
     @Override
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..ad4a824 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;
@@ -42,7 +43,7 @@ import org.osgi.framework.ServiceRegistration;
  */
 class MockServiceRegistration<T> implements ServiceRegistration<T>, Comparable<MockServiceRegistration<T>> {
 
-    private static volatile long serviceCounter;
+    private static final AtomicLong SERVICE_ID_COUNTER = new AtomicLong();
 
     private final Long serviceId;
     private final Set<String> clazzes;
@@ -54,7 +55,7 @@ class MockServiceRegistration<T> implements ServiceRegistration<T>, Comparable<M
     @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) {