Search in sources :

Example 31 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier 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

ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)31 Test (org.junit.Test)15 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)11 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)11 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)11 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 ActorRef (akka.actor.ActorRef)3 Status (akka.actor.Status)3 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 Timeout (akka.util.Timeout)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)3 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)3 FlipShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus)3 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)3 TestActorRef (akka.testkit.TestActorRef)2 HashMap (java.util.HashMap)2