Remove generics from mdsal-singleton-dom-impl 44/109244/4
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 02:19:57 +0000 (03:19 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Dec 2023 06:28:26 +0000 (07:28 +0100)
Cluster Singleton Service is using horrible amounts of generics just
because of its legacy origin, where there was another implementation
working on EntityOwnershipService.

We have had only a single, DOMEntityOwnershipService-based,
implementation for a long time and it works well.

Remove generics by pushing down DOM-based types.

JIRA: MDSAL-843
Change-Id: I975ab1dbb6cc820039fe72277080b7b2d6247fcb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/AbstractClusterSingletonServiceProviderImpl.java
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/ClusterSingletonServiceGroup.java
singleton-service/mdsal-singleton-dom-impl/src/main/java/org/opendaylight/mdsal/singleton/dom/impl/ClusterSingletonServiceGroupImpl.java
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/PlaceholderGroup.java
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/DOMClusterSingletonServiceProviderImplTest.java
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestEntity.java [deleted file]
singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestInstanceIdentifier.java [deleted file]

index d9272e41c3a4a5cab8bdeb918b317f4f6f6737f1..304e5a09d0ab690a78ffe00b2710560c826b9a70 100644 (file)
@@ -20,37 +20,28 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange;
-import org.opendaylight.mdsal.eos.common.api.GenericEntity;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipListener;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Abstract class {@link AbstractClusterSingletonServiceProviderImpl} represents implementations of
- * {@link ClusterSingletonServiceProvider} and it implements {@link GenericEntityOwnershipListener}
- * for providing OwnershipChange for all registered {@link ClusterSingletonServiceGroup} entity
- * candidate.
- *
- * @param <P> the instance identifier path type
- * @param <E> the GenericEntity type
- * @param <G> the GenericEntityOwnershipListener type
- * @param <S> the GenericEntityOwnershipService type
+ * {@link ClusterSingletonServiceProvider} and it implements {@link DOMEntityOwnershipListener} for providing
+ * OwnershipChange for all registered {@link ClusterSingletonServiceGroup} entity candidate.
  */
-public abstract class AbstractClusterSingletonServiceProviderImpl<P extends HierarchicalIdentifier<P>,
-        E extends GenericEntity<P>, G extends GenericEntityOwnershipListener<E>,
-        S extends GenericEntityOwnershipService<E, G>>
-        implements ClusterSingletonServiceProvider, GenericEntityOwnershipListener<E> {
+public abstract class AbstractClusterSingletonServiceProviderImpl
+        implements ClusterSingletonServiceProvider, DOMEntityOwnershipListener {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractClusterSingletonServiceProviderImpl.class);
 
     @VisibleForTesting
@@ -58,8 +49,8 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
     @VisibleForTesting
     static final @NonNull String CLOSE_SERVICE_ENTITY_TYPE = "org.opendaylight.mdsal.AsyncServiceCloseEntityType";
 
-    private final S entityOwnershipService;
-    private final Map<String, ClusterSingletonServiceGroup<P, E>> serviceGroupMap = new ConcurrentHashMap<>();
+    private final ConcurrentMap<String, ClusterSingletonServiceGroup> serviceGroupMap = new ConcurrentHashMap<>();
+    private final DOMEntityOwnershipService entityOwnershipService;
 
     /* EOS Entity Listeners Registration */
     private Registration serviceEntityListenerReg;
@@ -70,7 +61,8 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
      *
      * @param entityOwnershipService relevant EOS
      */
-    protected AbstractClusterSingletonServiceProviderImpl(final @NonNull S entityOwnershipService) {
+    protected AbstractClusterSingletonServiceProviderImpl(
+            final @NonNull DOMEntityOwnershipService entityOwnershipService) {
         this.entityOwnershipService = requireNonNull(entityOwnershipService);
     }
 
@@ -92,7 +84,7 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
         checkArgument(!Strings.isNullOrEmpty(serviceIdentifier),
             "ClusterSingletonService identifier may not be null nor empty");
 
-        final ClusterSingletonServiceGroup<P, E> serviceGroup;
+        final ClusterSingletonServiceGroup serviceGroup;
         final var existing = serviceGroupMap.get(serviceIdentifier);
         if (existing == null) {
             serviceGroup = createGroup(serviceIdentifier, new ArrayList<>(1));
@@ -120,14 +112,14 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
         return reg;
     }
 
-    private ClusterSingletonServiceGroup<P, E> createGroup(final String serviceIdentifier,
+    private ClusterSingletonServiceGroup createGroup(final String serviceIdentifier,
             final List<ClusterSingletonServiceRegistration> services) {
-        return new ClusterSingletonServiceGroupImpl<>(serviceIdentifier, entityOwnershipService,
+        return new ClusterSingletonServiceGroupImpl(serviceIdentifier, entityOwnershipService,
             createEntity(SERVICE_ENTITY_TYPE, serviceIdentifier),
             createEntity(CLOSE_SERVICE_ENTITY_TYPE, serviceIdentifier), services);
     }
 
-    private void initializeOrRemoveGroup(final ClusterSingletonServiceGroup<P, E> group)
+    private void initializeOrRemoveGroup(final ClusterSingletonServiceGroup group)
             throws CandidateAlreadyRegisteredException {
         try {
             group.initialize();
@@ -138,7 +130,7 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
     }
 
     void removeRegistration(final String serviceIdentifier, final ClusterSingletonServiceRegistration reg) {
-        final PlaceholderGroup<P, E> placeHolder;
+        final PlaceholderGroup placeHolder;
         final ListenableFuture<?> future;
         synchronized (this) {
             final var lookup = verifyNotNull(serviceGroupMap.get(serviceIdentifier));
@@ -149,7 +141,7 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
 
             // Close the group and replace it with a placeholder
             LOG.debug("Closing service group {}", serviceIdentifier);
-            placeHolder = new PlaceholderGroup<>(lookup, future);
+            placeHolder = new PlaceholderGroup(lookup, future);
 
             final String identifier = reg.getInstance().getIdentifier().getName();
             verify(serviceGroupMap.replace(identifier, lookup, placeHolder));
@@ -161,8 +153,8 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
         future.addListener(() -> finishShutdown(placeHolder), MoreExecutors.directExecutor());
     }
 
-    synchronized void finishShutdown(final PlaceholderGroup<P, E> placeHolder) {
-        final String identifier = placeHolder.getIdentifier();
+    synchronized void finishShutdown(final PlaceholderGroup placeHolder) {
+        final var identifier = placeHolder.getIdentifier();
         LOG.debug("Service group {} closed", identifier);
 
         final var services = placeHolder.getServices();
@@ -218,7 +210,7 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
     }
 
     @Override
-    public final void ownershipChanged(final E entity, final EntityOwnershipStateChange change,
+    public final void ownershipChanged(final DOMEntity entity, final EntityOwnershipStateChange change,
             final boolean inJeopardy) {
         LOG.debug("Ownership change for ClusterSingletonService Provider on {} {} inJeopardy={}", entity, change,
             inJeopardy);
@@ -235,19 +227,22 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
      * Method implementation registers the listener.
      *
      * @param entityType the type of the entity
-     * @param entityOwnershipServiceInst - EOS type
+     * @param eos - EOS type
      * @return a {@link Registration}
      */
-    protected abstract Registration registerListener(String entityType, S entityOwnershipServiceInst);
+    protected abstract Registration registerListener(String entityType, DOMEntityOwnershipService eos);
 
     /**
-     * Creates an extended {@link GenericEntity} instance.
+     * Creates an extended {@link DOMEntity} instance.
      *
      * @param entityType the type of the entity
      * @param entityIdentifier the identifier of the entity
      * @return instance of Entity extended GenericEntity type
      */
-    protected abstract E createEntity(String entityType, String entityIdentifier);
+    @VisibleForTesting
+    static final DOMEntity createEntity(final String entityType, final String entityIdentifier) {
+        return new DOMEntity(entityType, entityIdentifier);
+    }
 
     /**
      * Method is responsible for parsing ServiceGroupIdentifier from E entity.
@@ -255,7 +250,7 @@ public abstract class AbstractClusterSingletonServiceProviderImpl<P extends Hier
      * @param entity instance of GenericEntity type
      * @return ServiceGroupIdentifier parsed from entity key value.
      */
-    protected abstract String getServiceIdentifierFromEntity(E entity);
+    protected abstract String getServiceIdentifierFromEntity(DOMEntity entity);
 
     /**
      * Method is called async. from close method in end of Provider lifecycle.
index e8769e5f38d2f49282abd07f7be1240b1d3da02c..f52e76f80ab86be535e51f43e6e7b399df1581fb 100644 (file)
@@ -11,10 +11,9 @@ import com.google.common.util.concurrent.ListenableFuture;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange;
-import org.opendaylight.mdsal.eos.common.api.GenericEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.concepts.Identifiable;
 
 /**
@@ -29,8 +28,8 @@ import org.opendaylight.yangtools.concepts.Identifiable;
  * @param <P> the instance identifier path type
  * @param <E> the GenericEntity type
  */
-abstract class ClusterSingletonServiceGroup<P extends HierarchicalIdentifier<P>, E extends GenericEntity<P>>
-        implements Identifiable<String> {
+// FIXME: rename to ServiceGroup and seal
+abstract class ClusterSingletonServiceGroup implements Identifiable<String> {
     /**
      * This method must be called once on startup to initialize this group and
      * register the relevant group entity candidate. It means create relevant
@@ -67,7 +66,7 @@ abstract class ClusterSingletonServiceGroup<P extends HierarchicalIdentifier<P>,
      * @param change the change the entity underwent
      * @param inJeopardy {@code true} if ownership is in jeopardy and the reported change may be inaccurate
      */
-    abstract void ownershipChanged(E entity, EntityOwnershipStateChange change, boolean inJeopardy);
+    abstract void ownershipChanged(DOMEntity entity, EntityOwnershipStateChange change, boolean inJeopardy);
 
     /**
      * Closes this service group. All registered service providers are also closed. Please be careful
index 2506051177640b24f29290b2754f8c30484a31e6..5fda4d9c2c19cc139443958468da17f5a76ce4ee 100644 (file)
@@ -36,12 +36,10 @@ import org.checkerframework.checker.lock.qual.Holding;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange;
-import org.opendaylight.mdsal.eos.common.api.GenericEntity;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipListener;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,9 +66,8 @@ import org.slf4j.LoggerFactory;
  * @param <G> the GenericEntityOwnershipListener type
  * @param <S> the GenericEntityOwnershipService type
  */
-final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>, E extends GenericEntity<P>,
-        G extends GenericEntityOwnershipListener<E>, S extends GenericEntityOwnershipService<E, G>>
-        extends ClusterSingletonServiceGroup<P, E> {
+// FIXME: rename to ActiveServiceGroup
+final class ClusterSingletonServiceGroupImpl extends ClusterSingletonServiceGroup {
 
     private enum EntityState {
         /**
@@ -111,25 +108,23 @@ final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>
 
     private static final Logger LOG = LoggerFactory.getLogger(ClusterSingletonServiceGroupImpl.class);
 
-    private final S entityOwnershipService;
+    private final DOMEntityOwnershipService entityOwnershipService;
     private final String identifier;
 
     /* Entity instances */
-    private final @NonNull E serviceEntity;
-    private final @NonNull E cleanupEntity;
+    private final @NonNull DOMEntity serviceEntity;
+    private final @NonNull DOMEntity cleanupEntity;
 
     private final Set<ClusterSingletonServiceRegistration> members = ConcurrentHashMap.newKeySet();
     // Guarded by lock
     private final Map<ClusterSingletonServiceRegistration, ServiceInfo> services = new HashMap<>();
 
     // Marker for when any state changed
-    @SuppressWarnings("rawtypes")
     private static final AtomicIntegerFieldUpdater<ClusterSingletonServiceGroupImpl> DIRTY_UPDATER =
             AtomicIntegerFieldUpdater.newUpdater(ClusterSingletonServiceGroupImpl.class, "dirty");
     private volatile int dirty;
 
     // Simplified lock: non-reentrant, support tryLock() only
-    @SuppressWarnings("rawtypes")
     private static final AtomicIntegerFieldUpdater<ClusterSingletonServiceGroupImpl> LOCK_UPDATER =
             AtomicIntegerFieldUpdater.newUpdater(ClusterSingletonServiceGroupImpl.class, "lock");
     @SuppressWarnings("unused")
@@ -188,28 +183,29 @@ final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>
      * Class constructor. Note: last argument is reused as-is.
      *
      * @param identifier non-empty string as identifier
-     * @param mainEntity as Entity instance
-     * @param closeEntity as Entity instance
+     * @param serviceEntity as Entity instance
+     * @param cleanupEntity as Entity instance
      * @param entityOwnershipService GenericEntityOwnershipService instance
      * @param parent parent service
      * @param services Services list
      */
-    ClusterSingletonServiceGroupImpl(final String identifier, final S entityOwnershipService, final E mainEntity,
-            final E closeEntity, final Collection<ClusterSingletonServiceRegistration> services) {
+    ClusterSingletonServiceGroupImpl(final String identifier, final DOMEntityOwnershipService entityOwnershipService,
+            final DOMEntity serviceEntity, final DOMEntity cleanupEntity,
+            final Collection<ClusterSingletonServiceRegistration> services) {
         checkArgument(!identifier.isEmpty(), "Identifier may not be empty");
         this.identifier = identifier;
         this.entityOwnershipService = requireNonNull(entityOwnershipService);
-        serviceEntity = requireNonNull(mainEntity);
-        cleanupEntity = requireNonNull(closeEntity);
+        this.serviceEntity = requireNonNull(serviceEntity);
+        this.cleanupEntity = requireNonNull(cleanupEntity);
         members.addAll(services);
 
         LOG.debug("Instantiated new service group for {}", identifier);
     }
 
     @VisibleForTesting
-    ClusterSingletonServiceGroupImpl(final String identifier, final E mainEntity,
-            final E closeEntity, final S entityOwnershipService) {
-        this(identifier, entityOwnershipService, mainEntity, closeEntity, ImmutableList.of());
+    ClusterSingletonServiceGroupImpl(final String identifier, final DOMEntity serviceEntity,
+            final DOMEntity cleanupEntity, final DOMEntityOwnershipService entityOwnershipService) {
+        this(identifier, entityOwnershipService, serviceEntity, cleanupEntity, ImmutableList.of());
     }
 
     @Override
@@ -323,7 +319,7 @@ final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>
     }
 
     @Override
-    void ownershipChanged(final E entity, final EntityOwnershipStateChange change, final boolean inJeopardy) {
+    void ownershipChanged(final DOMEntity entity, final EntityOwnershipStateChange change, final boolean inJeopardy) {
         synchronized (this) {
             lockedOwnershipChanged(entity, change, inJeopardy);
         }
@@ -345,7 +341,7 @@ final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>
      * @param ownershipChange reported change
      */
     @Holding("this")
-    private void lockedOwnershipChanged(final E entity, final EntityOwnershipStateChange change,
+    private void lockedOwnershipChanged(final DOMEntity entity, final EntityOwnershipStateChange change,
             final boolean inJeopardy) {
         if (serviceEntity.equals(entity)) {
             serviceOwnershipChanged(change, inJeopardy);
index f45ca8c2fade26b43962b3d519960781cc28d770..cd266d63ce68716f0efad5a3cb5398626fd5808b 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.mdsal.singleton.dom.impl;
 import java.util.ServiceLoader;
 import org.kohsuke.MetaInfServices;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
-import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yangtools.concepts.Registration;
@@ -21,12 +20,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
  * Binding version of {@link AbstractClusterSingletonServiceProviderImpl}.
  */
 @MetaInfServices(value = ClusterSingletonServiceProvider.class)
-public class DOMClusterSingletonServiceProviderImpl extends
-        AbstractClusterSingletonServiceProviderImpl<YangInstanceIdentifier, DOMEntity,
-                                                    DOMEntityOwnershipListener,
-                                                    DOMEntityOwnershipService>
-        implements DOMEntityOwnershipListener {
-
+public class DOMClusterSingletonServiceProviderImpl extends AbstractClusterSingletonServiceProviderImpl {
     public DOMClusterSingletonServiceProviderImpl() {
         this(ServiceLoader.load(DOMEntityOwnershipService.class).findFirst().orElseThrow(
             () -> new IllegalStateException("Could not find DOMEntityOwnershipService")));
@@ -36,11 +30,6 @@ public class DOMClusterSingletonServiceProviderImpl extends
         super(entityOwnershipService);
     }
 
-    @Override
-    protected DOMEntity createEntity(final String type, final String ident) {
-        return new DOMEntity(type, ident);
-    }
-
     @Override
     protected Registration registerListener(final String type, final DOMEntityOwnershipService eos) {
         return eos.registerListener(type, this);
index d95e6ec19c5c8737f5c4c7e58addafd95d300dc5..62405014d2a9d7a7e2ac53c619baeeed19dfce87 100644 (file)
@@ -17,9 +17,8 @@ import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipStateChange;
-import org.opendaylight.mdsal.eos.common.api.GenericEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,17 +26,17 @@ import org.slf4j.LoggerFactory;
  * Intermediate place-holder to catch user requests while asynchronous shutdown of previous incarnation of
  * a {@link ClusterSingletonServiceGroup} finishes.
  */
-final class PlaceholderGroup<P extends HierarchicalIdentifier<P>, E extends GenericEntity<P>>
-        extends ClusterSingletonServiceGroup<P, E> {
+// FIXME: rename to PlaceholderServiceGroup
+final class PlaceholderGroup extends ClusterSingletonServiceGroup {
     private static final Logger LOG = LoggerFactory.getLogger(PlaceholderGroup.class);
 
     private final List<ClusterSingletonServiceRegistration> services = new ArrayList<>(0);
-    private final ClusterSingletonServiceGroup<P, E> previous;
+    private final ClusterSingletonServiceGroup previous;
     private final ListenableFuture<?> closeFuture;
 
-    private volatile ClusterSingletonServiceGroup<P, E> successor;
+    private volatile ClusterSingletonServiceGroup successor;
 
-    PlaceholderGroup(final ClusterSingletonServiceGroup<P, E> previous, final ListenableFuture<?> closeFuture) {
+    PlaceholderGroup(final ClusterSingletonServiceGroup previous, final ListenableFuture<?> closeFuture) {
         this.previous = requireNonNull(previous);
         this.closeFuture = requireNonNull(closeFuture);
     }
@@ -68,7 +67,7 @@ final class PlaceholderGroup<P extends HierarchicalIdentifier<P>, E extends Gene
     }
 
     @Override
-    void ownershipChanged(final E entity, final EntityOwnershipStateChange change, final boolean inJeopardy) {
+    void ownershipChanged(final DOMEntity entity, final EntityOwnershipStateChange change, final boolean inJeopardy) {
         // This really should not happen, but let's be defensive
         final var local = successor;
         (local == null ? previous : local).ownershipChanged(entity, change, inJeopardy);
@@ -87,7 +86,7 @@ final class PlaceholderGroup<P extends HierarchicalIdentifier<P>, E extends Gene
         return services;
     }
 
-    void setSuccessor(final ClusterSingletonServiceGroup<P, E> successor) {
+    void setSuccessor(final ClusterSingletonServiceGroup successor) {
         verifyNoSuccessor();
         this.successor = verifyNotNull(successor);
         LOG.debug("{}: successor set to {}", this, successor);
index 4e104f144abc018fbd4344579ee21eb0bcb95341..230e684f149e56fac8290e6ca024107a48651bc6 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.mdsal.singleton.dom.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
@@ -107,7 +106,7 @@ public abstract class AbstractDOMClusterServiceProviderTest {
     public TestClusterSingletonService clusterSingletonService2;
 
     @Before
-    public void setup() throws CandidateAlreadyRegisteredException {
+    public void setup() throws Exception {
         doNothing().when(mockEosEntityListReg).close();
         doNothing().when(mockEosDoubleEntityListReg).close();
         doNothing().when(mockEntityCandReg).close();
@@ -161,9 +160,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
      */
     @Test
     public void makeEntityClusterSingletonServiceProviderTest() {
-        final DOMEntity testEntity = clusterSingletonServiceProvider.createEntity(SERVICE_ENTITY_TYPE, SERVICE_NAME);
+        final var testEntity = AbstractClusterSingletonServiceProviderImpl.createEntity(SERVICE_ENTITY_TYPE,
+            SERVICE_NAME);
         assertEquals(ENTITY, testEntity);
-        final DOMEntity testDbEn = clusterSingletonServiceProvider.createEntity(CLOSE_SERVICE_ENTITY_TYPE,
+        final var testDbEn = AbstractClusterSingletonServiceProviderImpl.createEntity(CLOSE_SERVICE_ENTITY_TYPE,
                 SERVICE_NAME);
         assertEquals(DOUBLE_ENTITY, testDbEn);
     }
@@ -173,21 +173,16 @@ public abstract class AbstractDOMClusterServiceProviderTest {
      */
     @Test
     public void getIdentifierClusterSingletonServiceProviderTest() {
-        final String entityIdentifier = clusterSingletonServiceProvider.getServiceIdentifierFromEntity(ENTITY);
-        assertEquals(SERVICE_NAME, entityIdentifier);
-        final String doubleEntityId = clusterSingletonServiceProvider.getServiceIdentifierFromEntity(DOUBLE_ENTITY);
-        assertEquals(SERVICE_NAME, doubleEntityId);
+        assertEquals(SERVICE_NAME, clusterSingletonServiceProvider.getServiceIdentifierFromEntity(ENTITY));
+        assertEquals(SERVICE_NAME, clusterSingletonServiceProvider.getServiceIdentifierFromEntity(DOUBLE_ENTITY));
     }
 
     /**
      * Test GoldPath for initialization {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void initializationClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void initializationClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
@@ -195,13 +190,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for initialization with init ownership result SLAVE {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void slaveInitClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void slaveInitClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
@@ -211,13 +203,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for initialization with init ownership result SLAVE, but NO-MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void slaveInitNoMasterClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void slaveInitNoMasterClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_LOST_NO_OWNER, false);
@@ -227,13 +216,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void masterInitClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void masterInitClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -243,13 +229,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void masterInitSlaveDoubleCandidateClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void masterInitSlaveDoubleCandidateClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -260,13 +243,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void takeLeadershipClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void takeLeadershipClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -278,40 +258,31 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for initialization with init ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void masterInitClusterSingletonServiceTwoServicesTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void masterInitClusterSingletonServiceTwoServicesTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
         verify(mockEos).registerCandidate(DOUBLE_ENTITY);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
     }
 
     /**
      * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void takeLeadershipClusterSingletonServiceTwoAddDuringWaitPhaseServicesTest()
-            throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void takeLeadershipClusterSingletonServiceTwoAddDuringWaitPhaseServicesTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
         verify(mockEos).registerCandidate(DOUBLE_ENTITY);
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
@@ -322,29 +293,21 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks CandidateAlreadyRegisteredException processing in initialization phase.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
-    @Test(expected = RuntimeException.class)
-    public void initializationClusterSingletonServiceCandidateAlreadyRegistredTest()
-            throws CandidateAlreadyRegisteredException {
+    @Test
+    public void initializationClusterSingletonServiceCandidateAlreadyRegistredTest() throws Exception {
         doThrow(CandidateAlreadyRegisteredException.class).when(mockEos).registerCandidate(ENTITY);
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
-        assertNull(reg);
+        assertThrows(RuntimeException.class,
+            () -> clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService));
     }
 
     /**
      * Test GoldPath for lostLeadership during tryToTakeLeadership with ownership result MASTER
      * {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void lostLeadershipDuringTryToTakeLeadershipClusterSingletonServiceTest()
-            throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void lostLeadershipDuringTryToTakeLeadershipClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -358,13 +321,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for lostLeadership with ownership result MASTER-TO-SLAVE {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void lostLeadershipClusterSingletonServiceTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void lostLeadershipClusterSingletonServiceTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -380,13 +340,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks inJeopardy Cluster Node state for Slave Instance.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void inJeopardySlaveTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void inJeopardySlaveTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
@@ -402,13 +359,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test GoldPath for takeLeadership with ownership result MASTER {@link ClusterSingletonService}.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Test
-    public void takeLeadershipClusterSingletonServiceTowServicesTest() throws CandidateAlreadyRegisteredException {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+    public void takeLeadershipClusterSingletonServiceTowServicesTest() throws Exception {
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, LOCAL_OWNERSHIP_GRANTED, false);
@@ -424,13 +378,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void closeClusterSingletonServiceRegistrationNoRoleTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
@@ -444,17 +395,13 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void closeClusterSingletonServiceRegistrationNoRoleTwoServicesTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
@@ -469,13 +416,10 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void closeClusterSingletonServiceRegistrationSlaveTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
         verify(mockEos).registerCandidate(ENTITY);
@@ -490,17 +434,13 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void closeClusterSingletonServiceRegistrationSlaveTwoServicesTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
         verify(mockEos).registerCandidate(ENTITY);
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         clusterSingletonServiceProvider.ownershipChanged(ENTITY, REMOTE_OWNERSHIP_CHANGED, false);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
@@ -516,16 +456,12 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks close processing for {@link ClusterSingletonServiceRegistration}.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void closeClusterSingletonServiceRegistrationMasterTwoServicesTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
@@ -546,16 +482,12 @@ public abstract class AbstractDOMClusterServiceProviderTest {
 
     /**
      * Test checks validation Error processing for SLAVE-TO-MASTER entity Candidate role change.
-     *
-     * @throws Exception if the condition does not meet
      */
     @Test
     public void tryToTakeLeaderForClosedServiceRegistrationTest() throws Exception {
-        final ClusterSingletonServiceRegistration reg = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService);
+        final var reg = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService);
         assertNotNull(reg);
-        final ClusterSingletonServiceRegistration reg2 = clusterSingletonServiceProvider
-                .registerClusterSingletonService(clusterSingletonService2);
+        final var reg2 = clusterSingletonServiceProvider.registerClusterSingletonService(clusterSingletonService2);
         assertNotNull(reg2);
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService.getServiceState());
         assertEquals(TestClusterSingletonServiceState.INITIALIZED, clusterSingletonService2.getServiceState());
index 546b39ff108229f7c570e82474f05dcf2a4d6d48..26276164d40814cc8869d3c7acdab216b2717a6d 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.mdsal.singleton.dom.impl;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -33,13 +34,12 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipListener;
-import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
+import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
-import org.opendaylight.mdsal.singleton.dom.impl.util.TestEntity;
-import org.opendaylight.mdsal.singleton.dom.impl.util.TestInstanceIdentifier;
 import org.opendaylight.yangtools.concepts.Registration;
 
 /**
@@ -50,9 +50,8 @@ public class ClusterSingletonServiceGroupImplTest {
     public static final String SERVICE_IDENTIFIER = "TestServiceIdent";
     public static final ServiceGroupIdentifier SERVICE_GROUP_IDENT = ServiceGroupIdentifier.create(SERVICE_IDENTIFIER);
 
-    public static final @NonNull TestEntity MAIN_ENTITY = new TestEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
-    public static final @NonNull TestEntity CLOSE_ENTITY =
-        new TestEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
+    public static final @NonNull DOMEntity MAIN_ENTITY = new DOMEntity(SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
+    public static final @NonNull DOMEntity CLOSE_ENTITY = new DOMEntity(CLOSE_SERVICE_ENTITY_TYPE, SERVICE_IDENTIFIER);
 
     @Mock
     public ClusterSingletonService mockClusterSingletonService;
@@ -63,14 +62,11 @@ public class ClusterSingletonServiceGroupImplTest {
     @Mock
     public Registration mockCloseEntityCandReg;
     @Mock
-    public GenericEntityOwnershipListener<TestEntity> mockEosListener;
-
+    public DOMEntityOwnershipListener mockEosListener;
     @Mock
-    public GenericEntityOwnershipService<TestEntity, GenericEntityOwnershipListener<TestEntity>> mockEosService;
+    public DOMEntityOwnershipService mockEosService;
 
-    public ClusterSingletonServiceGroupImpl<TestInstanceIdentifier, TestEntity,
-        GenericEntityOwnershipListener<TestEntity>,
-        GenericEntityOwnershipService<TestEntity, GenericEntityOwnershipListener<TestEntity>>> singletonServiceGroup;
+    public ClusterSingletonServiceGroupImpl singletonServiceGroup;
 
     public ClusterSingletonServiceRegistration firstReg;
     public ClusterSingletonServiceRegistration secondReg;
@@ -105,48 +101,53 @@ public class ClusterSingletonServiceGroupImplTest {
             }
         };
 
-        singletonServiceGroup = new ClusterSingletonServiceGroupImpl<>(SERVICE_IDENTIFIER, MAIN_ENTITY, CLOSE_ENTITY,
+        singletonServiceGroup = new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, MAIN_ENTITY, CLOSE_ENTITY,
             mockEosService);
     }
 
     /**
      * Test NULL ServiceIdent input for new ServiceGroup instance.
      */
-    @Test(expected = NullPointerException.class)
+    @Test
     public void instantiationClusterSingletonServiceGroupNullIdentTest() {
-        new ClusterSingletonServiceGroupImpl<>(null, MAIN_ENTITY, CLOSE_ENTITY, mockEosService);
+        assertThrows(NullPointerException.class,
+            () -> new ClusterSingletonServiceGroupImpl(null, MAIN_ENTITY, CLOSE_ENTITY, mockEosService));
     }
 
     /**
      * Test empty ServiceIdent input for new ServiceGroup instance.
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void instantiationClusterSingletonServiceGroupEmptyIdentTest() {
-        new ClusterSingletonServiceGroupImpl<>("", MAIN_ENTITY, CLOSE_ENTITY, mockEosService);
+        assertThrows(IllegalArgumentException.class,
+            () -> new ClusterSingletonServiceGroupImpl("", MAIN_ENTITY, CLOSE_ENTITY, mockEosService));
     }
 
     /**
      * Test NULL MainEntity input for new ServiceGroup instance.
      */
-    @Test(expected = NullPointerException.class)
+    @Test
     public void instantiationClusterSingletonServiceGroupNullMainEntityTest() {
-        new ClusterSingletonServiceGroupImpl<>(SERVICE_IDENTIFIER, null, CLOSE_ENTITY, mockEosService);
+        assertThrows(NullPointerException.class,
+            () -> new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, null, CLOSE_ENTITY, mockEosService));
     }
 
     /**
      * Test NULL CloseEntity input for new ServiceGroup instance.
      */
-    @Test(expected = NullPointerException.class)
+    @Test
     public void instantiationClusterSingletonServiceGroupNullCloseEntityTest() {
-        new ClusterSingletonServiceGroupImpl<>(SERVICE_IDENTIFIER, MAIN_ENTITY, null, mockEosService);
+        assertThrows(NullPointerException.class,
+            () -> new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, MAIN_ENTITY, null, mockEosService));
     }
 
     /**
      * Test NULL EntityOwnershipService input for new ServiceGroup instance.
      */
-    @Test(expected = NullPointerException.class)
+    @Test
     public void instantiationClusterSingletonServiceGroupNullEOS_Test() {
-        new ClusterSingletonServiceGroupImpl<>(SERVICE_IDENTIFIER, MAIN_ENTITY, CLOSE_ENTITY, null);
+        assertThrows(NullPointerException.class,
+            () -> new ClusterSingletonServiceGroupImpl(SERVICE_IDENTIFIER, MAIN_ENTITY, CLOSE_ENTITY, null));
     }
 
     /**
index 76779a9772b1e9f47ee9e2907811cf044ea2d961..caba7787a7220b5de7deffe4bddb46b06e81924d 100644 (file)
@@ -23,7 +23,6 @@ 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;
 
@@ -34,12 +33,10 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegist
 public class DOMClusterSingletonServiceProviderImplTest extends AbstractDOMClusterServiceProviderTest {
     /**
      * Initialization functionality for every Tests in this suite.
-     *
-     * @throws CandidateAlreadyRegisteredException if the condition does not meet
      */
     @Override
     @Before
-    public void setup() throws CandidateAlreadyRegisteredException {
+    public void setup() throws Exception {
         super.setup();
     }
 
diff --git a/singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestEntity.java b/singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestEntity.java
deleted file mode 100644 (file)
index 75cd2e1..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.util;
-
-import java.io.Serial;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.eos.common.api.GenericEntity;
-import org.opendaylight.yangtools.yang.common.QName;
-
-/**
- * Test util class.
- */
-public class TestEntity extends GenericEntity<TestInstanceIdentifier> {
-    @Serial
-    private static final long serialVersionUID = 1L;
-
-    static final QName ENTITY = QName
-            .create("urn:opendaylight:params:xml:ns:yang:mdsal:core:test-entity", "2016-06-06", "entity").intern();
-    static final QName ENTITY_NAME = QName.create(ENTITY, "name").intern();
-
-    /** Constructs an instance.
-     *
-     * @param type the entity type
-     * @param id the entity id.
-     */
-    public TestEntity(final @NonNull String type, final @NonNull TestInstanceIdentifier id) {
-        super(type, id);
-    }
-
-    /**
-     * Construct an Entity with an with a name. The general-entity schema is used to construct the
-     * {@link TestInstanceIdentifier}.
-     *
-     * @param type the type of the entity
-     * @param entityName the name of the entity used to construct a general-entity YangInstanceIdentifier
-     */
-    public TestEntity(final @NonNull String type, final @NonNull String entityName) {
-        super(type, new TestInstanceIdentifier(entityName));
-    }
-}
diff --git a/singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestInstanceIdentifier.java b/singleton-service/mdsal-singleton-dom-impl/src/test/java/org/opendaylight/mdsal/singleton/dom/impl/util/TestInstanceIdentifier.java
deleted file mode 100644 (file)
index 956bfb0..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.util;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import java.io.Serial;
-import java.util.LinkedList;
-import java.util.List;
-import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
-
-/**
- * Test helper class. {@link HierarchicalIdentifier} for testing only.
- */
-public class TestInstanceIdentifier implements HierarchicalIdentifier<TestInstanceIdentifier> {
-    @Serial
-    private static final long serialVersionUID = 1L;
-
-    private final ImmutableList<String> path;
-
-    public TestInstanceIdentifier(final Iterable<? extends TestInstanceIdentifier> path) {
-        Preconditions.checkArgument(path != null);
-        final List<String> tiis = new LinkedList<>();
-        for (final TestInstanceIdentifier t : path) {
-            tiis.add(t.toString());
-        }
-        this.path = ImmutableList.copyOf(tiis);
-    }
-
-    TestInstanceIdentifier(final String path) {
-        this.path = ImmutableList.of(path);
-    }
-
-    @Override
-    public boolean contains(final TestInstanceIdentifier other) {
-        throw new UnsupportedOperationException();
-    }
-}