From c635f363b08648325878c21078fb188664124207 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 11 Jul 2014 11:33:51 +0200 Subject: [PATCH 1/1] Bug 1352: Added regression test to InMemory Data Store. Change-Id: Ia3a4e332c275d6dfdf9dafd2dfc433de15dbcb6f Signed-off-by: Tony Tkacik --- .../impl/SchemaUpdateForTransactionTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java new file mode 100644 index 0000000000..ee62c0bfbf --- /dev/null +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.sal.dom.store.impl; + +import static org.junit.Assert.assertNotNull; + +import java.util.concurrent.ExecutionException; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top; +import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; +import org.opendaylight.yangtools.yang.binding.util.BindingReflections; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +import com.google.common.base.Throwables; +import com.google.common.util.concurrent.MoreExecutors; + +public class SchemaUpdateForTransactionTest { + + private static final InstanceIdentifier TOP_PATH = InstanceIdentifier.of(Top.QNAME); + private SchemaContext schemaContext; + private InMemoryDOMDataStore domStore; + + @Before + public void setupStore() { + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); + loadSchemas(RockTheHouseInput.class); + } + + public void loadSchemas(final Class... classes) { + YangModuleInfo moduleInfo; + try { + ModuleInfoBackedContext context = ModuleInfoBackedContext.create(); + for (Class clz : classes) { + moduleInfo = BindingReflections.getModuleInfo(clz); + + context.registerModuleInfo(moduleInfo); + } + schemaContext = context.tryToCreateSchemaContext().get(); + domStore.onGlobalContextUpdated(schemaContext); + } catch (Exception e) { + Throwables.propagateIfPossible(e); + } + } + + /** + * Test suite tests allocating transaction when schema context + * does not contain module necessary for client write, + * then triggering update of global schema context + * and then performing write (according to new module). + * + * If transaction between allocation and schema context was + * unmodified, it is safe to change its schema context + * to new one (e.g. it will be same as if allocated after + * schema context update.) + * + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testTransactionSchemaUpdate() throws InterruptedException, ExecutionException { + + assertNotNull(domStore); + + // We allocate transaction, initial schema context does not + // contain Lists model + DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction(); + assertNotNull(writeTx); + + // we trigger schema context update to contain Lists model + loadSchemas(RockTheHouseInput.class, Top.class); + + /** + * + * Writes /test in writeTx, this write should not fail + * with IllegalArgumentException since /test is in + * schema context. + * + */ + writeTx.write(TOP_PATH, ImmutableNodes.containerNode(Top.QNAME)); + + } + +} -- 2.36.6