ModuleShardStrategy implements ShardStrategy { @Override public String findShard(YangInstanceIdentifier path) { String shardName = configuration.getShardNameForModule(moduleName); return shardName != null ? shardName : DefaultShardStrategy.DEFAULT_SHARD; } ModuleShardStrategy(String moduleName, Configuration configuration); @Override String findShard(YangInstanceIdentifier path); @Override YangInstanceIdentifier getPrefixForPath(YangInstanceIdentifier path); static final String NAME; }
@Test public void testFindShard() { ModuleShardStrategy moduleShardStrategy = new ModuleShardStrategy("cars", configuration); String shard = moduleShardStrategy.findShard(CarsModel.BASE_PATH); assertEquals("cars-1", shard); }
@Test public void testFindShardWhenModuleConfigurationPresentInModulesButMissingInModuleShards() { final QName baseQName = QName.create( "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:missing", "2014-03-13", "missing"); final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(baseQName); ModuleShardStrategy moduleShardStrategy = new ModuleShardStrategy("missing", configuration); String shard = moduleShardStrategy.findShard(BASE_PATH); assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard); }