Merge "Bug#1854 - Exit command in console causing OOM."
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / BenchmarkModel.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.md.sal.dom.store.benchmark;
9
10 import java.io.InputStream;
11 import java.util.Collections;
12 import java.util.Set;
13
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
19
20 /**
21  * Benchmark Model class loads the odl-datastore-test.yang model from resources.
22  * <br>
23  * This class serves as facilitator class which holds several references to initialized yang model as static final
24  * members.
25  *
26  * @author Lukas Sedlak <lsedlak@cisco.com>
27  */
28 public final class BenchmarkModel {
29
30     public static final QName TEST_QNAME = QName
31         .create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13","test");
32     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
33     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
34     public static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
35     public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
36     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
37
38     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
39     public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
40
41     public static final InputStream getDatastoreBenchmarkInputStream() {
42         return getInputStream(DATASTORE_TEST_YANG);
43     }
44
45     private static InputStream getInputStream(final String resourceName) {
46         return BenchmarkModel.class.getResourceAsStream(resourceName);
47     }
48
49     public static SchemaContext createTestContext() {
50         YangParserImpl parser = new YangParserImpl();
51         Set<Module> modules = parser.parseYangModelsFromStreams(Collections.singletonList(
52             getDatastoreBenchmarkInputStream()));
53         return parser.resolveSchemaContext(modules);
54     }
55 }