Search in sources :

Example 16 with FindLocalShard

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

the class ShardManagerTest method testOnReceiveFindLocalShardForExistentShard.

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

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            LocalShardFound found = expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertTrue("Found path contains " + found.getPath().path().toString(), found.getPath().path().toString().contains("member-1-shard-default-config"));
        }
    };
}
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) 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 17 with FindLocalShard

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

the class ShardManagerTest method testOnCreateShardWithLocalMemberNotInShardConfig.

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

        {
            datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-5", "member-6"));
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertEquals("peerMembers size", 0, shardBuilder.getPeerAddresses().size());
            assertEquals("schemaContext", DisableElectionsRaftPolicy.class.getName(), shardBuilder.getDatastoreContext().getShardRaftConfig().getCustomRaftPolicyImplementationClass());
        }
    };
    LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 18 with FindLocalShard

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

the class ShardManagerTest method testOnCreateShardWithNoInitialSchemaContext.

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

        {
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1"));
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            SchemaContext schemaContext = TestModel.createTestContext();
            shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
            assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
        }
    };
    LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 19 with FindLocalShard

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

the class ShardManagerTest method testServerRemovedShardActorNotRunning.

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

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
            TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.underlyingActor().waitForRecoveryComplete();
            shardManager.tell(new FindLocalShard("people", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
            shardManager.tell(new FindLocalShard("default", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
            // Removed the default shard replica from member-1
            ShardIdentifier.Builder builder = new ShardIdentifier.Builder();
            ShardIdentifier shardId = builder.shardName("default").memberName(MEMBER_1).type(shardMrgIDSuffix).build();
            shardManager.tell(new ServerRemoved(shardId.toString()), getRef());
            shardManager.underlyingActor().verifySnapshotPersisted(Sets.newHashSet("people"));
        }
    };
    LOG.info("testServerRemovedShardActorNotRunning ending");
}
Also used : ServerRemoved(org.opendaylight.controller.cluster.raft.messages.ServerRemoved) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 20 with FindLocalShard

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

the class ShardManagerTest method testAddShardReplicaWithAddServerReplyFailure.

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

        {
            TestKit mockShardLeaderKit = new TestKit(getSystem());
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("astronauts", Arrays.asList("member-2")).build());
            ActorRef mockNewReplicaShardActor = newMockShardActor(getSystem(), "astronauts", "member-1");
            final TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newTestShardMgrBuilder(mockConfig).shardActor(mockNewReplicaShardActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
            shardManager.underlyingActor().setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            TestKit terminateWatcher = new TestKit(getSystem());
            terminateWatcher.watch(mockNewReplicaShardActor);
            shardManager.tell(new AddShardReplica("astronauts"), getRef());
            AddServer addServerMsg = mockShardLeaderKit.expectMsgClass(AddServer.class);
            assertEquals("AddServer serverId", "member-1-shard-astronauts-" + shardMrgIDSuffix, addServerMsg.getNewServerId());
            mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.TIMEOUT, null));
            Failure failure = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", TimeoutException.class, failure.cause().getClass());
            shardManager.tell(new FindLocalShard("astronauts", false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            terminateWatcher.expectTerminated(mockNewReplicaShardActor);
            shardManager.tell(new AddShardReplica("astronauts"), getRef());
            mockShardLeaderKit.expectMsgClass(AddServer.class);
            mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.NO_LEADER, null));
            failure = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", NoShardLeaderException.class, failure.cause().getClass());
        }
    };
    LOG.info("testAddShardReplicaWithAddServerReplyFailure ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Failure(akka.actor.Status.Failure) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) 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