2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.dom.store.impl;
10 import static org.junit.Assert.assertNotNull;
12 import java.util.concurrent.ExecutionException;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
19 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
20 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
21 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import com.google.common.base.Throwables;
27 import com.google.common.util.concurrent.MoreExecutors;
29 public class SchemaUpdateForTransactionTest {
31 private static final YangInstanceIdentifier TOP_PATH = YangInstanceIdentifier.of(Top.QNAME);
32 private SchemaContext schemaContext;
33 private InMemoryDOMDataStore domStore;
36 public void setupStore() {
37 domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor(),
38 MoreExecutors.sameThreadExecutor());
39 loadSchemas(RockTheHouseInput.class);
42 public void loadSchemas(final Class<?>... classes) {
43 YangModuleInfo moduleInfo;
45 ModuleInfoBackedContext context = ModuleInfoBackedContext.create();
46 for (Class<?> clz : classes) {
47 moduleInfo = BindingReflections.getModuleInfo(clz);
49 context.registerModuleInfo(moduleInfo);
51 schemaContext = context.tryToCreateSchemaContext().get();
52 domStore.onGlobalContextUpdated(schemaContext);
53 } catch (Exception e) {
54 Throwables.propagateIfPossible(e);
59 * Test suite tests allocating transaction when schema context
60 * does not contain module necessary for client write,
61 * then triggering update of global schema context
62 * and then performing write (according to new module).
64 * If transaction between allocation and schema context was
65 * unmodified, it is safe to change its schema context
66 * to new one (e.g. it will be same as if allocated after
67 * schema context update.)
69 * @throws InterruptedException
70 * @throws ExecutionException
73 public void testTransactionSchemaUpdate() throws InterruptedException, ExecutionException {
75 assertNotNull(domStore);
77 // We allocate transaction, initial schema context does not
78 // contain Lists model
79 DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
80 assertNotNull(writeTx);
82 // we trigger schema context update to contain Lists model
83 loadSchemas(RockTheHouseInput.class, Top.class);
87 * Writes /test in writeTx, this write should not fail
88 * with IllegalArgumentException since /test is in
92 writeTx.write(TOP_PATH, ImmutableNodes.containerNode(Top.QNAME));