Search in sources :

Example 26 with DOMEntity

use of org.opendaylight.mdsal.eos.dom.api.DOMEntity in project controller by opendaylight.

the class EntityOwnershipShardTest method testOnRegisterCandidateLocalWithIsolatedLeader.

@Test
public void testOnRegisterCandidateLocalWithIsolatedLeader() throws Exception {
    testLog.info("testOnRegisterCandidateLocalWithIsolatedLeader starting");
    final ShardTestKit kit = new ShardTestKit(getSystem());
    dataStoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2).shardIsolatedLeaderCheckIntervalInMillis(50);
    ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
    ShardIdentifier peerId = newShardId(PEER_MEMBER_1_NAME);
    TestActorRef<TestEntityOwnershipShard> peer = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId, peerMap(leaderId.toString()), PEER_MEMBER_1_NAME)), peerId.toString());
    TestEntityOwnershipShard peerShard = peer.underlyingActor();
    peerShard.startDroppingMessagesOfType(ElectionTimeout.class);
    TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId.toString()), LOCAL_MEMBER_NAME));
    ShardTestKit.waitUntilLeader(leader);
    // Drop AppendEntries and wait enough time for the shard to switch to IsolatedLeader.
    peerShard.startDroppingMessagesOfType(AppendEntries.class);
    verifyRaftState(leader, state -> assertEquals("getRaftState", RaftState.IsolatedLeader.toString(), state.getRaftState()));
    YangInstanceIdentifier entityId = ENTITY_ID1;
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    leader.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Resume AppendEntries - the candidate write should now be committed.
    peerShard.stopDroppingMessagesOfType(AppendEntries.class);
    verifyCommittedEntityCandidate(leader, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    verifyOwner(leader, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    testLog.info("testOnRegisterCandidateLocalWithIsolatedLeader ending");
}
Also used : RegisterCandidateLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal) ShardTestKit(org.opendaylight.controller.cluster.datastore.ShardTestKit) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)26 Test (org.junit.Test)21 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)13 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)13 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)7 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)4 UnregisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal)4 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)4 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 ArrayList (java.util.ArrayList)2 UnregisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal)2 EntityOwnerSelectionStrategyConfig (org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig)2 PeerUp (org.opendaylight.controller.cluster.datastore.messages.PeerUp)2 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)2 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)2 ActorRef (akka.actor.ActorRef)1 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1