Search in sources :

Example 11 with FindLocalShard

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

the class ShardManagerTest method testOnReceiveFindLocalShardForNonExistentShard.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new FindLocalShard("non-existent", false), getRef());
            LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            assertEquals("getShardName", "non-existent", notFound.getShardName());
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 12 with FindLocalShard

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

the class ShardManagerTest method testOnReceiveFindLocalShardWaitForShardInitialized.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            // We're passing waitUntilInitialized = true to FindLocalShard
            // so the response should be
            // delayed until we send ActorInitialized.
            Future<Object> future = Patterns.ask(shardManager, new FindLocalShard(Shard.DEFAULT_NAME, true), new Timeout(5, TimeUnit.SECONDS));
            shardManager.tell(new ActorInitialized(), mockShardActor);
            Object resp = Await.result(future, duration("5 seconds"));
            assertTrue("Expected: LocalShardFound, Actual: " + resp, resp instanceof LocalShardFound);
        }
    };
    LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) Timeout(akka.util.Timeout) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 13 with FindLocalShard

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

the class ShardManagerTest method waitForShardInitialized.

private static void waitForShardInitialized(final ActorRef shardManager, final String shardName, final TestKit kit) {
    AssertionError last = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        try {
            shardManager.tell(new FindLocalShard(shardName, true), kit.getRef());
            kit.expectMsgClass(LocalShardFound.class);
            return;
        } catch (AssertionError e) {
            last = e;
        }
        Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    }
    throw last;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)

Example 14 with FindLocalShard

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

the class ShardManagerTest method testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader.

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

        {
            TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newPropsShardMgrWithMockShardActor(), shardMgrID);
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            String leaderId = "leader-member-shard-default-" + shardMrgIDSuffix;
            AddServerReply addServerReply = new AddServerReply(ServerChangeStatus.ALREADY_EXISTS, null);
            ActorRef leaderShardActor = shardManager.underlyingActor().getContext().actorOf(Props.create(MockRespondActor.class, AddServer.class, addServerReply), leaderId);
            MockClusterWrapper.sendMemberUp(shardManager, "leader-member", leaderShardActor.path().toString());
            String newReplicaId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(newReplicaId, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            shardManager.tell(new ShardLeaderStateChanged(newReplicaId, leaderId, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            MessageCollectorActor.expectFirstMatching(leaderShardActor, AddServer.class);
            Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            // Send message again to verify previous in progress state is
            // cleared
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            resp = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
            // Send message again with an AddServer timeout to verify the
            // pre-existing shard actor isn't terminated.
            shardManager.tell(newDatastoreContextFactory(datastoreContextBuilder.shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build()), getRef());
            leaderShardActor.tell(MockRespondActor.CLEAR_RESPONSE, ActorRef.noSender());
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            expectMsgClass(duration("5 seconds"), Failure.class);
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
        }
    };
    LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader ending");
}
Also used : 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) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 15 with FindLocalShard

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

the class ShardManagerTest method testAddShardReplicaWithPreExistingLocalReplicaLeader.

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

        {
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
        }
    };
    LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader ending");
}
Also used : 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) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)24 TestKit (akka.testkit.javadsl.TestKit)20 Test (org.junit.Test)20 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)12 ActorRef (akka.actor.ActorRef)10 TestActorRef (akka.testkit.TestActorRef)10 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)9 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)9 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)8 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 FiniteDuration (scala.concurrent.duration.FiniteDuration)8 AddressFromURIString (akka.actor.AddressFromURIString)6 LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)5 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)4 DataChangeScope (org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope)4 ClusteredDOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)4 Failure (akka.actor.Status.Failure)3 Shard (org.opendaylight.controller.cluster.datastore.Shard)3 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)3