Search in sources :

Example 1 with RaftStateVerifier

use of org.opendaylight.controller.cluster.datastore.MemberNode.RaftStateVerifier in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testAddShardReplica.

@Test
public void testAddShardReplica() throws Exception {
    String name = "testAddShardReplica";
    String moduleShardsConfig = "module-shards-cars-member-1.conf";
    MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).waitForShardLeader("cars").build();
    MemberNode newReplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.waitForMembersUp("member-2");
    doAddShardReplica(newReplicaNode2, "cars", "member-1");
    MemberNode newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.waitForMembersUp("member-3");
    newReplicaNode2.waitForMembersUp("member-3");
    doAddShardReplica(newReplicaNode3, "cars", "member-1", "member-2");
    verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "cars", "member-1", "member-3");
    verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "cars", "member-1", "member-3");
    // Write data to member-2's config datastore and read/verify via member-3
    final NormalizedNode<?, ?> configCarsNode = writeCarsNodeAndVerify(newReplicaNode2.configDataStore(), newReplicaNode3.configDataStore());
    // Write data to member-3's oper datastore and read/verify via member-2
    writeCarsNodeAndVerify(newReplicaNode3.operDataStore(), newReplicaNode2.operDataStore());
    // Verify all data has been replicated. We expect 4 log entries and thus last applied index of 3 -
    // 2 ServerConfigurationPayload entries,  the transaction payload entry plus a purge payload.
    RaftStateVerifier verifier = raftState -> {
        assertEquals("Commit index", 3, raftState.getCommitIndex());
        assertEquals("Last applied index", 3, raftState.getLastApplied());
    };
    verifyRaftState(leaderNode1.configDataStore(), "cars", verifier);
    verifyRaftState(leaderNode1.operDataStore(), "cars", verifier);
    verifyRaftState(newReplicaNode2.configDataStore(), "cars", verifier);
    verifyRaftState(newReplicaNode2.operDataStore(), "cars", verifier);
    verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
    verifyRaftState(newReplicaNode3.operDataStore(), "cars", verifier);
    // Restart member-3 and verify the cars config shard is re-instated.
    Cluster.get(leaderNode1.kit().getSystem()).down(Cluster.get(newReplicaNode3.kit().getSystem()).selfAddress());
    newReplicaNode3.cleanup();
    newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).createOperDatastore(false).build();
    verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
    readCarsNodeAndVerify(newReplicaNode3.configDataStore(), configCarsNode);
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Arrays(java.util.Arrays) AddShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddShardReplicaInputBuilder) PoisonPill(akka.actor.PoisonPill) ActorRef(akka.actor.ActorRef) Cluster(akka.cluster.Cluster) Optional(com.google.common.base.Optional) Map(java.util.Map) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Set(java.util.Set) GetPrefixShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput) People(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People) GetShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput) GetShardRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInputBuilder) Assert.assertFalse(org.junit.Assert.assertFalse) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) TRUE(java.lang.Boolean.TRUE) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) Iterables(com.google.common.collect.Iterables) BackupDatastoreInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInputBuilder) SerializationUtils(org.apache.commons.lang3.SerializationUtils) InMemorySnapshotStore(org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore) ArrayList(java.util.ArrayList) ClusterUtils(org.opendaylight.controller.cluster.datastore.utils.ClusterUtils) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) Lists(com.google.common.collect.Lists) Success(akka.actor.Status.Success) RaftStateVerifier(org.opendaylight.controller.cluster.datastore.MemberNode.RaftStateVerifier) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) ChangeMemberVotingStatesForShardInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForShardInputBuilder) Before(org.junit.Before) PrefixShardConfiguration(org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration) AddPrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddPrefixShardReplicaInput) GetPrefixShardRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInputBuilder) MemberNode.verifyRaftState(org.opendaylight.controller.cluster.datastore.MemberNode.verifyRaftState) Assert.assertTrue(org.junit.Assert.assertTrue) AddPrefixShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddPrefixShardReplicaInputBuilder) Test(org.junit.Test) File(java.io.File) ShardResultBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResultBuilder) Assert.assertNull(org.junit.Assert.assertNull) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RemovePrefixShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInputBuilder) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Shard(org.opendaylight.controller.cluster.datastore.Shard) Assert.assertEquals(org.junit.Assert.assertEquals) RpcError(org.opendaylight.yangtools.yang.common.RpcError) MakeLeaderLocalInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.MakeLeaderLocalInputBuilder) AddReplicasForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput) ChangeMemberVotingStatesForAllShardsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsInputBuilder) ServerInfo(org.opendaylight.controller.cluster.raft.persisted.ServerInfo) GetPrefixShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInput) CarsModel(org.opendaylight.controller.md.cluster.datastore.model.CarsModel) Assert.assertThat(org.junit.Assert.assertThat) MemberNode.verifyNoShardPresent(org.opendaylight.controller.cluster.datastore.MemberNode.verifyNoShardPresent) After(org.junit.After) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) FlipMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutput) Assert.fail(org.junit.Assert.fail) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) URI(java.net.URI) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ImmutableMap(com.google.common.collect.ImmutableMap) Sets(com.google.common.collect.Sets) PeopleModel(org.opendaylight.controller.md.cluster.datastore.model.PeopleModel) List(java.util.List) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) Entry(java.util.Map.Entry) MemberVotingStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingStateBuilder) PrefixShardCreated(org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated) RemoveShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveShardReplicaInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemovePrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInput) InMemoryJournal(org.opendaylight.controller.cluster.raft.utils.InMemoryJournal) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) MemberNode.verifyRaftPeersPresent(org.opendaylight.controller.cluster.datastore.MemberNode.verifyRaftPeersPresent) GetShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInput) RemoveAllShardReplicasInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasInputBuilder) Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) SimpleEntry(java.util.AbstractMap.SimpleEntry) FALSE(java.lang.Boolean.FALSE) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) ChangeMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutput) Assert.assertNotNull(org.junit.Assert.assertNotNull) RaftState(org.opendaylight.controller.cluster.raft.RaftState) RemoveAllShardReplicasOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutput) FileInputStream(java.io.FileInputStream) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) ShardResult(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResult) UpdateElectionTerm(org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm) Collections(java.util.Collections) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) RaftStateVerifier(org.opendaylight.controller.cluster.datastore.MemberNode.RaftStateVerifier) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)1 PoisonPill (akka.actor.PoisonPill)1 Success (akka.actor.Status.Success)1 Cluster (akka.cluster.Cluster)1 Optional (com.google.common.base.Optional)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FALSE (java.lang.Boolean.FALSE)1 TRUE (java.lang.Boolean.TRUE)1 URI (java.net.URI)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1