use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.
the class DistributedEntityOwnershipServiceTest method testRegisterCandidate.
@Test
public void testRegisterCandidate() throws Exception {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), 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.getActorContext().getCurrentMemberName().getName());
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.getActorContext().getCurrentMemberName().getName());
service.close();
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.
the class DistributedEntityOwnershipServiceTest method testListenerRegistration.
@Test
public void testListenerRegistration() {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME);
DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
DOMEntityOwnershipListener listener = mock(DOMEntityOwnershipListener.class);
DOMEntityOwnershipListenerRegistration reg = service.registerListener(entity.getType(), listener);
assertNotNull("EntityOwnershipListenerRegistration null", reg);
assertEquals("getEntityType", entity.getType(), reg.getEntityType());
assertEquals("getInstance", listener, reg.getInstance());
RegisterListenerLocal regListener = verifyMessage(service, RegisterListenerLocal.class);
assertSame("getListener", listener, regListener.getListener());
assertEquals("getEntityType", entity.getType(), regListener.getEntityType());
reset(service);
reg.close();
UnregisterListenerLocal unregListener = verifyMessage(service, UnregisterListenerLocal.class);
assertEquals("getEntityType", entity.getType(), unregListener.getEntityType());
assertSame("getListener", listener, unregListener.getListener());
service.close();
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.
the class DistributedEntityOwnershipServiceTest method testIsCandidateRegistered.
@Test
public void testIsCandidateRegistered() throws CandidateAlreadyRegisteredException {
DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build());
final DOMEntity test = new DOMEntity("test-type", "test");
assertFalse(service.isCandidateRegistered(test));
service.registerCandidate(test);
assertTrue(service.isCandidateRegistered(test));
service.close();
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.
the class EntityOwnershipListenerActorTest method testOnEntityOwnershipChanged.
@Test
public void testOnEntityOwnershipChanged() {
DOMEntityOwnershipListener mockListener = mock(DOMEntityOwnershipListener.class);
TestActorRef<EntityOwnershipListenerActor> listenerActor = actorFactory.createTestActor(EntityOwnershipListenerActor.props(mockListener), actorFactory.generateActorId("listener"));
DOMEntity entity = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id1")));
boolean wasOwner = false;
boolean isOwner = true;
boolean hasOwner = true;
listenerActor.tell(new DOMEntityOwnershipChange(entity, EntityOwnershipChangeState.from(wasOwner, isOwner, hasOwner)), ActorRef.noSender());
verify(mockListener, timeout(5000)).ownershipChanged(ownershipChange(entity, wasOwner, isOwner, hasOwner));
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.
the class EntityOwnershipShardTest method testDelayedEntityOwnerSelection.
@Test
public void testDelayedEntityOwnerSelection() throws Exception {
testLog.info("testDelayedEntityOwnerSelection starting");
final ShardTestKit kit = new ShardTestKit(getSystem());
EntityOwnerSelectionStrategyConfig.Builder builder = EntityOwnerSelectionStrategyConfig.newBuilder().addStrategy(ENTITY_TYPE, LastCandidateSelectionStrategy.class, 500);
dataStoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2);
ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
ShardIdentifier peerId1 = newShardId(PEER_MEMBER_1_NAME);
ShardIdentifier peerId2 = newShardId(PEER_MEMBER_2_NAME);
TestActorRef<TestEntityOwnershipShard> peer1 = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId1, peerMap(leaderId.toString(), peerId2.toString()), PEER_MEMBER_1_NAME)), peerId1.toString());
peer1.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class);
TestActorRef<TestEntityOwnershipShard> peer2 = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId2, peerMap(leaderId.toString(), peerId1.toString()), PEER_MEMBER_2_NAME)), peerId2.toString());
peer2.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class);
TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId1.toString(), peerId2.toString()), LOCAL_MEMBER_NAME, builder.build()), leaderId.toString());
ShardTestKit.waitUntilLeader(leader);
DOMEntity entity = new DOMEntity(ENTITY_TYPE, ENTITY_ID1);
// Add a remote candidate
peer1.tell(new RegisterCandidateLocal(entity), kit.getRef());
kit.expectMsgClass(SuccessReply.class);
// Register local
leader.tell(new RegisterCandidateLocal(entity), kit.getRef());
kit.expectMsgClass(SuccessReply.class);
// Verify the local candidate becomes owner
verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), PEER_MEMBER_1_NAME);
verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
verifyOwner(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
testLog.info("testDelayedEntityOwnerSelection ending");
}
Aggregations