Bug 8568: Convert sal-binding-dom-it tests to use DataBroker 22/58022/4
authorTom Pantelis <tompantelis@gmail.com>
Tue, 30 May 2017 22:41:49 +0000 (18:41 -0400)
committerRobert Varga <nite@hq.sk>
Thu, 1 Jun 2017 00:17:35 +0000 (00:17 +0000)
Converted the tests in sal-binding-dom-it to use the DataBroker API
instead of the deprecated DataProviderService.

Change-Id: I6d4a3442d3c5cf5ddf34806b6a71454c48e3b54a
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/md/sal/binding/data/ConcurrentImplicitCreateTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/md/sal/binding/data/WildcardedDataChangeListenerTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/DeleteNestedAugmentationListenParentTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentListenAugmentTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentReadChildTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/BrokerIntegrationTest.java
opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java

index cdf7fbc..e74a97f 100644 (file)
@@ -7,20 +7,19 @@
  */
 package org.opendaylight.controller.md.sal.binding.data;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 
 /**
  * FIXME: THis test should be moved to sal-binding-broker and rewriten
@@ -35,25 +34,16 @@ public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
     private static final InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, BAR_KEY);
 
     @Test
-    public void testConcurrentCreate() throws InterruptedException, ExecutionException {
+    public void testConcurrentCreate() throws InterruptedException, ExecutionException, TimeoutException {
 
-        DataModificationTransaction fooTx = baDataService.beginTransaction();
-        DataModificationTransaction barTx = baDataService.beginTransaction();
+        DataBroker dataBroker = testContext.getDataBroker();
+        WriteTransaction fooTx = dataBroker.newWriteOnlyTransaction();
+        WriteTransaction barTx = dataBroker.newWriteOnlyTransaction();
 
-        fooTx.putOperationalData(FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
-        barTx.putOperationalData(BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
-
-        Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
-        Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
-
-        RpcResult<TransactionStatus> fooResult = fooFuture.get();
-        RpcResult<TransactionStatus> barResult = barFuture.get();
-
-        assertTrue(fooResult.isSuccessful());
-        assertTrue(barResult.isSuccessful());
-
-        assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
-        assertEquals(TransactionStatus.COMMITED, barResult.getResult());
+        fooTx.put(LogicalDatastoreType.OPERATIONAL, FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
+        barTx.put(LogicalDatastoreType.OPERATIONAL, BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
 
+        fooTx.submit().get(5, TimeUnit.SECONDS);
+        barTx.submit().get(5, TimeUnit.SECONDS);
     }
 }
index e0a151a..e9f0b20 100644 (file)
@@ -10,16 +10,18 @@ package org.opendaylight.controller.md.sal.binding.data;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Collections;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
@@ -83,23 +85,20 @@ public class WildcardedDataChangeListenerTest extends AbstractDataServiceTest {
     @Test
     public void testSeparateWrites() throws InterruptedException, TimeoutException, ExecutionException {
 
-        DataProviderService dataBroker = testContext.getBindingDataBroker();
+        DataBroker dataBroker = testContext.getDataBroker();
 
-        final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
-        dataBroker.registerDataChangeListener(DEEP_WILDCARDED_PATH, new DataChangeListener() {
-            @Override
-            public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent) {
-                eventFuture.set(dataChangeEvent);
-            }
-        });
+        final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
+                SettableFuture.create();
+        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
+            dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
 
-        DataModificationTransaction transaction = dataBroker.beginTransaction();
-        transaction.putOperationalData(NODE_0_CWU_PATH, CWU);
-        transaction.putOperationalData(NODE_0_LVU_PATH, LVU);
-        transaction.putOperationalData(NODE_1_LVU_PATH, LVU);
-        transaction.commit().get();
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
+        transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
+        transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
+        transaction.submit().get(5, TimeUnit.SECONDS);
 
-        DataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
 
         validateEvent(event);
     }
@@ -107,30 +106,27 @@ public class WildcardedDataChangeListenerTest extends AbstractDataServiceTest {
     @Test
     public void testWriteByReplace() throws InterruptedException, TimeoutException, ExecutionException {
 
-        DataProviderService dataBroker = testContext.getBindingDataBroker();
+        DataBroker dataBroker = testContext.getDataBroker();
 
-        final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
-        dataBroker.registerDataChangeListener(DEEP_WILDCARDED_PATH, new DataChangeListener() {
-            @Override
-            public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent) {
-                eventFuture.set(dataChangeEvent);
-            }
-        });
+        final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
+                SettableFuture.create();
+        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
+            dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
 
-        DataModificationTransaction cwuTx = dataBroker.beginTransaction();
-        cwuTx.putOperationalData(NODE_0_CWU_PATH, CWU);
-        cwuTx.commit().get();
+        final WriteTransaction cwuTx = dataBroker.newWriteOnlyTransaction();
+        cwuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
+        cwuTx.submit().get(5, TimeUnit.SECONDS);
 
         assertFalse(eventFuture.isDone());
 
-        DataModificationTransaction lvuTx = dataBroker.beginTransaction();
+        final WriteTransaction lvuTx = dataBroker.newWriteOnlyTransaction();
 
         TreeComplexUsesAugment tcua = new TreeComplexUsesAugmentBuilder()
                 .setListViaUses(Collections.singletonList(LVU)).build();
 
-        lvuTx.putOperationalData(NODE_0_TCU_PATH, tcua);
-        lvuTx.putOperationalData(NODE_1_LVU_PATH, LVU);
-        lvuTx.commit().get();
+        lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_TCU_PATH, tcua, true);
+        lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
+        lvuTx.submit().get(5, TimeUnit.SECONDS);
 
         validateEvent(eventFuture.get(1000, TimeUnit.MILLISECONDS));
     }
@@ -138,42 +134,38 @@ public class WildcardedDataChangeListenerTest extends AbstractDataServiceTest {
     @Test
     public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
 
-        DataProviderService dataBroker = testContext.getBindingDataBroker();
+        DataBroker dataBroker = testContext.getDataBroker();
 
         // We wrote initial state NODE_0_FLOW
-        DataModificationTransaction transaction = dataBroker.beginTransaction();
-        transaction.putOperationalData(NODE_0_LVU_PATH, LVU);
-        transaction.commit().get();
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
+        transaction.submit().get(5, TimeUnit.SECONDS);
 
         // We registered DataChangeListener
-        final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
-        dataBroker.registerDataChangeListener(DEEP_WILDCARDED_PATH, new DataChangeListener() {
-
-            @Override
-            public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> dataChangeEvent) {
-                eventFuture.set(dataChangeEvent);
-            }
-        });
+        final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
+                SettableFuture.create();
+        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
+            dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
         assertFalse(eventFuture.isDone());
 
-        DataModificationTransaction secondTx = dataBroker.beginTransaction();
-        secondTx.putOperationalData(NODE_0_LVU_PATH, LVU);
-        secondTx.putOperationalData(NODE_1_LVU_PATH, LVU);
-        secondTx.commit().get();
+        final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
+        secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
+        secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
+        secondTx.submit().get(5, TimeUnit.SECONDS);
 
-        DataChangeEvent<InstanceIdentifier<?>, DataObject> event = (eventFuture.get(1000, TimeUnit.MILLISECONDS));
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
         assertNotNull(event);
         // Data change should contains NODE_1 Flow - which was added
-        assertTrue(event.getCreatedOperationalData().containsKey(NODE_1_LVU_PATH));
+        assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
         // Data change must not containe NODE_0 Flow which was replaced with same value.
-        assertFalse(event.getUpdatedOperationalData().containsKey(NODE_0_LVU_PATH));
+        assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
     }
 
-    private static void validateEvent(final DataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
+    private static void validateEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
         assertNotNull(event);
-        assertTrue(event.getCreatedOperationalData().containsKey(NODE_1_LVU_PATH));
-        assertTrue(event.getCreatedOperationalData().containsKey(NODE_0_LVU_PATH));
-        assertFalse(event.getCreatedOperationalData().containsKey(NODE_0_CWU_PATH));
+        assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
+        assertTrue(event.getCreatedData().containsKey(NODE_0_LVU_PATH));
+        assertFalse(event.getCreatedData().containsKey(NODE_0_CWU_PATH));
     }
 
 }
index 6e6ae9a..213f62e 100644 (file)
@@ -9,12 +9,17 @@
 package org.opendaylight.controller.sal.binding.test.bugfix;
 
 import static org.junit.Assert.assertFalse;
+
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugmentBuilder;
@@ -50,28 +55,23 @@ public class DeleteNestedAugmentationListenParentTest extends AbstractDataServic
 
 
     @Test
-    public void deleteChildListenParent() throws InterruptedException, ExecutionException {
-        DataModificationTransaction initTx = baDataService.beginTransaction();
-
-        initTx.putOperationalData(LIST11_PATH, createList11());
-        initTx.commit().get();
-
-        final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
+    public void deleteChildListenParent() throws InterruptedException, ExecutionException, TimeoutException {
+        DataBroker dataBroker = testContext.getDataBroker();
+        final WriteTransaction initTx = dataBroker.newWriteOnlyTransaction();
 
-        baDataService.registerDataChangeListener(LIST11_PATH, new DataChangeListener() {
+        initTx.put(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, createList11(), true);
+        initTx.submit().get(5, TimeUnit.SECONDS);
 
-            @Override
-            public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-                event.set(change);
-            }
-        });
+        final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
+        dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, LIST11_PATH,
+            change -> event.set(change), DataChangeScope.SUBTREE);
 
-        DataModificationTransaction deleteTx = baDataService.beginTransaction();
-        deleteTx.removeOperationalData(LIST11_PATH.augmentation(List11SimpleAugment.class));
-        deleteTx.commit().get();
+        final WriteTransaction deleteTx = dataBroker.newWriteOnlyTransaction();
+        deleteTx.delete(LogicalDatastoreType.OPERATIONAL, LIST11_PATH.augmentation(List11SimpleAugment.class));
+        deleteTx.submit().get(5, TimeUnit.SECONDS);
 
-        DataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
-        assertFalse(receivedEvent.getRemovedOperationalData().contains(TLL_COMPLEX_AUGMENT_PATH));
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
+        assertFalse(receivedEvent.getRemovedPaths().contains(TLL_COMPLEX_AUGMENT_PATH));
     }
 
     private List11 createList11() {
index 591effb..a74b6ea 100644 (file)
@@ -10,12 +10,15 @@ package org.opendaylight.controller.sal.binding.test.bugfix;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.concurrent.TimeUnit;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
@@ -45,37 +48,32 @@ public class WriteParentListenAugmentTest extends AbstractDataServiceTest {
     @Test
     public void writeNodeListenAugment() throws Exception {
 
-        final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
-
-        ListenerRegistration<DataChangeListener> dclRegistration = baDataService.registerDataChangeListener(
-                AUGMENT_WILDCARDED_PATH, new DataChangeListener() {
+        final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
+        DataBroker dataBroker = testContext.getDataBroker();
+        ListenerRegistration<org.opendaylight.controller.md.sal.binding.api.DataChangeListener> dclRegistration =
+                dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, AUGMENT_WILDCARDED_PATH,
+                    change -> event.set(change), DataChangeScope.SUBTREE);
 
-                    @Override
-                    public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-                        event.set(change);
-                    }
-                });
-
-        DataModificationTransaction modification = baDataService.beginTransaction();
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
 
         TopLevelList tll = new TopLevelListBuilder() //
                 .setKey(TLL_KEY) //
                 .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
-        modification.putOperationalData(TLL_INSTANCE_ID_BA, tll);
-        modification.commit().get();
+        transaction.put(LogicalDatastoreType.OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
+        transaction.submit().get(5, TimeUnit.SECONDS);
 
-        DataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
-        assertTrue(receivedEvent.getCreatedOperationalData().containsKey(AUGMENT_TLL_PATH));
+        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
+        assertTrue(receivedEvent.getCreatedData().containsKey(AUGMENT_TLL_PATH));
 
         dclRegistration.close();
 
-        DataModificationTransaction mod2 = baDataService.beginTransaction();
-        mod2.putOperationalData(AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
-        mod2.commit().get();
+        final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
+        transaction2.put(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
+        transaction2.submit().get(5, TimeUnit.SECONDS);
 
-        TreeComplexUsesAugment readedAug = (TreeComplexUsesAugment) baDataService.readOperationalData(AUGMENT_TLL_PATH);
+        TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(
+                LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH).checkedGet(5, TimeUnit.SECONDS).get();
         assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
-
     }
 
     private TreeComplexUsesAugment treeComplexUsesAugment(final String value) {
@@ -83,4 +81,4 @@ public class WriteParentListenAugmentTest extends AbstractDataServiceTest {
                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build()) //
                 .build();
     }
-}
\ No newline at end of file
+}
index de7445e..dca56ab 100644 (file)
@@ -11,10 +11,14 @@ package org.opendaylight.controller.sal.binding.test.bugfix;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
+import java.util.concurrent.TimeUnit;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
@@ -28,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class WriteParentReadChildTest extends AbstractDataServiceTest {
 
@@ -49,43 +52,36 @@ public class WriteParentReadChildTest extends AbstractDataServiceTest {
 
     private static final InstanceIdentifier<? extends DataObject> LIST11_INSTANCE_ID_BA = //
             LIST1_INSTANCE_ID_BA.child(List11.class, LIST11_KEY);
+
     /**
-     *
      * The scenario tests writing parent node, which also contains child items
      * and then reading child directly, by specifying path to the child.
-     *
      * Expected behaviour is child is returned.
-     *
-     * @throws Exception
      */
     @Test
     public void writeParentReadChild() throws Exception {
 
-        DataModificationTransaction modification = baDataService.beginTransaction();
+        DataBroker dataBroker = testContext.getDataBroker();
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
 
         List11 list11 = new List11Builder() //
                 .setKey(LIST11_KEY) //
                 .setAttrStr("primary")
                 .build();
 
-        List1 list1 = new List1Builder()
-            .setKey(LIST1_KEY)
-            .setList11(ImmutableList.of(list11))
-        .build();
+        List1 list1 = new List1Builder().setKey(LIST1_KEY).setList11(ImmutableList.of(list11)).build();
 
-        modification.putConfigurationData(LIST1_INSTANCE_ID_BA, list1);
-        RpcResult<TransactionStatus> ret = modification.commit().get();
-        assertNotNull(ret);
-        assertEquals(TransactionStatus.COMMITED, ret.getResult());
+        transaction.put(LogicalDatastoreType.OPERATIONAL, LIST1_INSTANCE_ID_BA, list1, true);
+        transaction.submit().get(5, TimeUnit.SECONDS);
 
-        DataObject readList1 = baDataService.readConfigurationData(LIST1_INSTANCE_ID_BA);
-        assertNotNull("Readed table should not be nul.", readList1);
-        assertTrue(readList1 instanceof List1);
+        Optional<List1> readList1 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
+                LIST1_INSTANCE_ID_BA).checkedGet(1000, TimeUnit.MILLISECONDS);
+        assertTrue(readList1.isPresent());
 
