@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());
    // Register the same entity - should throw exception
    try {
        service.registerCandidate(entity);
        fail("Expected CandidateAlreadyRegisteredException");
    } catch (CandidateAlreadyRegisteredException e) {
        // expected
        assertEquals("getEntity", entity, e.getEntity());
    }
    // Register a different entity - should succeed
    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();
}