Cache full datastore context 71/87071/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Jan 2020 22:31:31 +0000 (23:31 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 28 Jan 2020 17:21:29 +0000 (17:21 +0000)
While the context is small, it is also invariant across a number of
test cases, each of which is instantiating it. Just share one
instance across all tests to speed them up.

While we are at it, we switch to using EffectiveModelContext to
ease our future migration.

Change-Id: I29a89e93903e7582bde4984828405aa2a8e45c27
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java

index c98044af329416a365c50cf14f09dbdb0dbd968e..0e421b1bc6065225622ad088afb96e8c8f1f419e 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.md.cluster.datastore.model;
 
 import java.io.InputStream;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public final class SchemaContextHelper {
@@ -17,6 +17,8 @@ public final class SchemaContextHelper {
     public static final String PEOPLE_YANG = "/people.yang";
     public static final String CARS_YANG = "/cars.yang";
 
+    private static volatile EffectiveModelContext FULL;
+
     private SchemaContextHelper() {
 
     }
@@ -25,15 +27,25 @@ public final class SchemaContextHelper {
         return SchemaContextHelper.class.getResourceAsStream(yangFileName);
     }
 
-    public static SchemaContext full() {
-        return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
+    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);
+                }
+            }
+        }
+
+        return ret;
     }
 
-    public static SchemaContext select(final String... schemaFiles) {
+    public static EffectiveModelContext select(final String... schemaFiles) {
         return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, schemaFiles);
     }
 
-    public static SchemaContext distributedShardedDOMDataTreeSchemaContext() {
+    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,