BUG-2138: Create DistributedShardFrontend
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / PrefixShardCreationTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore;
10
11 import akka.actor.ActorRef;
12 import akka.actor.Status.Success;
13 import akka.testkit.JavaTestKit;
14 import java.util.Collections;
15 import java.util.concurrent.TimeUnit;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.Shard.Builder;
18 import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl;
19 import org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider;
20 import org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration;
21 import org.opendaylight.controller.cluster.datastore.messages.CreatePrefixedShard;
22 import org.opendaylight.controller.cluster.datastore.messages.FindLocalShard;
23 import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound;
24 import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound;
25 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
26 import org.opendaylight.controller.cluster.datastore.shardstrategy.PrefixShardStrategy;
27 import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
28 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
29 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
30 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
31 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * Tests prefix shard creation in ShardManager.
37  */
38 public class PrefixShardCreationTest extends AbstractShardManagerTest {
39
40     private static final Logger LOG = LoggerFactory.getLogger(PrefixShardCreationTest.class);
41
42     private static final DOMDataTreeIdentifier TEST_ID =
43             new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
44
45     @Test
46     public void testPrefixShardCreation() throws Exception {
47
48         LOG.info("testPrefixShardCreation starting");
49         new JavaTestKit(getSystem()) {
50             {
51                 datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
52
53                 final ActorRef shardManager = actorFactory.createActor(newShardMgrProps(
54                         new ConfigurationImpl(new EmptyModuleShardConfigProvider())));
55
56                 final SchemaContext schemaContext = TestModel.createTestContext();
57                 shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
58
59                 shardManager.tell(new FindLocalShard(
60                         ClusterUtils.getCleanShardName(TestModel.TEST_PATH), true), getRef());
61                 expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
62
63                 final Builder builder = Shard.builder();
64
65                 final CreatePrefixedShard createPrefixedShard = new CreatePrefixedShard(
66                         new PrefixShardConfiguration(TEST_ID,
67                                 PrefixShardStrategy.NAME,
68                                 Collections.singletonList(MEMBER_1)),
69                         datastoreContextBuilder.build(), builder);
70
71                 shardManager.tell(createPrefixedShard, getRef());
72                 expectMsgClass(duration("5 seconds"), Success.class);
73
74                 shardManager.tell(new FindLocalShard(
75                         ClusterUtils.getCleanShardName(TestModel.TEST_PATH), true), getRef());
76                 expectMsgClass(duration("5 seconds"), LocalShardFound.class);
77             }
78         };
79     }
80 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.