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