Search in sources :

Example 16 with FindPrimary

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

the class ShardManagerTest method testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp.

@Test
public void testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp starting");
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
            String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            shardManager.tell(new LeaderStateChanged(memberId1, memberId2, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
        }
    };
    LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) 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) LeaderStateChanged(org.opendaylight.controller.cluster.notifications.LeaderStateChanged) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 17 with FindPrimary

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

the class ShardManagerTest method testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId.

@Test
public void testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId starting");
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
            DataTree mockDataTree = mock(DataTree.class);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            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());
        }
    };
    LOG.info("testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId starting");
}
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)

Example 18 with FindPrimary

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

the class ShardManager method findPrimary.

private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
    Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
    Future<Object> futureObj = ask(getSelf(), new FindPrimary(shardName, true), findPrimaryTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                handler.onFailure(failure);
            } else {
                if (response instanceof RemotePrimaryShardFound) {
                    handler.onRemotePrimaryShardFound((RemotePrimaryShardFound) response);
                } else if (response instanceof LocalPrimaryShardFound) {
                    handler.onLocalPrimaryFound((LocalPrimaryShardFound) response);
                } else {
                    handler.onUnknownResponse(response);
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) RemoteFindPrimary(org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) Timeout(akka.util.Timeout) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Aggregations

FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)18 ActorRef (akka.actor.ActorRef)16 TestActorRef (akka.testkit.TestActorRef)16 TestKit (akka.testkit.javadsl.TestKit)16 Test (org.junit.Test)16 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)16 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)15 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)14 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)11 AddressFromURIString (akka.actor.AddressFromURIString)9 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)9 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)7 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)6 ActorSystem (akka.actor.ActorSystem)4 ClusterWrapperImpl (org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl)4 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)4 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)3 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)3 PrimaryShardInfoFutureCache (org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache)2 Timeout (akka.util.Timeout)1