Search in sources :

Example 1 with ShardLeaderStateChanged

use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.

the class ShardManagerTest method testRoleChangeNotificationToFollowerWithShardLeaderStateChangedReleaseReady.

@Test
public void testRoleChangeNotificationToFollowerWithShardLeaderStateChangedReleaseReady() throws Exception {
    new TestKit(getSystem()) {

        {
            TestShardManager shardManager = newTestShardManager();
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.onReceiveCommand(new RoleChangeNotification(memberId, null, RaftState.Follower.name()));
            verify(ready, never()).countDown();
            shardManager.onReceiveCommand(MockClusterWrapper.createMemberUp("member-2", getRef().path().toString()));
            shardManager.onReceiveCommand(new ShardLeaderStateChanged(memberId, "member-2-shard-default-" + shardMrgIDSuffix, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION));
            verify(ready, times(1)).countDown();
        }
    };
}
Also used : ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 2 with ShardLeaderStateChanged

use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.

the class ShardManagerTest method testRemoveShardReplicaRemote.

@Test
public void testRemoveShardReplicaRemote() throws Exception {
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-1")).build());
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    // Create an ActorSystem ShardManager actor for member-1.
    final ActorSystem system1 = newActorSystem("Member1");
    Cluster.get(system1).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    ActorRef mockDefaultShardActor = newMockShardActor(system1, Shard.DEFAULT_NAME, "member-1");
    final TestActorRef<TestShardManager> newReplicaShardManager = TestActorRef.create(system1, newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockDefaultShardActor).cluster(new ClusterWrapperImpl(system1)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem ShardManager actor for member-2.
    final ActorSystem system2 = newActorSystem("Member2");
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    String name = ShardIdentifier.create("default", MEMBER_2, shardMrgIDSuffix).toString();
    String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
    final TestActorRef<MockRespondActor> mockShardLeaderActor = TestActorRef.create(system2, Props.create(MockRespondActor.class, RemoveServer.class, new RemoveServerReply(ServerChangeStatus.OK, memberId2)), name);
    LOG.error("Mock Shard Leader Actor : {}", mockShardLeaderActor);
    final TestActorRef<TestShardManager> leaderShardManager = TestActorRef.create(system2, newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockShardLeaderActor).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Because mockShardLeaderActor is created at the top level of the actor system it has an address like so,
    // akka://cluster-test@127.0.0.1:2559/user/member-2-shard-default-config1
    // However when a shard manager has a local shard which is a follower and a leader that is remote it will
    // try to compute an address for the remote shard leader using the ShardPeerAddressResolver. This address will
    // look like so,
    // akka://cluster-test@127.0.0.1:2559/user/shardmanager-config1/member-2-shard-default-config1
    // In this specific case if we did a FindPrimary for shard default from member-1 we would come up
    // with the address of an actor which does not exist, therefore any message sent to that actor would go to
    // dead letters.
    // To work around this problem we create a ForwardingActor with the right address and pass to it the
    // mockShardLeaderActor. The ForwardingActor simply forwards all messages to the mockShardLeaderActor and every
    // thing works as expected
    final ActorRef actorRef = leaderShardManager.underlyingActor().context().actorOf(Props.create(ForwardingActor.class, mockShardLeaderActor), "member-2-shard-default-" + shardMrgIDSuffix);
    LOG.error("Forwarding actor : {}", actorRef);
    new TestKit(system1) {

        {
            newReplicaShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.tell(new ActorInitialized(), mockShardLeaderActor);
            newReplicaShardManager.tell(new ActorInitialized(), mockShardLeaderActor);
            short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
            leaderShardManager.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), leaderVersion), mockShardLeaderActor);
            leaderShardManager.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardLeaderActor);
            String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
            newReplicaShardManager.tell(new ShardLeaderStateChanged(memberId1, memberId2, mock(DataTree.class), leaderVersion), mockShardActor);
            newReplicaShardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            newReplicaShardManager.underlyingActor().waitForMemberUp();
            leaderShardManager.underlyingActor().waitForMemberUp();
            // construct a mock response message
            newReplicaShardManager.tell(new RemoveShardReplica("default", MEMBER_1), getRef());
            RemoveServer removeServer = MessageCollectorActor.expectFirstMatching(mockShardLeaderActor, RemoveServer.class);
            String removeServerId = ShardIdentifier.create("default", MEMBER_1, shardMrgIDSuffix).toString();
            assertEquals("RemoveServer serverId", removeServerId, removeServer.getServerId());
            expectMsgClass(duration("5 seconds"), Status.Success.class);
        }
    };
}
Also used : ActorSystem(akka.actor.ActorSystem) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ForwardingActor(org.opendaylight.controller.cluster.datastore.utils.ForwardingActor) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) RemoveServerReply(org.opendaylight.controller.cluster.raft.messages.RemoveServerReply) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 3 with ShardLeaderStateChanged

