From 1b41def30b66456bdf9ccbcb295f258ef3129707 Mon Sep 17 00:00:00 2001 From: Basheeruddin Ahmed Date: Fri, 22 Aug 2014 19:03:02 -0700 Subject: [PATCH] BUG 1606 - A read is attempted on a WRITE_ONLY transaction Change-Id: I896d976ff387ecdc9ecfe6e4cb2ead75b15c15f5 Signed-off-by: Basheeruddin Ahmed --- .../datastore/TransactionChainProxy.java | 4 +- .../datastore/TransactionChainProxyTest.java | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index c4ec760b40..76bbef713c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -36,13 +36,13 @@ public class TransactionChainProxy implements DOMStoreTransactionChain{ @Override public DOMStoreReadWriteTransaction newReadWriteTransaction() { return new TransactionProxy(actorContext, - TransactionProxy.TransactionType.WRITE_ONLY, schemaContext); + TransactionProxy.TransactionType.READ_WRITE, schemaContext); } @Override public DOMStoreWriteTransaction newWriteOnlyTransaction() { return new TransactionProxy(actorContext, - TransactionProxy.TransactionType.READ_WRITE, schemaContext); + TransactionProxy.TransactionType.WRITE_ONLY, schemaContext); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java new file mode 100644 index 0000000000..9b7039764f --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -0,0 +1,52 @@ +/* + * + * 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.cluster.datastore; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class TransactionChainProxyTest { + ActorContext actorContext = Mockito.mock(ActorContext.class); + SchemaContext schemaContext = Mockito.mock(SchemaContext.class); + @Test + public void testNewReadOnlyTransaction() throws Exception { + + DOMStoreTransaction dst = new TransactionChainProxy(actorContext, schemaContext).newReadOnlyTransaction(); + Assert.assertTrue(dst instanceof DOMStoreReadTransaction); + + } + + @Test + public void testNewReadWriteTransaction() throws Exception { + DOMStoreTransaction dst = new TransactionChainProxy(actorContext, schemaContext).newReadWriteTransaction(); + Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction); + + } + + @Test + public void testNewWriteOnlyTransaction() throws Exception { + DOMStoreTransaction dst = new TransactionChainProxy(actorContext, schemaContext).newWriteOnlyTransaction(); + Assert.assertTrue(dst instanceof DOMStoreWriteTransaction); + + } + + @Test(expected=UnsupportedOperationException.class) + public void testClose() throws Exception { + new TransactionChainProxy(actorContext, schemaContext).close(); + } +} -- 2.36.6