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
@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;
*
* @param entityOwnershipService relevant EOS
*/
- protected AbstractClusterSingletonServiceProviderImpl(final @NonNull S entityOwnershipService) {
+ protected AbstractClusterSingletonServiceProviderImpl(
+ final @NonNull DOMEntityOwnershipService entityOwnershipService) {
this.entityOwnershipService = requireNonNull(entityOwnershipService);
}
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));
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();
}
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));
// 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));
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();
}
@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);
* 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.
* @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.
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;
/**
* @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
* @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
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;
* @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 {
/**
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")
* 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
}
@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);
}
* @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);
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;
* 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")));
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);
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;
* 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);
}
}
@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);
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);
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;
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();
*/
@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);
}
*/
@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());
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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());
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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());
/**
* 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());
/**
* 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);
/**
* 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());
/**
* 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());
/**
* 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());
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;
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;
/**
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;
@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;
}
};
- 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));
}
/**
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;
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();
}
+++ /dev/null
-/*
- * 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));
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}