Convert mdsal-singleton-dom-impl to a JPMS module 81/93681/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 8 Nov 2020 11:24:04 +0000 (12:24 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 8 Nov 2020 16:35:22 +0000 (17:35 +0100)
This is a simple implementation, convert it to JPMS, providing
integration with various DI frameworks. We also minimize dependencies

JIRA: MDSAL-640
Change-Id: I00724709bd557dbbd814942fe0968390317073dd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
replicate/mdsal-replicate-netty/src/test/java/org/opendaylight/mdsal/replicate/netty/IntegrationTest.java
singleton-service/mdsal-singleton-dom-impl/pom.xml
singleton-service/mdsal-singleton-dom-impl/src/main/java/module-info.java [new file with mode: 0644]
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/DOMClusterSingletonServiceProviderImpl.java
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/di/DefaultClusterSingletonServiceProvider.java [new file with mode: 0644]
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/AbstractDOMClusterServiceProviderTest.java
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/ClusterSingletonServiceGroupImplTest.java
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/DOMClusterSingletonServiceProviderAsyncImplTest.java
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/DOMClusterSingletonServiceProviderImplTest.java

index 5f0a06b082f5751faadc781d75f20cc82beffd4f..874491e585b98b7ba6a55898eb2801adfec357e5 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.eos.dom.simple.SimpleDOMEntityOwnershipService;
-import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProviderImpl;
+import org.opendaylight.mdsal.singleton.dom.impl.di.DefaultClusterSingletonServiceProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.EntityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.EntityKey;
@@ -59,12 +59,12 @@ public class IntegrationTest extends AbstractDataBrokerTest {
     private static final QName ENTITY_NAME_QNAME = QName.create(ENTITY_QNAME, "name");
 
     private AbstractBootstrapSupport support;
-    private DOMClusterSingletonServiceProviderImpl css;
+    private DefaultClusterSingletonServiceProvider css;
 
     @Before
     public void before() {
         support = AbstractBootstrapSupport.create();
-        css = new DOMClusterSingletonServiceProviderImpl(new SimpleDOMEntityOwnershipService());
+        css = new DefaultClusterSingletonServiceProvider(new SimpleDOMEntityOwnershipService());
         css.initializeProvider();
     }
 
index 0510231d9eef8ed3bc07d986b8c938f366e15cc3..a992e72c398f4395a6fccd88cb352a94ce21a53a 100644 (file)
     <packaging>bundle</packaging>
 
     <dependencies>
-        <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>mdsal-common-api</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-eos-dom-api</artifactId>
             <artifactId>yang-data-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-model-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>osgi.cmpn</artifactId>
+            <groupId>org.kohsuke.metainf-services</groupId>
+            <artifactId>metainf-services</artifactId>
         </dependency>
         <dependency>
-            <groupId>javax.inject</groupId>
+            <groupId>com.guicedee.services</groupId>
             <artifactId>javax.inject</artifactId>
-            <scope>provided</scope>
             <optional>true</optional>
         </dependency>
-
         <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-data-impl</artifactId>
-            <scope>test</scope>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
         </dependency>
     </dependencies>
 
diff --git a/singleton-service/mdsal-singleton-dom-impl/src/main/java/module-info.java b/singleton-service/mdsal-singleton-dom-impl/src/main/java/module-info.java
new file mode 100644 (file)
index 0000000..664be7b
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProviderImpl;
+
+module org.opendaylight.mdsal.singleton.dom.impl {
+    exports org.opendaylight.mdsal.singleton.dom.impl.di;
+
+    provides ClusterSingletonServiceProvider with DOMClusterSingletonServiceProviderImpl;
+
+    requires transitive org.opendaylight.mdsal.singleton.common.api;
+    requires transitive org.opendaylight.mdsal.eos.dom.api;
+    requires org.opendaylight.mdsal.eos.common.api;
+    requires org.opendaylight.yangtools.concepts;
+    requires org.slf4j;
+
+    uses DOMEntityOwnershipService;
+
+    // Annotations
+    requires static transitive org.eclipse.jdt.annotation;
+    requires static javax.inject;
+    requires static metainf.services;
+    requires static org.checkerframework.checker.qual;
+    requires static org.osgi.service.component.annotations;
+}
index 88f720a8c9df21bdfe305daff444338f08f1234e..667db395580852fdf78bed392adc2d62918accea 100644 (file)
@@ -7,22 +7,22 @@
  */
 package org.opendaylight.mdsal.singleton.dom.impl;
 
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
+import java.util.ServiceLoader;
+import org.kohsuke.MetaInfServices;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 /**
  * Binding version of {@link AbstractClusterSingletonServiceProviderImpl}.
  */
-@Singleton
-public final class DOMClusterSingletonServiceProviderImpl extends
+@MetaInfServices(value = ClusterSingletonServiceProvider.class)
+public class DOMClusterSingletonServiceProviderImpl extends
         AbstractClusterSingletonServiceProviderImpl<YangInstanceIdentifier, DOMEntity,
                                                     DOMEntityOwnershipChange,
                                                     DOMEntityOwnershipListener,
@@ -30,13 +30,12 @@ public final class DOMClusterSingletonServiceProviderImpl extends
                                                     DOMEntityOwnershipListenerRegistration>
         implements DOMEntityOwnershipListener {
 
-    /**
-     * Initialization all needed class internal property for {@link DOMClusterSingletonServiceProviderImpl}.
-     *
-     * @param entityOwnershipService - we need only {@link GenericEntityOwnershipService}
-     */
-    @Inject
-    public DOMClusterSingletonServiceProviderImpl(final DOMEntityOwnershipService entityOwnershipService) {
+    public DOMClusterSingletonServiceProviderImpl() {
+        this(ServiceLoader.load(DOMEntityOwnershipService.class).findFirst().orElseThrow(
+            () -> new IllegalStateException("Could not find DOMEntityOwnershipService")));
+    }
+
+    protected DOMClusterSingletonServiceProviderImpl(final DOMEntityOwnershipService entityOwnershipService) {
         super(entityOwnershipService);
     }
 
diff --git a/singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/di/DefaultClusterSingletonServiceProvider.java b/singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/di/DefaultClusterSingletonServiceProvider.java
new file mode 100644 (file)
index 0000000..ca02793
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.singleton.dom.impl.di;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProviderImpl;
+
+@Singleton
+public final class DefaultClusterSingletonServiceProvider extends DOMClusterSingletonServiceProviderImpl {
+    @Inject
+    public DefaultClusterSingletonServiceProvider(final DOMEntityOwnershipService entityOwnershipService) {
+        super(entityOwnershipService);
+    }
+}
index a4808aad03a572c1c8640d895761dcedbfcacdc4..46a600b842779c25785e29da3b9b4b8446bc70dd 100644 (file)
@@ -25,7 +25,6 @@ import com.google.common.util.concurrent.ListenableFuture;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
@@ -85,29 +84,27 @@ public abstract class AbstractDOMClusterServiceProviderTest {
         }
     }
 
-    static final String SERVICE_NAME = "testServiceName";
-    static final DOMEntity ENTITY = new DOMEntity(SERVICE_ENTITY_TYPE, SERVICE_NAME);
-    static final DOMEntity DOUBLE_ENTITY = new DOMEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_NAME);
+    public static final String SERVICE_NAME = "testServiceName";
+    public static final DOMEntity ENTITY = new DOMEntity(SERVICE_ENTITY_TYPE, SERVICE_NAME);
+    public static final DOMEntity DOUBLE_ENTITY = new DOMEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_NAME);
 
     @Mock
-    protected DOMEntityOwnershipService mockEos;
+    public DOMEntityOwnershipService mockEos;
     @Mock
-    protected DOMEntityOwnershipCandidateRegistration mockEntityCandReg;
+    public DOMEntityOwnershipCandidateRegistration mockEntityCandReg;
     @Mock
-    protected DOMEntityOwnershipCandidateRegistration mockDoubleEntityCandReg;
+    public DOMEntityOwnershipCandidateRegistration mockDoubleEntityCandReg;
     @Mock
-    protected DOMEntityOwnershipListenerRegistration mockEosEntityListReg;
+    public DOMEntityOwnershipListenerRegistration mockEosEntityListReg;
     @Mock
-    protected DOMEntityOwnershipListenerRegistration mockEosDoubleEntityListReg;
+    public DOMEntityOwnershipListenerRegistration mockEosDoubleEntityListReg;
 
-    protected DOMClusterSingletonServiceProviderImpl clusterSingletonServiceProvider;
-    protected TestClusterSingletonService clusterSingletonService;
-    protected TestClusterSingletonService clusterSingletonService2;
+    public DOMClusterSingletonServiceProviderImpl clusterSingletonServiceProvider;
+    public TestClusterSingletonService clusterSingletonService;
+    public TestClusterSingletonService clusterSingletonService2;
 
     @Before
     public void setup() throws CandidateAlreadyRegisteredException {
-        MockitoAnnotations.initMocks(this);
-
         doNothing().when(mockEosEntityListReg).close();
         doNothing().when(mockEosDoubleEntityListReg).close();
         doNothing().when(mockEntityCandReg).close();
index e59453e15c50b17efa85e55961511fb2db4cdc43..ffe062051078c68c857b65af12acd7948a7be185 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.mdsal.singleton.dom.impl;
 
 import static org.junit.Assert.assertFalse;
@@ -24,8 +23,9 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipCandidateRegistration;
@@ -41,31 +41,32 @@ import org.opendaylight.mdsal.singleton.dom.impl.util.TestInstanceIdentifier;
 /**
  * Testing {@link ClusterSingletonServiceGroupImpl}.
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ClusterSingletonServiceGroupImplTest {
-    private static final String SERVICE_IDENTIFIER = "TestServiceIdent";
-    private static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = ServiceGroupIdentifier.create(SERVICE_IDENTIFIER);
+    public static final String SERVICE_IDENTIFIER = "TestServiceIdent";
+    public static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = ServiceGroupIdentifier.create(SERVICE_IDENTIFIER);
 
-    private static final TestEntity MAIN_ENTITY = new TestEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
-    private static final TestEntity CLOSE_ENTITY = new TestEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
+    public static final TestEntity MAIN_ENTITY = new TestEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
+    public static final TestEntity CLOSE_ENTITY = new TestEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
 
     @Mock
-    private ClusterSingletonService mockClusterSingletonService;
+    public ClusterSingletonService mockClusterSingletonService;
     @Mock
-    private ClusterSingletonService mockClusterSingletonServiceSecond;
+    public ClusterSingletonService mockClusterSingletonServiceSecond;
     @Mock
-    private GenericEntityOwnershipCandidateRegistration<?, ?> mockEntityCandReg;
+    public GenericEntityOwnershipCandidateRegistration<?, ?> mockEntityCandReg;
     @Mock
-    private GenericEntityOwnershipCandidateRegistration<?, ?> mockCloseEntityCandReg;
+    public GenericEntityOwnershipCandidateRegistration<?, ?> mockCloseEntityCandReg;
     @Mock
-    private GenericEntityOwnershipListener<TestInstanceIdentifier,
+    public GenericEntityOwnershipListener<TestInstanceIdentifier,
         GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>> mockEosListener;
 
     @Mock
-    private GenericEntityOwnershipService<TestInstanceIdentifier,TestEntity,
+    public GenericEntityOwnershipService<TestInstanceIdentifier,TestEntity,
         GenericEntityOwnershipListener<TestInstanceIdentifier,
             GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>> mockEosService;
 
-    private ClusterSingletonServiceGroupImpl<TestInstanceIdentifier,TestEntity,
+    public ClusterSingletonServiceGroupImpl<TestInstanceIdentifier,TestEntity,
         GenericEntityOwnershipChange<TestInstanceIdentifier,TestEntity>,
             GenericEntityOwnershipListener<TestInstanceIdentifier,
                 GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>,
@@ -73,8 +74,8 @@ public class ClusterSingletonServiceGroupImplTest {
                         GenericEntityOwnershipListener<TestInstanceIdentifier,
                             GenericEntityOwnershipChange<TestInstanceIdentifier, TestEntity>>>> singletonServiceGroup;
 
-    private ClusterSingletonServiceRegistration firstReg;
-    private ClusterSingletonServiceRegistration secondReg;
+    public ClusterSingletonServiceRegistration firstReg;
+    public ClusterSingletonServiceRegistration secondReg;
 
     /**
      * Initialization functionality for every Tests in this suite.
@@ -83,8 +84,6 @@ public class ClusterSingletonServiceGroupImplTest {
      */
     @Before
     public void setup() throws CandidateAlreadyRegisteredException {
-        MockitoAnnotations.initMocks(this);
-
         doReturn(mockEntityCandReg).when(mockEosService).registerCandidate(MAIN_ENTITY);
         doReturn(mockCloseEntityCandReg).when(mockEosService).registerCandidate(CLOSE_ENTITY);
         doNothing().when(mockEntityCandReg).close();
index 5e01ad3b0a57a56dbf1dafdf754ee467e308c354..1a24bb6c51fb4ca70b099deeb80633e50232c9df 100644 (file)
@@ -20,17 +20,20 @@ import java.util.TimerTask;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 
 /*
  * Testing {@link DOMClusterSingletonServiceProviderImpl} implementation
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public final class DOMClusterSingletonServiceProviderAsyncImplTest extends AbstractDOMClusterServiceProviderTest {
     /*
      * Test implementation of {@link ClusterSingletonService}
      */
-    static class TestClusterSingletonAsyncServiceInstance extends TestClusterSingletonService {
+    public static class TestClusterSingletonAsyncServiceInstance extends TestClusterSingletonService {
         @Override
         public ListenableFuture<Void> closeServiceInstance() {
             super.closeServiceInstance();
@@ -46,8 +49,8 @@ public final class DOMClusterSingletonServiceProviderAsyncImplTest extends Abstr
         }
     }
 
-    protected static final long ASYNC_TIME_DELAY_MILLIS = 100L;
-    protected static Timer TIMER;
+    public static final long ASYNC_TIME_DELAY_MILLIS = 100L;
+    public static Timer TIMER;
 
     @BeforeClass
     public static void asyncInitTest() {
index 72b6e90404cd546ce5f1d17b84ba3405d261557c..1710b41e2e8458eadf19daebd03eb6811bce6149 100644 (file)
@@ -17,6 +17,8 @@ import static org.mockito.Mockito.verify;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
@@ -24,6 +26,7 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegist
 /**
  * Synchronous test suite.
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class DOMClusterSingletonServiceProviderImplTest extends AbstractDOMClusterServiceProviderTest {
     /**
      * Initialization functionality for every Tests in this suite.