use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.

the class ShardManagerTest method testRoleChangeNotificationAndShardLeaderStateChangedReleaseReady.

@Test
public void testRoleChangeNotificationAndShardLeaderStateChangedReleaseReady() throws Exception {
    TestShardManager shardManager = newTestShardManager();
    String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()));
    verify(ready, never()).countDown();
    shardManager.onReceiveCommand(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION));
    verify(ready, times(1)).countDown();
}
Also used : ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 4 with ShardLeaderStateChanged

use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryForRemoteShard.

@Test
public void testOnReceiveFindPrimaryForRemoteShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForRemoteShard starting");
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    // Create an ActorSystem ShardManager actor for member-1.
    final ActorSystem system1 = newActorSystem("Member1");
    Cluster.get(system1).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1, newTestShardMgrBuilderWithMockShardActor().cluster(new ClusterWrapperImpl(system1)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem ShardManager actor for member-2.
    final ActorSystem system2 = newActorSystem("Member2");
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    final ActorRef mockShardActor2 = newMockShardActor(system2, "astronauts", "member-2");
    MockConfiguration mockConfig2 = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).build());
    final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system1) {

        {
            shardManager1.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId2 = "member-2-shard-astronauts-" + shardMrgIDSuffix;
            short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), leaderVersion), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor2);
            shardManager1.underlyingActor().waitForMemberUp();
            shardManager1.tell(new FindPrimary("astronauts", false), getRef());
            RemotePrimaryShardFound found = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-astronauts-config"));
            assertEquals("getPrimaryVersion", leaderVersion, found.getPrimaryVersion());
            shardManager2.underlyingActor().verifyFindPrimary();
        // This part times out quite a bit on jenkins for some reason
        // Cluster.get(system2).down(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
        // 
        // shardManager1.underlyingActor().waitForMemberRemoved();
        // 
        // shardManager1.tell(new FindPrimary("astronauts", false), getRef());
        // 
        // expectMsgClass(duration("5 seconds"), PrimaryNotFoundException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryForRemoteShard ending");
}
Also used : ActorSystem(akka.actor.ActorSystem) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 5 with ShardLeaderStateChanged

use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryWaitForShardLeader.

@Test
public void testOnReceiveFindPrimaryWaitForShardLeader() throws Exception {
    LOG.info("testOnReceiveFindPrimaryWaitForShardLeader starting");
    datastoreContextBuilder.shardInitializationTimeout(10, TimeUnit.SECONDS);
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            // We're passing waitUntilInitialized = true to FindPrimary so
            // the response should be
            // delayed until we send ActorInitialized and
            // RoleChangeNotification.
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            shardManager.tell(new ActorInitialized(), mockShardActor);
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
            expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
            DataTree mockDataTree = mock(DataTree.class);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
            assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
            expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
        }
    };
    LOG.info("testOnReceiveFindPrimaryWaitForShardLeader ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

Test (org.junit.Test)18 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)18 AddressFromURIString (akka.actor.AddressFromURIString)17 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)17 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)17 TestKit (akka.testkit.javadsl.TestKit)16 ActorRef (akka.actor.ActorRef)15 TestActorRef (akka.testkit.TestActorRef)15 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)14 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)14 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)8 ActorSystem (akka.actor.ActorSystem)6 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)6 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)6 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)5 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)4 List (java.util.List)3 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)3 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)3 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)3