-        DataObject readList11 = baDataService.readConfigurationData(LIST11_INSTANCE_ID_BA);
+        Optional<? extends DataObject> readList11 = dataBroker.newReadOnlyTransaction().read(
+                LogicalDatastoreType.OPERATIONAL, LIST11_INSTANCE_ID_BA).checkedGet(5, TimeUnit.SECONDS);
         assertNotNull("Readed flow should not be null.",readList11);
-        assertTrue(readList11 instanceof List11);
-        assertEquals(list11, readList11);
-
+        assertTrue(readList11.isPresent());
+        assertEquals(list11, readList11.get());
     }
 }
index 425a62b..2d7f44d 100644 (file)
@@ -8,20 +8,21 @@
 package org.opendaylight.controller.sal.binding.test.connect.dom;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import java.util.concurrent.Future;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import java.util.concurrent.TimeUnit;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class BrokerIntegrationTest extends AbstractDataServiceTest {
 
@@ -36,69 +37,47 @@ public class BrokerIntegrationTest extends AbstractDataServiceTest {
     @Test
     public void simpleModifyOperation() throws Exception {
 
-        DataObject tllFoo = baDataService.readConfigurationData(FOO_PATH);
-        assertNull(tllFoo);
-        TopLevelList tllFooData = createTll(TLL_FOO_KEY);
-
-        DataModificationTransaction transaction = baDataService.beginTransaction();
-        transaction.putConfigurationData(FOO_PATH, tllFooData);
-        Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
-        assertNotNull(commitResult);
+        DataBroker dataBroker = testContext.getDataBroker();
+        Optional<TopLevelList> tllFoo = dataBroker.newReadOnlyTransaction().read(
+                LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
+        assertFalse(tllFoo.isPresent());
 
-        RpcResult<TransactionStatus> result = commitResult.get();
+        TopLevelList tllFooData = createTll(TLL_FOO_KEY);
 
-        assertNotNull(result);
-        assertNotNull(result.getResult());
-        assertEquals(TransactionStatus.COMMITED, result.getResult());
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        transaction.put(LogicalDatastoreType.CONFIGURATION, FOO_PATH, tllFooData);
+        transaction.submit().get(5, TimeUnit.SECONDS);
 
-        TopLevelList readedData = (TopLevelList) baDataService.readConfigurationData(FOO_PATH);
-        assertNotNull(readedData);
-        assertEquals(tllFooData.getKey(), readedData.getKey());
+        Optional<TopLevelList> readedData = dataBroker.newReadOnlyTransaction().read(
+                LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
+        assertTrue(readedData.isPresent());
+        assertEquals(tllFooData.getKey(), readedData.get().getKey());
 
         TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
         TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
 
-        DataModificationTransaction insertMoreTr = baDataService.beginTransaction();
-        insertMoreTr.putConfigurationData(BAR_PATH, nodeBarData);
-        insertMoreTr.putConfigurationData(BAZ_PATH, nodeBazData);
-        RpcResult<TransactionStatus> result2 = insertMoreTr.commit().get();
-
-        assertNotNull(result2);
-        assertNotNull(result2.getResult());
-        assertEquals(TransactionStatus.COMMITED, result.getResult());
-
-        Top top = (Top) baDataService.readConfigurationData(TOP_PATH);
-        assertNotNull(top);
-        assertNotNull(top.getTopLevelList());
-        assertEquals(3, top.getTopLevelList().size());
-
-        /**
-         * We create transaction no 2
-         *
-         */
-        DataModificationTransaction removalTransaction = baDataService.beginTransaction();
-        assertNotNull(transaction);
-
-        /**
-         * We remove node 1
-         *
-         */
-        removalTransaction.removeConfigurationData(BAR_PATH);
-
-        /**
-         * We commit transaction
-         */
-        Future<RpcResult<TransactionStatus>> commitResult2 = removalTransaction.commit();
-        assertNotNull(commitResult2);
-
-        RpcResult<TransactionStatus> result3 = commitResult2.get();
-
-        assertNotNull(result3);
-        assertNotNull(result3.getResult());
-        assertEquals(TransactionStatus.COMMITED, result2.getResult());
-
-        DataObject readedData2 = baDataService.readConfigurationData(BAR_PATH);
-        assertNull(readedData2);
+        final WriteTransaction insertMoreTr = dataBroker.newWriteOnlyTransaction();
+        insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAR_PATH, nodeBarData);
+        insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAZ_PATH, nodeBazData);
+        insertMoreTr.submit().get(5, TimeUnit.SECONDS);
+
+        Optional<Top> top = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, TOP_PATH)
+                .checkedGet(5, TimeUnit.SECONDS);
+        assertTrue(top.isPresent());
+        assertEquals(3, top.get().getTopLevelList().size());
+
+         // We create transaction no 2
+        final WriteTransaction removalTransaction = dataBroker.newWriteOnlyTransaction();
+
+         // We remove node 1
+        removalTransaction.delete(LogicalDatastoreType.CONFIGURATION, BAR_PATH);
+
+         // We commit transaction
+        removalTransaction.submit().get(5, TimeUnit.SECONDS);
+
+        Optional<TopLevelList> readedData2 = dataBroker.newReadOnlyTransaction().read(
+                LogicalDatastoreType.CONFIGURATION, BAR_PATH).checkedGet(5, TimeUnit.SECONDS);
+        assertFalse(readedData2.isPresent());
     }
 
     private static TopLevelList createTll(final TopLevelListKey key) {
index fc92567..baa2c12 100644 (file)
@@ -8,28 +8,29 @@
 package org.opendaylight.controller.test.sal.binding.it;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import java.util.concurrent.Future;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import java.util.concurrent.TimeUnit;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
 
 /**
  * covers creating, reading and deleting of an item in dataStore
  */
 public class DataServiceIT extends AbstractIT {
-    protected DataBrokerService consumerDataService;
+    protected DataBroker dataBroker;
 
     /**
      *
@@ -41,51 +42,40 @@ public class DataServiceIT extends AbstractIT {
      */
     @Test
     public void test() throws Exception {
-        BindingAwareConsumer consumer = session -> consumerDataService = session.getSALService(DataBrokerService.class);
+        BindingAwareConsumer consumer = session -> dataBroker = session.getSALService(DataBroker.class);
 
         broker.registerConsumer(consumer);
 
-        assertNotNull(consumerDataService);
+        assertNotNull(dataBroker);
 
 
-        DataModificationTransaction transaction = consumerDataService.beginTransaction();
+        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
         assertNotNull(transaction);
 
         InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
-        DataObject node = consumerDataService.readOperationalData(node1);
-        assertNull(node);
+        Optional<UnorderedList> node = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1)
+                .checkedGet(5, TimeUnit.SECONDS);
+        assertFalse(node.isPresent());
         UnorderedList nodeData1 = createNode("0");
 
-        transaction.putOperationalData(node1, nodeData1);
-        Future<RpcResult<TransactionStatus>> commitResult = transaction.commit();
-        assertNotNull(commitResult);
-
-        RpcResult<TransactionStatus> result = commitResult.get();
-
-        assertNotNull(result);
-        assertNotNull(result.getResult());
-        assertEquals(TransactionStatus.COMMITED, result.getResult());
+        transaction.put(LogicalDatastoreType.OPERATIONAL, node1, nodeData1);
+        transaction.submit().checkedGet(5, TimeUnit.SECONDS);
 
-        UnorderedList readedData = (UnorderedList) consumerDataService.readOperationalData(node1);
-        assertNotNull(readedData);
-        assertEquals(nodeData1.getKey(), readedData.getKey());
+        Optional<UnorderedList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
+                node1).checkedGet(5, TimeUnit.SECONDS);
+        assertTrue(readedData.isPresent());
+        assertEquals(nodeData1.getKey(), readedData.get().getKey());
 
-        DataModificationTransaction transaction2 = consumerDataService.beginTransaction();
+        final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
         assertNotNull(transaction2);
 
-        transaction2.removeOperationalData(node1);
-
-        Future<RpcResult<TransactionStatus>> commitResult2 = transaction2.commit();
-        assertNotNull(commitResult2);
-
-        RpcResult<TransactionStatus> result2 = commitResult2.get();
+        transaction2.delete(LogicalDatastoreType.OPERATIONAL, node1);
 
-        assertNotNull(result2);
-        assertNotNull(result2.getResult());
-        assertEquals(TransactionStatus.COMMITED, result2.getResult());
+        transaction2.submit().checkedGet(5, TimeUnit.SECONDS);
 
-        DataObject readedData2 = consumerDataService.readOperationalData(node1);
-        assertNull(readedData2);
+        Optional<UnorderedList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
+                node1).checkedGet(5, TimeUnit.SECONDS);
+        assertFalse(readedData2.isPresent());
     }
 
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.