Search in sources :

Example 1 with ClusterWrapperImpl

use of org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl 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 2 with ClusterWrapperImpl

use of org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl 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 3 with ClusterWrapperImpl

use of org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl in project controller by opendaylight.

the class ShardManagerTest method testAddShardReplica.

@Test
public void testAddShardReplica() throws Exception {
    LOG.info("testAddShardReplica starting");
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).build());
    final String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    datastoreContextBuilder.shardManagerPersistenceId(shardManagerID);
    // 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(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 memberId2 = "member-2-shard-astronauts-" + shardMrgIDSuffix;
    String name = ShardIdentifier.create("astronauts", MEMBER_2, "config").toString();
    final TestActorRef<MockRespondActor> mockShardLeaderActor = TestActorRef.create(system2, Props.create(MockRespondActor.class, AddServer.class, new AddServerReply(ServerChangeStatus.OK, memberId2)).withDispatcher(Dispatchers.DefaultDispatcherId()), name);
    final TestActorRef<TestShardManager> leaderShardManager = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig).shardActor(mockShardLeaderActor).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system1) {

        {
            newReplicaShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            leaderShardManager.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);
            newReplicaShardManager.underlyingActor().waitForMemberUp();
            leaderShardManager.underlyingActor().waitForMemberUp();
            // Have a dummy snapshot to be overwritten by the new data
            // persisted.
            String[] restoredShards = { "default", "people" };
            ShardManagerSnapshot snapshot = new ShardManagerSnapshot(Arrays.asList(restoredShards), Collections.emptyMap());
            InMemorySnapshotStore.addSnapshot(shardManagerID, snapshot);
            Uninterruptibles.sleepUninterruptibly(2, TimeUnit.MILLISECONDS);
            InMemorySnapshotStore.addSnapshotSavedLatch(shardManagerID);
            InMemorySnapshotStore.addSnapshotDeletedLatch(shardManagerID);
            // construct a mock response message
            newReplicaShardManager.tell(new AddShardReplica("astronauts"), getRef());
            AddServer addServerMsg = MessageCollectorActor.expectFirstMatching(mockShardLeaderActor, AddServer.class);
            String addServerId = "member-1-shard-astronauts-" + shardMrgIDSuffix;
            assertEquals("AddServer serverId", addServerId, addServerMsg.getNewServerId());
            expectMsgClass(duration("5 seconds"), Status.Success.class);
            InMemorySnapshotStore.waitForSavedSnapshot(shardManagerID, ShardManagerSnapshot.class);
            InMemorySnapshotStore.waitForDeletedSnapshot(shardManagerID);
            List<ShardManagerSnapshot> persistedSnapshots = InMemorySnapshotStore.getSnapshots(shardManagerID, ShardManagerSnapshot.class);
            assertEquals("Number of snapshots persisted", 1, persistedSnapshots.size());
            ShardManagerSnapshot shardManagerSnapshot = persistedSnapshots.get(0);
            assertEquals("Persisted local shards", Sets.newHashSet("default", "astronauts"), Sets.newHashSet(shardManagerSnapshot.getShardList()));
        }
    };
    LOG.info("testAddShardReplica ending");
}
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) 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) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) ShardManagerSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 4 with ClusterWrapperImpl

use of org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl in project controller by opendaylight.

the class ShardManagerTest method testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange.

