DistributedEntityOwnershipService implements DOMEntityOwnershipService, AutoCloseable { @Override public DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity) throws CandidateAlreadyRegisteredException { requireNonNull(entity, "entity cannot be null"); if (registeredEntities.putIfAbsent(entity, entity) != null) { throw new CandidateAlreadyRegisteredException(entity); } RegisterCandidateLocal registerCandidate = new RegisterCandidateLocal(entity); LOG.debug("Registering candidate with message: {}", registerCandidate); executeLocalEntityOwnershipShardOperation(registerCandidate); return new DistributedEntityOwnershipCandidateRegistration(entity, this); } DistributedEntityOwnershipService(final ActorUtils context); static DistributedEntityOwnershipService start(final ActorUtils context,
            final EntityOwnerSelectionStrategyConfig strategyConfig); @Override DOMEntityOwnershipCandidateRegistration registerCandidate(final DOMEntity entity); @Override DOMEntityOwnershipListenerRegistration registerListener(final String entityType,
            final DOMEntityOwnershipListener listener); @Override Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity); @Override boolean isCandidateRegistered(final DOMEntity entity); @Override void close();  }
@Test public void testRegisterCandidate() throws Exception { DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start( dataStore.getActorUtils(), EntityOwnerSelectionStrategyConfig.newBuilder().build())); YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME); DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId); DOMEntityOwnershipCandidateRegistration reg = service.registerCandidate(entity); verifyRegisterCandidateLocal(service, entity); verifyEntityOwnershipCandidateRegistration(entity, reg); verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE, entityId, dataStore.getActorUtils().getCurrentMemberName().getName()); try { service.registerCandidate(entity); fail("Expected CandidateAlreadyRegisteredException"); } catch (CandidateAlreadyRegisteredException e) { assertEquals("getEntity", entity, e.getEntity()); } reset(service); DOMEntity entity2 = new DOMEntity(ENTITY_TYPE2, entityId); DOMEntityOwnershipCandidateRegistration reg2 = service.registerCandidate(entity2); verifyEntityOwnershipCandidateRegistration(entity2, reg2); verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE2, entityId, dataStore.getActorUtils().getCurrentMemberName().getName()); service.close(); }