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

[sling-org-apache-sling-testing-osgi-mock] 01/01: SLING-10930 add failing test with multiple deactivate() calls on the same component

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

kwin pushed a commit to branch bugfix/SLING-10930-failing-test
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit b1c3b73ee47973a61920dcdf9050df4e2d55dd97
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Nov 22 19:18:32 2021 +0100

    SLING-10930 add failing test with multiple deactivate() calls on the
    same component
---
 .../mock/osgi/context/OsgiContextImplTest.java     |  6 +++
 .../activatedeactivate/Service8.java               | 46 ++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
index b8ad838..008a54f 100644
--- a/core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImplTest.java
@@ -37,6 +37,7 @@ import org.apache.sling.testing.mock.osgi.testsvc.osgicontextimpl.MyService;
 import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.Service3;
 import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.ServiceInterface1;
 import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.ServiceInterface2;
+import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.activatedeactivate.Service8;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -195,6 +196,11 @@ public class OsgiContextImplTest {
         assertNotNull(service.getConfig().get("component.id"));
     }
 
+    @Test
+    public void testRegisterInjectActivateWithAdditionalManualServiceRegistration() {
+        context.registerInjectActivateService(new Service8());
+    }
+
     @Test(expected=RuntimeException.class)
     public void testRegisterInjectActivate_RefrenceMissing_Instance() {
         context.registerInjectActivateService(new Service3());
diff --git a/test-services/src/main/java/org/apache/sling/testing/mock/osgi/testsvc/osgiserviceutil/activatedeactivate/Service8.java b/test-services/src/main/java/org/apache/sling/testing/mock/osgi/testsvc/osgiserviceutil/activatedeactivate/Service8.java
new file mode 100644
index 0000000..75a99d0
--- /dev/null
+++ b/test-services/src/main/java/org/apache/sling/testing/mock/osgi/testsvc/osgiserviceutil/activatedeactivate/Service8.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.activatedeactivate;
+
+import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.ServiceInterface1;
+import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.ServiceInterface2;
+import org.apache.sling.testing.mock.osgi.testsvc.osgiserviceutil.ServiceInterface3;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+
+@Component(service = { ServiceInterface1.class, ServiceInterface2.class })
+public class Service8 implements ServiceInterface1, ServiceInterface2, ServiceInterface3 {
+
+    private ServiceRegistration<ServiceInterface3> serviceRegistration;
+
+    @Activate
+    private void activate(BundleContext bundleContext) {
+        serviceRegistration = bundleContext.registerService(ServiceInterface3.class, this, null);
+    }
+
+    @Deactivate
+    private void deactivate(BundleContext bundleContext) {
+        serviceRegistration.unregister();
+        //serviceRegistration = null; // this may cause a NPE with subsequent deactivate() calls
+    }
+
+}