@Test
public void testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange() throws Exception {
    LOG.info("testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange 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 ActorRef mockShardActor1 = newMockShardActor(system1, Shard.DEFAULT_NAME, "member-1");
    final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
    final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1, newTestShardMgrBuilder().shardActor(mockShardActor1).cluster(new ClusterWrapperImpl(system1)).primaryShardInfoCache(primaryShardInfoCache).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, Shard.DEFAULT_NAME, "member-2");
    MockConfiguration mockConfig2 = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "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());
            shardManager1.tell(new ActorInitialized(), mockShardActor1);
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
            String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager1.tell(new ShardLeaderStateChanged(memberId1, memberId2, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor1);
            shardManager1.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor1);
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor2);
            shardManager1.underlyingActor().waitForMemberUp();
            shardManager1.tell(new FindPrimary("default", true), getRef());
            RemotePrimaryShardFound found = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-default-config"));
            primaryShardInfoCache.putSuccessful("default", new PrimaryShardInfo(system1.actorSelection(mockShardActor1.path()), DataStoreVersions.CURRENT_VERSION));
            shardManager1.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager1.underlyingActor().waitForUnreachableMember();
            shardManager1.tell(new FindPrimary("default", true), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
            assertNull("Expected primaryShardInfoCache entry removed", primaryShardInfoCache.getIfPresent("default"));
            shardManager1.tell(new ShardLeaderStateChanged(memberId1, memberId1, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor1);
            shardManager1.tell(new RoleChangeNotification(memberId1, RaftState.Follower.name(), RaftState.Leader.name()), mockShardActor1);
            shardManager1.tell(new FindPrimary("default", true), getRef());
            LocalPrimaryShardFound found1 = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            String path1 = found1.getPrimaryPath();
            assertTrue("Unexpected primary path " + path1, path1.contains("member-1-shard-default-config"));
        }
    };
    LOG.info("testShardAvailabilityChangeOnMemberUnreachableAndLeadershipChange 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) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 5 with ClusterWrapperImpl

use of org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl in project controller by opendaylight.

the class ShardManagerTest method testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable.

@Test
public void testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable() throws Exception {
    LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable starting");
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-256", "member-2")).build());
    // Create an ActorSystem, ShardManager and actor for member-256.
    final ActorSystem system256 = newActorSystem("Member256");
    // 2562 is the tcp port of Member256 in src/test/resources/application.conf.
    Cluster.get(system256).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
    final ActorRef mockShardActor256 = newMockShardActor(system256, Shard.DEFAULT_NAME, "member-256");
    final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
    // ShardManager must be created with shard configuration to let its localShards has shards.
    final TestActorRef<TestShardManager> shardManager256 = TestActorRef.create(system256, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor256).cluster(new ClusterWrapperImpl(system256)).primaryShardInfoCache(primaryShardInfoCache).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem, ShardManager and actor for member-2 whose name is contained in member-256.
    final ActorSystem system2 = newActorSystem("Member2");
    // Join member-2 into the cluster of member-256.
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
    final ActorRef mockShardActor2 = newMockShardActor(system2, Shard.DEFAULT_NAME, "member-2");
    final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system256) {

        {
            shardManager256.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager256.tell(new ActorInitialized(), mockShardActor256);
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId256 = "member-256-shard-default-" + shardMrgIDSuffix;
            String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
            shardManager256.tell(new ShardLeaderStateChanged(memberId256, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor256);
            shardManager256.tell(new RoleChangeNotification(memberId256, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor256);
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor2);
            shardManager256.underlyingActor().waitForMemberUp();
            shardManager256.tell(new FindPrimary("default", true), getRef());
            LocalPrimaryShardFound found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path + " which must on member-256", path.contains("member-256-shard-default-config"));
            PrimaryShardInfo primaryShardInfo = new PrimaryShardInfo(system256.actorSelection(mockShardActor256.path()), DataStoreVersions.CURRENT_VERSION);
            primaryShardInfoCache.putSuccessful("default", primaryShardInfo);
            // Simulate member-2 become unreachable.
            shardManager256.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager256.underlyingActor().waitForUnreachableMember();
            // Make sure leader shard on member-256 is still leader and still in the cache.
            shardManager256.tell(new FindPrimary("default", true), getRef());
            found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path + " which must still not on member-256", path.contains("member-256-shard-default-config"));
            Future<PrimaryShardInfo> futurePrimaryShard = primaryShardInfoCache.getIfPresent("default");
            futurePrimaryShard.onComplete(new OnComplete<PrimaryShardInfo>() {

                @Override
                public void onComplete(final Throwable failure, final PrimaryShardInfo futurePrimaryShardInfo) {
                    if (failure != null) {
                        assertTrue("Primary shard info is unexpectedly removed from primaryShardInfoCache", false);
                    } else {
                        assertEquals("Expected primaryShardInfoCache entry", primaryShardInfo, futurePrimaryShardInfo);
                    }
                }
            }, system256.dispatchers().defaultGlobalDispatcher());
        }
    };
    LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable 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) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

ActorRef (akka.actor.ActorRef)6 ActorSystem (akka.actor.ActorSystem)6 AddressFromURIString (akka.actor.AddressFromURIString)6 TestActorRef (akka.testkit.TestActorRef)6 TestKit (akka.testkit.javadsl.TestKit)6 Test (org.junit.Test)6 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)6 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)6 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)6 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)6 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)6 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)6 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)6 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)4 List (java.util.List)3 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)3 Status (akka.actor.Status)2 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)2 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)2 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)2