1e0511622a8a60b936fa535632a7a30b2b8239f9
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / shardstrategy / ModuleShardStrategyTest.java
1 /*
2  * Copyright (c) 2014, 2015 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.shardstrategy;
10
11 import static org.junit.Assert.assertEquals;
12 import org.junit.BeforeClass;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.ExpectedException;
16 import org.opendaylight.controller.cluster.datastore.Configuration;
17 import org.opendaylight.controller.cluster.datastore.ConfigurationImpl;
18 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21
22 public class ModuleShardStrategyTest {
23     @Rule
24     public ExpectedException expectedEx = ExpectedException.none();
25
26     private static Configuration configuration;
27
28     @BeforeClass
29     public static void setUpClass(){
30         configuration = new ConfigurationImpl("module-shards.conf", "modules.conf");
31     }
32
33
34     @Test
35     public void testFindShard() throws Exception {
36         ModuleShardStrategy moduleShardStrategy =
37             new ModuleShardStrategy("cars", configuration);
38
39         String shard = moduleShardStrategy.findShard(CarsModel.BASE_PATH);
40
41         assertEquals("cars-1", shard);
42     }
43
44     @Test
45     public void testFindShardWhenModuleConfigurationPresentInModulesButMissingInModuleShards() {
46
47         final QName BASE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:missing", "2014-03-13",
48             "missing");
49
50         final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
51
52         ModuleShardStrategy moduleShardStrategy =
53             new ModuleShardStrategy("missing", configuration);
54
55         String shard = moduleShardStrategy.findShard(BASE_PATH);
56
57         assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard);
58
59     }
60 }