diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-05-17 09:10:39 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-05-23 09:24:12 +0000 |
commit | d54ea758da8dcf71d52727c4f01f87090c50bf2e (patch) | |
tree | bf86e49ad4899b50c97654ae144d4b2e8902d1b8 /v3po/data-impl/src/test | |
parent | 9e59a344c5a5b81fb7b7292184e849ad0fc9507c (diff) |
HONEYCOMB-61: Add BA broker for context data tree
With broker, context data can be accessed in a transactional
manner, same as config data
+ Renamed data-api concepts to not include DataTree
+ Renamed context related concepts to better distinguish between them
+ Now passing full ReadContext to read customizers
+ Naming context is backed by context data broker
Change-Id: I0b2876dd74a31a9ced7d9b5145672868e12f8b82
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/data-impl/src/test')
-rw-r--r-- | v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/DataBrokerTest.java | 20 | ||||
-rw-r--r-- | v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegatorTest.java (renamed from v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTreeTest.java) | 77 | ||||
-rw-r--r-- | v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadOnlyTransactionTest.java | 10 | ||||
-rw-r--r-- | v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegatorTest.java (renamed from v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java) | 14 | ||||
-rw-r--r-- | v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/WriteTransactionTest.java | 30 |
5 files changed, 94 insertions, 57 deletions
diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/DataBrokerTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/DataBrokerTest.java index a2908d591..55b92b50b 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/DataBrokerTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/DataBrokerTest.java @@ -22,9 +22,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; -import io.fd.honeycomb.v3po.data.ReadableDataTree; -import io.fd.honeycomb.v3po.data.ModifiableDataTree; -import io.fd.honeycomb.v3po.data.DataTreeSnapshot; +import io.fd.honeycomb.v3po.data.ReadableDataManager; +import io.fd.honeycomb.v3po.data.ModifiableDataManager; +import io.fd.honeycomb.v3po.data.DataModification; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -42,18 +42,18 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class DataBrokerTest { @Mock - private ReadableDataTree operationalData; + private ReadableDataManager operationalData; @Mock - private ModifiableDataTree confiDataTree; + private ModifiableDataManager confiDataTree; @Mock - private DataTreeSnapshot configSnapshot; + private DataModification configSnapshot; private DataBroker broker; @Before public void setUp() { initMocks(this); - when(confiDataTree.takeSnapshot()).thenReturn(configSnapshot); - broker = new DataBroker(operationalData, confiDataTree); + when(confiDataTree.newModification()).thenReturn(configSnapshot); + broker = DataBroker.create(confiDataTree, operationalData); } @Test @@ -64,7 +64,7 @@ public class DataBrokerTest { // verify that read and write transactions use the same config snapshot verify(configSnapshot).read(path); - verify(configSnapshot).newModification(); + verify(confiDataTree).newModification(); } @Test @@ -72,7 +72,7 @@ public class DataBrokerTest { final DOMDataWriteTransaction writeTx = broker.newWriteOnlyTransaction(); // verify that write transactions use config snapshot - verify(configSnapshot).newModification(); + verify(confiDataTree).newModification(); } @Test diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTreeTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegatorTest.java index b7f8b9d2c..fed32da8a 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTreeTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegatorTest.java @@ -25,13 +25,15 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.data.DataTreeSnapshot; +import com.google.common.util.concurrent.Futures; +import io.fd.honeycomb.v3po.data.DataModification; import io.fd.honeycomb.v3po.translate.TranslationException; import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriterRegistry; @@ -42,6 +44,7 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet; @@ -55,9 +58,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -public class ConfigDataTreeTest { +public class ModifiableDataTreeDelegatorTest { @Mock private WriterRegistry writer; @@ -66,14 +68,16 @@ public class ConfigDataTreeTest { @Mock private DataTree dataTree; @Mock - private DataTreeModification modification; + private org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification modification; + @Mock + private DataBroker contextBroker; - private ConfigDataTree configDataTree; + private ModifiableDataTreeManager configDataTree; @Before public void setUp() { initMocks(this); - configDataTree = new ConfigDataTree(serializer, dataTree, writer); + configDataTree = new ModifiableDataTreeDelegator(serializer, dataTree, writer, contextBroker); } @Test @@ -81,17 +85,18 @@ public class ConfigDataTreeTest { final org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot snapshot = mock(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot.class); when(dataTree.takeSnapshot()).thenReturn(snapshot); + when(snapshot.newModification()).thenReturn(modification); final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class); final Optional node = mock(Optional.class); - doReturn(node).when(snapshot).readNode(path); + doReturn(node).when(modification).readNode(path); - final DataTreeSnapshot dataTreeSnapshot = configDataTree.takeSnapshot(); + final DataModification dataTreeSnapshot = configDataTree.newModification(); final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future = dataTreeSnapshot.read(path); - verify(dataTree).takeSnapshot(); - verify(snapshot).readNode(path); + verify(dataTree, times(2)).takeSnapshot(); + verify(modification).readNode(path); assertTrue(future.isDone()); assertEquals(node, future.get()); @@ -102,19 +107,29 @@ public class ConfigDataTreeTest { final org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot snapshot = mock(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot.class); when(dataTree.takeSnapshot()).thenReturn(snapshot); - when(snapshot.newModification()).thenReturn(modification); - final DataTreeSnapshot dataTreeSnapshot = configDataTree.takeSnapshot(); - final DataTreeModification newModification = dataTreeSnapshot.newModification(); - verify(dataTree).takeSnapshot(); - verify(snapshot).newModification(); - - assertEquals(modification, newModification); + final DataModification dataTreeSnapshot = configDataTree.newModification(); + // Snapshot captured twice, so that original data could be provided to translation layer without any possible + // modification + verify(dataTree, times(2)).takeSnapshot(); + verify(snapshot, times(2)).newModification(); } @Test public void testCommitSuccessful() throws Exception { + final org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot + snapshot = mock(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot.class); + when(dataTree.takeSnapshot()).thenReturn(snapshot); + when(snapshot.newModification()).thenReturn(modification); + final DataTreeCandidate prepare = mock(DataTreeCandidate.class); + doReturn(prepare).when(dataTree).prepare(modification); + + final org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction ctxTransaction = mock( + org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction.class); + doReturn(ctxTransaction).when(contextBroker).newReadWriteTransaction(); + doReturn(Futures.immediateCheckedFuture(null)).when(ctxTransaction).submit(); + final DataObject dataBefore = mockDataObject("before", Ethernet.class); final DataObject dataAfter = mockDataObject("after", Ethernet.class); @@ -128,7 +143,9 @@ public class ConfigDataTreeTest { when(rootNode.getDataAfter()).thenReturn(Optional.<NormalizedNode<?, ?>>fromNullable(nodeAfter)); // Run the test - configDataTree.modify(modification); + doReturn(rootNode).when(prepare).getRootNode(); + final DataModification dataModification = configDataTree.newModification(); + dataModification.commit(); // Verify all changes were processed: verify(writer).update( @@ -138,6 +155,8 @@ public class ConfigDataTreeTest { // Verify modification was validated verify(dataTree).validate(modification); + // Verify context transaction was finished + verify(ctxTransaction).submit(); } private Map<InstanceIdentifier<?>, DataObject> mapOf(final DataObject dataBefore, final Class<Ethernet> type) { @@ -154,6 +173,13 @@ public class ConfigDataTreeTest { @Test public void testCommitUndoSuccessful() throws Exception { + final org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot + snapshot = mock(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot.class); + when(dataTree.takeSnapshot()).thenReturn(snapshot); + when(snapshot.newModification()).thenReturn(modification); + final DataTreeCandidate prepare = mock(DataTreeCandidate.class); + doReturn(prepare).when(dataTree).prepare(modification); + // Prepare data changes: final DataObject dataBefore = mockDataObject("before", Ethernet.class); final DataObject dataAfter = mockDataObject("after", Ethernet.class); @@ -177,7 +203,9 @@ public class ConfigDataTreeTest { // Run the test try { - configDataTree.modify(modification); + doReturn(rootNode).when(prepare).getRootNode(); + final DataModification dataModification = configDataTree.newModification(); + dataModification.commit(); } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException e) { verify(writer).update(anyMap(), anyMap(), any(WriteContext.class)); verify(reverter).revert(); @@ -190,6 +218,13 @@ public class ConfigDataTreeTest { @Test public void testCommitUndoFailed() throws Exception { + final org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot + snapshot = mock(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot.class); + when(dataTree.takeSnapshot()).thenReturn(snapshot); + when(snapshot.newModification()).thenReturn(modification); + final DataTreeCandidate prepare = mock(DataTreeCandidate.class); + doReturn(prepare).when(dataTree).prepare(modification); + // Prepare data changes: final DataObject dataBefore = mockDataObject("before", Ethernet.class); final DataObject dataAfter = mockDataObject("after", Ethernet.class); @@ -219,7 +254,9 @@ public class ConfigDataTreeTest { // Run the test try { - configDataTree.modify(modification); + doReturn(rootNode).when(prepare).getRootNode(); + final DataModification dataModification = configDataTree.newModification(); + dataModification.commit(); } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.Reverter.RevertFailedException e) { verify(writer).update(anyMap(), anyMap(), any(WriteContext.class)); verify(reverter).revert(); diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadOnlyTransactionTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadOnlyTransactionTest.java index 30fdd1392..a13621725 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadOnlyTransactionTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadOnlyTransactionTest.java @@ -24,8 +24,8 @@ import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.data.ReadableDataTree; -import io.fd.honeycomb.v3po.data.DataTreeSnapshot; +import io.fd.honeycomb.v3po.data.ReadableDataManager; +import io.fd.honeycomb.v3po.data.DataModification; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -37,16 +37,16 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; public class ReadOnlyTransactionTest { @Mock - private ReadableDataTree operationalData; + private ReadableDataManager operationalData; @Mock - private DataTreeSnapshot configSnapshot; + private DataModification configSnapshot; private ReadOnlyTransaction readOnlyTx; @Before public void setUp() { initMocks(this); - readOnlyTx = new ReadOnlyTransaction(operationalData, configSnapshot); + readOnlyTx = ReadOnlyTransaction.create(configSnapshot, operationalData); } @Test diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegatorTest.java index 7e6abcdcd..4492c70a2 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/ReadableDataTreeDelegatorTest.java @@ -42,6 +42,7 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; @@ -58,14 +59,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -public class OperationalDataTreeTest { +public class ReadableDataTreeDelegatorTest { @Mock private BindingNormalizedNodeSerializer serializer; @Mock private ReaderRegistry reader; - private OperationalDataTree operationalData; + private ReadableDataTreeDelegator operationalData; @Mock private InstanceIdentifier<DataObject> id; @@ -81,16 +82,23 @@ public class OperationalDataTreeTest { private DOMDataBroker netconfMonitoringBroker; @Mock private DOMDataReadOnlyTransaction domDataReadOnlyTransaction; + @Mock + private DataBroker contextBroker; @Before public void setUp() { initMocks(this); - operationalData = new OperationalDataTree(serializer, globalContext, reader, netconfMonitoringBroker); + operationalData = new ReadableDataTreeDelegator(serializer, globalContext, reader, netconfMonitoringBroker, contextBroker); doReturn(schemaNode).when(globalContext).getDataChildByName(any(QName.class)); doReturn(domDataReadOnlyTransaction).when(netconfMonitoringBroker).newReadOnlyTransaction(); doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(domDataReadOnlyTransaction) .read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class)); + + final org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction ctxTransaction = mock( + org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction.class); + doReturn(ctxTransaction).when(contextBroker).newReadWriteTransaction(); + doReturn(Futures.immediateCheckedFuture(null)).when(ctxTransaction).submit(); } @Test diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/WriteTransactionTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/WriteTransactionTest.java index d0360dbd8..9cde27d2b 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/WriteTransactionTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/WriteTransactionTest.java @@ -23,12 +23,10 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.data.ModifiableDataTree; -import io.fd.honeycomb.v3po.data.DataTreeSnapshot; +import io.fd.honeycomb.v3po.data.DataModification; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -36,54 +34,48 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; public class WriteTransactionTest { @Mock - private ModifiableDataTree configDataTree; - @Mock - private DataTreeSnapshot configSnapshot; + private DataModification configSnapshot; @Mock private YangInstanceIdentifier path; @Mock private NormalizedNode<?,?> data; - @Mock - private DataTreeModification dataTreeModification; private WriteTransaction writeTx; @Before public void setUp() { initMocks(this); - when(configSnapshot.newModification()).thenReturn(dataTreeModification); - writeTx = new WriteTransaction(configDataTree, configSnapshot); + writeTx = WriteTransaction.createConfigOnly(configSnapshot); } @Test public void testPut() { writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data); - verify(dataTreeModification).write(path, data); + verify(configSnapshot).write(path, data); } @Test(expected = IllegalArgumentException.class) public void testPutOperational() { writeTx.put(LogicalDatastoreType.OPERATIONAL, path, data); - verify(dataTreeModification).write(path, data); + verify(configSnapshot).write(path, data); } @Test(expected = IllegalStateException.class) public void testOnFinishedTx() { writeTx.submit(); writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data); - verify(dataTreeModification).write(path, data); + verify(configSnapshot).write(path, data); } @Test public void testMerge() { writeTx.merge(LogicalDatastoreType.CONFIGURATION, path, data); - verify(dataTreeModification).merge(path, data); + verify(configSnapshot).merge(path, data); } @Test @@ -100,19 +92,19 @@ public class WriteTransactionTest { @Test public void testDelete() { writeTx.delete(LogicalDatastoreType.CONFIGURATION, path); - verify(dataTreeModification).delete(path); + verify(configSnapshot).delete(path); } @Test public void testSubmit() throws Exception { writeTx.submit(); - verify(dataTreeModification).ready(); - verify(configDataTree).modify(dataTreeModification); + verify(configSnapshot).validate(); + verify(configSnapshot).commit(); } @Test public void testSubmitFailed() throws Exception { - doThrow(mock(DataValidationFailedException.class)).when(configDataTree).modify(dataTreeModification); + doThrow(mock(DataValidationFailedException.class)).when(configSnapshot).commit(); final CheckedFuture<Void, TransactionCommitFailedException> future = writeTx.submit(); try { future.get(); |