X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fcluster%2Fdatastore%2Fmodel%2FSchemaContextHelper.java;h=0e421b1bc6065225622ad088afb96e8c8f1f419e;hb=abaef4a5ae37f27542155457fe7306a4662b1eeb;hp=4e906a4d157850b54e42cafeb2f5d181a3fda9bc;hpb=149feb98f151186975fe42bab5853e05aafd4b51;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java index 4e906a4d15..0e421b1bc6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java @@ -5,67 +5,50 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.md.cluster.datastore.model; -import com.google.common.base.Throwables; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; -public class SchemaContextHelper { +public final class SchemaContextHelper { public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; public static final String PEOPLE_YANG = "/people.yang"; public static final String CARS_YANG = "/cars.yang"; - public static InputStream getInputStream(final String yangFileName) { - return SchemaContextHelper.class.getResourceAsStream(yangFileName); - } + private static volatile EffectiveModelContext FULL; + + private SchemaContextHelper() { - public static SchemaContext full() { - return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG); } - public static SchemaContext select(final String... schemaFiles) { - List streams = new ArrayList<>(schemaFiles.length); + public static InputStream getInputStream(final String yangFileName) { + return SchemaContextHelper.class.getResourceAsStream(yangFileName); + } - for (String schemaFile : schemaFiles) { - streams.add(getInputStream(schemaFile)); + public static EffectiveModelContext full() { + EffectiveModelContext ret = FULL; + if (ret == null) { + synchronized (SchemaContextHelper.class) { + ret = FULL; + if (ret == null) { + ret = FULL = select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG); + } + } } - try { - return YangParserTestUtils.parseYangStreams(streams); - } catch (ReactorException e) { - throw new RuntimeException("Unable to build schema context from " + streams, e); - } + return ret; } - public static SchemaContext distributedShardedDOMDataTreeSchemaContext() { - final List streams = new ArrayList<>(); - try { - // we need prefix-shard-configuration and odl-datastore-test models - // for DistributedShardedDOMDataTree tests - streams.add(getInputStream(ODL_DATASTORE_TEST_YANG)); - streams.add(new FileInputStream("src/main/yang/prefix-shard-configuration.yang")); - return YangParserTestUtils.parseYangStreams(streams); - } catch (FileNotFoundException | ReactorException e) { - throw new RuntimeException(e); - } + public static EffectiveModelContext select(final String... schemaFiles) { + return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, schemaFiles); } - public static SchemaContext entityOwners() { - try { - return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang")); - } catch (IOException | ReactorException e) { - throw Throwables.propagate(e); - } + public static EffectiveModelContext distributedShardedDOMDataTreeSchemaContext() { + // we need prefix-shard-configuration and odl-datastore-test models + // for DistributedShardedDOMDataTree tests + return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, ODL_DATASTORE_TEST_YANG, + "/META-INF/yang/prefix-shard-configuration@2017-01-10.yang"); } }