BUG-7390: fix dsbenchmark 11/56111/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Apr 2017 17:56:30 +0000 (19:56 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 26 Apr 2017 19:27:36 +0000 (19:27 +0000)
Benchmark tests were not consistent as to what data store they were
using, leading to flooded logs in read case because of this and
irrelevant results in the delete case.

This patch corrects the mistakes, adding at least some consistency
and hope for relevant results.

Change-Id: I0528eb42cb38eacd5e0525c0a78ada111b1edb55
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaDelete.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaRead.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomDelete.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomRead.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxDomWrite.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaDelete.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaRead.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainBaWrite.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomDelete.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomRead.java
benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/txchain/TxchainDomWrite.java

index 4d67d4c..a96d0d5 100644 (file)
@@ -25,10 +25,10 @@ import org.slf4j.LoggerFactory;
 
 public class SimpletxBaDelete extends DatastoreAbstractWriter {
     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaDelete.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
 
-    public SimpletxBaDelete(DataBroker dataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public SimpletxBaDelete(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.dataBroker = dataBroker;
         LOG.info("Created SimpletxBaDelete");
@@ -51,13 +51,15 @@ public class SimpletxBaDelete extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
+        final LogicalDatastoreType dsType = getDataStoreType();
+
         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         long putCnt = 0;
 
         for (long l = 0; l < outerListElem; l++) {
             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
                                                         .child(OuterList.class, new OuterListKey((int)l));
-            tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+            tx.delete(dsType, iid);
             putCnt++;
             if (putCnt == writesPerTx) {
                 try {
index 8f8ecaf..269d2fa 100644 (file)
@@ -11,9 +11,8 @@ package org.opendaylight.dsbenchmark.simpletx;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
@@ -30,10 +29,10 @@ import org.slf4j.LoggerFactory;
 
 public class SimpletxBaRead extends DatastoreAbstractWriter {
     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaRead.class);
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
 
-    public SimpletxBaRead(DataBroker dataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public SimpletxBaRead(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.dataBroker = dataBroker;
         LOG.info("Created SimpletxBaRead");
@@ -56,46 +55,45 @@ public class SimpletxBaRead extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
-        ReadTransaction tx = dataBroker.newReadOnlyTransaction();
+        final LogicalDatastoreType dsType = getDataStoreType();
 
-        for (long l = 0; l < outerListElem; l++) {
+        try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+            for (long l = 0; l < outerListElem; l++) {
 
-            OuterList outerList;
-            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
-                    .child(OuterList.class, new OuterListKey((int)l));
-            Optional<OuterList> optionalDataObject;
-            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
-                    tx.read(LogicalDatastoreType.CONFIGURATION, iid);
-            try {
-                optionalDataObject = submitFuture.checkedGet();
-                if (optionalDataObject != null && optionalDataObject.isPresent()) {
-                    outerList = optionalDataObject.get();
+                InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
+                        .child(OuterList.class, new OuterListKey((int)l));
+                Optional<OuterList> optionalDataObject;
+                CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
+                try {
+                    optionalDataObject = submitFuture.checkedGet();
+                    if (optionalDataObject != null && optionalDataObject.isPresent()) {
+                        OuterList outerList = optionalDataObject.get();
 
-                    String[] objectsArray = new String[outerList.getInnerList().size()];
+                        String[] objectsArray = new String[outerList.getInnerList().size()];
 
-                    for (InnerList innerList : outerList.getInnerList()) {
-                        if (objectsArray[innerList.getName()] != null) {
-                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
+                        for (InnerList innerList : outerList.getInnerList()) {
+                            if (objectsArray[innerList.getName()] != null) {
+                                LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
                                     innerList.getValue());
+                            }
+                            objectsArray[innerList.getName()] = innerList.getValue();
                         }
-                        objectsArray[innerList.getName()] = innerList.getValue();
-                    }
-                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
-                        String itemStr = objectsArray[i];
-                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
-                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
-                            break;
+                        for (int i = 0; i < outerList.getInnerList().size(); i++) {
+                            String itemStr = objectsArray[i];
+                            if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
+                                LOG.error("innerList: name: {}, value: {}", i, itemStr);
+                                break;
+                            }
                         }
+                        txOk++;
+                    } else {
+                        txError++;
                     }
-                    txOk++;
-                } else {
+                } catch (ReadFailedException e) {
+                    LOG.warn("failed to ....", e);
                     txError++;
                 }
-            } catch (ReadFailedException e) {
-                LOG.warn("failed to ....", e);
-                txError++;
             }
         }
-
     }
 }
index 57dd810..046ac75 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.dsbenchmark.simpletx;
 
 import java.util.List;
-
 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;
@@ -29,8 +28,8 @@ public class SimpletxBaWrite extends DatastoreAbstractWriter {
     private final DataBroker dataBroker;
     private List<OuterList> list;
 
-    public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper,
-            int outerListElem, int innerListElem, long writesPerTx, DataStore dataStore) {
+    public SimpletxBaWrite(final DataBroker dataBroker, final StartTestInput.Operation oper,
+            final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
         this.dataBroker = dataBroker;
         LOG.info("Created SimpletxBaWrite");
@@ -43,9 +42,9 @@ public class SimpletxBaWrite extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
-        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
-        LogicalDatastoreType dsType = getDataStoreType();
+        final LogicalDatastoreType dsType = getDataStoreType();
 
+        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         long writeCnt = 0;
 
         for (OuterList element : this.list) {
@@ -68,7 +67,6 @@ public class SimpletxBaWrite extends DatastoreAbstractWriter {
                     txError++;
                 }
                 tx = dataBroker.newWriteOnlyTransaction();
-                dsType = getDataStoreType();
 
                 writeCnt = 0;
             }
index 2794fb4..565b2f8 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -26,8 +27,8 @@ public class SimpletxDomDelete extends DatastoreAbstractWriter {
     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomDelete.class);
     private final DOMDataBroker domDataBroker;
 
-    public SimpletxDomDelete(DOMDataBroker domDataBroker, int outerListElem,
-            int innerListElem, long writesPerTx, DataStore dataStore) {
+    public SimpletxDomDelete(final DOMDataBroker domDataBroker, final int outerListElem,
+            final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created simpleTxDomDelete");
@@ -50,19 +51,19 @@ public class SimpletxDomDelete extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
-        long writeCnt = 0;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
+
 
-        org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
+        long writeCnt = 0;
 
         for (int l = 0; l < outerListElem; l++) {
-            YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
-                                         .node(TestExec.QNAME)
-                                         .node(OuterList.QNAME)
-                                         .nodeWithKey(OuterList.QNAME, olId, l)
-                                         .build();
+            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
 
-            tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
+            tx.delete(dsType, yid);
             writeCnt++;
             if (writeCnt == writesPerTx) {
                 try {
index 9624343..0edccbf 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.dsbenchmark.simpletx;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-
 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;
@@ -23,6 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,8 +32,8 @@ public class SimpletxDomRead extends DatastoreAbstractWriter {
     private static final Logger LOG = LoggerFactory.getLogger(SimpletxDomRead.class);
     private final DOMDataBroker domDataBroker;
 
-    public SimpletxDomRead(DOMDataBroker domDataBroker, int outerListElem,
-                           int innerListElem, long writesPerTx, DataStore dataStore) {
+    public SimpletxDomRead(final DOMDataBroker domDataBroker, final int outerListElem,
+                           final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created simpleTxDomRead");
@@ -57,35 +57,30 @@ public class SimpletxDomRead extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
-        org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
-        DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction();
-
-        for (long l = 0; l < outerListElem; l++) {
-            NormalizedNode<?,?> ret = null;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
 
-            YangInstanceIdentifier yid = YangInstanceIdentifier.builder()
-                    .node(TestExec.QNAME)
-                    .node(OuterList.QNAME)
-                    .nodeWithKey(OuterList.QNAME, olId, l)
-                    .build();
-            Optional<NormalizedNode<?,?>> optionalDataObject;
-            CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture =
-                    tx.read(LogicalDatastoreType.CONFIGURATION, yid);
-            try {
-                optionalDataObject = submitFuture.checkedGet();
-                if (optionalDataObject != null && optionalDataObject.isPresent()) {
-                    ret = optionalDataObject.get();
-                    LOG.info("/n" + String.valueOf(ret));
-                    txOk++;
-                } else {
+        try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
+            for (int l = 0; l < outerListElem; l++) {
+                YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
+                CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
+                try {
+                    Optional<NormalizedNode<?,?>> optionalDataObject = submitFuture.checkedGet();
+                    if (optionalDataObject != null && optionalDataObject.isPresent()) {
+                        NormalizedNode<?, ?> ret = optionalDataObject.get();
+                        LOG.info("/n" + String.valueOf(ret));
+                        txOk++;
+                    } else {
+                        txError++;
+                        LOG.warn("optionalDataObject is either null or .isPresent is false");
+                    }
+                } catch (ReadFailedException e) {
+                    LOG.warn("failed to ....", e);
                     txError++;
-                    LOG.warn("optionalDataObject is either null or .isPresent is false");
                 }
-            } catch (ReadFailedException e) {
-                LOG.warn("failed to ....", e);
-                txError++;
             }
         }
     }
-
 }
index 572f4f7..b944680 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.dsbenchmark.simpletx;
 
 import java.util.List;
-
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
@@ -31,8 +30,8 @@ public class SimpletxDomWrite extends DatastoreAbstractWriter {
     private final DOMDataBroker domDataBroker;
     private List<MapEntryNode> list;
 
-    public SimpletxDomWrite(DOMDataBroker domDataBroker, StartTestInput.Operation oper,
-                                    int outerListElem, int innerListElem, long putsPerTx, DataStore dataStore ) {
+    public SimpletxDomWrite(final DOMDataBroker domDataBroker, final StartTestInput.Operation oper,
+                                    final int outerListElem, final int innerListElem, final long putsPerTx, final DataStore dataStore ) {
         super(oper, outerListElem, innerListElem, putsPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created SimpletxDomWrite");
@@ -45,12 +44,13 @@ public class SimpletxDomWrite extends DatastoreAbstractWriter {
 
     @Override
     public void executeList() {
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
+
         DOMDataWriteTransaction tx = domDataBroker.newWriteOnlyTransaction();
-        LogicalDatastoreType dsType = getDataStoreType();
         long writeCnt = 0;
 
-        YangInstanceIdentifier pid =
-                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
         for (MapEntryNode element : this.list) {
             YangInstanceIdentifier yid =
                     pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
@@ -72,7 +72,6 @@ public class SimpletxDomWrite extends DatastoreAbstractWriter {
                     txError++;
                 }
                 tx = domDataBroker.newWriteOnlyTransaction();
-                dsType = getDataStoreType();
                 writeCnt = 0;
             }
         }
index b4f6769..dc45d4c 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.dsbenchmark.txchain;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -31,10 +30,10 @@ import org.slf4j.LoggerFactory;
 
 public class TxchainBaDelete extends DatastoreAbstractWriter implements TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(TxchainBaDelete.class);
-    private DataBroker bindingDataBroker;
+    private final DataBroker bindingDataBroker;
 
-    public TxchainBaDelete(DataBroker bindingDataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public TxchainBaDelete(final DataBroker bindingDataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.bindingDataBroker = bindingDataBroker;
         LOG.info("Created TxchainBaDelete");
@@ -58,16 +57,17 @@ public class TxchainBaDelete extends DatastoreAbstractWriter implements Transact
 
     @Override
     public void executeList() {
-        int txSubmitted = 0;
-        int writeCnt = 0;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
 
-        BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
         WriteTransaction tx = chain.newWriteOnlyTransaction();
+        int txSubmitted = 0;
+        int writeCnt = 0;
 
-        for (long l = 0; l < outerListElem; l++) {
+        for (int l = 0; l < outerListElem; l++) {
             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
-                                                    .child(OuterList.class, new OuterListKey((int)l));
-            tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+                                                    .child(OuterList.class, new OuterListKey(l));
+            tx.delete(dsType, iid);
 
             writeCnt++;
 
@@ -109,14 +109,14 @@ public class TxchainBaDelete extends DatastoreAbstractWriter implements Transact
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-            AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+            final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("TxchainBaDelete closed successfully, chain {}", chain);
     }
 
index cb57f37..19a0bfe 100644 (file)
@@ -10,10 +10,13 @@ package org.opendaylight.dsbenchmark.txchain;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.*;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+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.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
@@ -27,10 +30,10 @@ import org.slf4j.LoggerFactory;
 
 public class TxchainBaRead extends DatastoreAbstractWriter implements TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(TxchainBaRead.class);
-    private DataBroker bindingDataBroker;
+    private final DataBroker bindingDataBroker;
 
-    public TxchainBaRead(DataBroker bindingDataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public TxchainBaRead(final DataBroker bindingDataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.bindingDataBroker = bindingDataBroker;
         LOG.info("Created TxchainBaRead");
@@ -54,57 +57,57 @@ public class TxchainBaRead extends DatastoreAbstractWriter implements Transactio
 
     @Override
     public void executeList() {
-        ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction();
+        final LogicalDatastoreType dsType = getDataStoreType();
 
-        for (long l = 0; l < outerListElem; l++) {
+        try (ReadOnlyTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
+            for (long l = 0; l < outerListElem; l++) {
 
-            OuterList outerList;
-            InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
-                    .child(OuterList.class, new OuterListKey((int) l));
-            Optional<OuterList> optionalDataObject;
-            CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
-                    tx.read(LogicalDatastoreType.CONFIGURATION, iid);
+                InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
+                        .child(OuterList.class, new OuterListKey((int) l));
+                CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture =
+                        tx.read(dsType, iid);
 
-            try {
-                optionalDataObject = submitFuture.checkedGet();
-                if (optionalDataObject != null && optionalDataObject.isPresent()) {
-                    outerList = optionalDataObject.get();
+                try {
+                    Optional<OuterList> optionalDataObject = submitFuture.checkedGet();
+                    if (optionalDataObject != null && optionalDataObject.isPresent()) {
+                        OuterList outerList = optionalDataObject.get();
 
-                    String[] objectsArray = new String[outerList.getInnerList().size()];
-                    for (InnerList innerList : outerList.getInnerList()) {
-                        if (objectsArray[innerList.getName()] != null) {
-                            LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
+                        String[] objectsArray = new String[outerList.getInnerList().size()];
+                        for (InnerList innerList : outerList.getInnerList()) {
+                            if (objectsArray[innerList.getName()] != null) {
+                                LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
                                     innerList.getValue());
+                            }
+                            objectsArray[innerList.getName()] = innerList.getValue();
                         }
-                        objectsArray[innerList.getName()] = innerList.getValue();
-                    }
-                    for (int i = 0; i < outerList.getInnerList().size(); i++) {
-                        String itemStr = objectsArray[i];
-                        if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
-                            LOG.error("innerList: name: {}, value: {}", i, itemStr);
-                            break;
+                        for (int i = 0; i < outerList.getInnerList().size(); i++) {
+                            String itemStr = objectsArray[i];
+                            if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
+                                LOG.error("innerList: name: {}, value: {}", i, itemStr);
+                                break;
+                            }
                         }
+                        txOk++;
+                    } else {
+                        txError++;
                     }
-                    txOk++;
-                } else {
+                } catch (ReadFailedException e) {
+                    LOG.warn("failed to ....", e);
                     txError++;
                 }
-            } catch (ReadFailedException e) {
-                LOG.warn("failed to ....", e);
-                txError++;
             }
         }
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-                                         AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+                                         final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in TxchainBaDelete, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("TxchainBaDelete closed successfully, chain {}", chain);
     }
 
index 962c950..bf8c0b8 100644 (file)
@@ -10,9 +10,7 @@ package org.opendaylight.dsbenchmark.txchain;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-
 import java.util.List;
-
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -23,9 +21,9 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListen
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.dsbenchmark.BaListBuilder;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.Operation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -37,8 +35,8 @@ public class TxchainBaWrite extends DatastoreAbstractWriter implements Transacti
     private final DataBroker bindingDataBroker;
     private List<OuterList> list;
 
-    public TxchainBaWrite(DataBroker bindingDataBroker, Operation oper,
-                          int outerListElem, int innerListElem, long writesPerTx, DataStore dataStore) {
+    public TxchainBaWrite(final DataBroker bindingDataBroker, final Operation oper,
+                          final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
         this.bindingDataBroker = bindingDataBroker;
         LOG.info("Created TxchainBaWrite");
@@ -51,12 +49,12 @@ public class TxchainBaWrite extends DatastoreAbstractWriter implements Transacti
 
     @Override
     public void executeList() {
-        int txSubmitted = 0;
-        int writeCnt = 0;
+        final BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
+        final LogicalDatastoreType dsType = getDataStoreType();
 
-        BindingTransactionChain chain = bindingDataBroker.createTransactionChain(this);
         WriteTransaction tx = chain.newWriteOnlyTransaction();
-        LogicalDatastoreType dsType = getDataStoreType();
+        int txSubmitted = 0;
+        int writeCnt = 0;
 
         for (OuterList element : this.list) {
             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
@@ -85,7 +83,6 @@ public class TxchainBaWrite extends DatastoreAbstractWriter implements Transacti
                     }
                 });
                 tx = chain.newWriteOnlyTransaction();
-                dsType = getDataStoreType();
                 writeCnt = 0;
             }
         }
@@ -110,14 +107,14 @@ public class TxchainBaWrite extends DatastoreAbstractWriter implements Transacti
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-            AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+            final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in DatastoreBaAbstractWrite, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("DatastoreBaAbstractWrite closed successfully, chain {}", chain);
     }
 
index 63e9934..2465548 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.dsbenchmark.txchain;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
@@ -27,15 +29,12 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-
 public class TxchainDomDelete extends DatastoreAbstractWriter implements TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(TxchainBaWrite.class);
     private final DOMDataBroker domDataBroker;
 
-    public TxchainDomDelete(DOMDataBroker domDataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public TxchainDomDelete(final DOMDataBroker domDataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created TxchainDomDelete");
@@ -59,18 +58,19 @@ public class TxchainDomDelete extends DatastoreAbstractWriter implements Transac
 
     @Override
     public void executeList() {
-        int txSubmitted = 0;
-        int writeCnt = 0;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
+        final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
 
-        org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
-        DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
         DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
+        int txSubmitted = 0;
+        int writeCnt = 0;
 
-        YangInstanceIdentifier pid =
-                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
         for (int l = 0; l < outerListElem; l++) {
             YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
-            tx.delete(LogicalDatastoreType.CONFIGURATION, yid);
+            tx.delete(dsType, yid);
 
             writeCnt++;
 
@@ -113,14 +113,14 @@ public class TxchainDomDelete extends DatastoreAbstractWriter implements Transac
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-            AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+            final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in TxchainDomDelete, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("TxchainDomDelete closed successfully, chain {}", chain);
     }
 }
index 6a910f3..793ff7e 100644 (file)
@@ -10,8 +10,11 @@ package org.opendaylight.dsbenchmark.txchain;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
-
-import org.opendaylight.controller.md.sal.common.api.data.*;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+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.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
@@ -30,8 +33,8 @@ public class TxchainDomRead extends DatastoreAbstractWriter implements Transacti
     private static final Logger LOG = LoggerFactory.getLogger(TxchainDomRead.class);
     private final DOMDataBroker domDataBroker;
 
-    public TxchainDomRead(DOMDataBroker domDataBroker, int outerListElem, int innerListElem,
-            long writesPerTx, DataStore dataStore) {
+    public TxchainDomRead(final DOMDataBroker domDataBroker, final int outerListElem, final int innerListElem,
+            final long writesPerTx, final DataStore dataStore) {
         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created TxchainDomDelete");
@@ -55,40 +58,38 @@ public class TxchainDomRead extends DatastoreAbstractWriter implements Transacti
 
     @Override
     public void executeList() {
-
-        org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
-        DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction();
-
-        YangInstanceIdentifier pid =
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
+        final YangInstanceIdentifier pid =
                 YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
-        for (int l = 0; l < outerListElem; l++) {
-            YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
-            Optional<NormalizedNode<?,?>> optionalDataObject;
-            CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture =
-                    tx.read(LogicalDatastoreType.CONFIGURATION, yid);
-            try {
-                optionalDataObject = submitFuture.checkedGet();
-                if (optionalDataObject != null && optionalDataObject.isPresent()) {
-                    txOk++;
+
+        try (DOMDataReadOnlyTransaction tx = domDataBroker.newReadOnlyTransaction()) {
+            for (int l = 0; l < outerListElem; l++) {
+                YangInstanceIdentifier yid = pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, olId, l));
+                Optional<NormalizedNode<?,?>> optionalDataObject;
+                CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> submitFuture = tx.read(dsType, yid);
+                try {
+                    optionalDataObject = submitFuture.checkedGet();
+                    if (optionalDataObject != null && optionalDataObject.isPresent()) {
+                        txOk++;
+                    }
+                } catch (ReadFailedException e) {
+                    LOG.warn("failed to ....", e);
+                    txError++;
                 }
-            } catch (ReadFailedException e) {
-                LOG.warn("failed to ....", e);
-                txError++;
             }
         }
-
-
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-                                         AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+                                         final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in TxchainDomDelete, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("TxchainDomDelete closed successfully, chain {}", chain);
     }
 }
index f422d43..4811616 100644 (file)
@@ -8,8 +8,9 @@
 
 package org.opendaylight.dsbenchmark.txchain;
 
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
 import java.util.List;
-
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
@@ -30,16 +31,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-
 public class TxchainDomWrite extends DatastoreAbstractWriter implements TransactionChainListener {
     private static final Logger LOG = LoggerFactory.getLogger(TxchainDomWrite.class);
     private final DOMDataBroker domDataBroker;
     private List<MapEntryNode> list;
 
-    public TxchainDomWrite(DOMDataBroker domDataBroker, StartTestInput.Operation oper, int outerListElem,
-            int innerListElem, long writesPerTx, DataStore dataStore) {
+    public TxchainDomWrite(final DOMDataBroker domDataBroker, final StartTestInput.Operation oper, final int outerListElem,
+            final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
         this.domDataBroker = domDataBroker;
         LOG.info("Created TxchainDomWrite");
@@ -52,15 +50,15 @@ public class TxchainDomWrite extends DatastoreAbstractWriter implements Transact
 
     @Override
     public void executeList() {
-        int txSubmitted = 0;
-        int writeCnt = 0;
+        final LogicalDatastoreType dsType = getDataStoreType();
+        final YangInstanceIdentifier pid =
+                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
+        final DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
 
-        DOMTransactionChain chain = domDataBroker.createTransactionChain(this);
-        LogicalDatastoreType dsType = getDataStoreType();
         DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
+        int txSubmitted = 0;
+        int writeCnt = 0;
 
-        YangInstanceIdentifier pid =
-                YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
         for (MapEntryNode element : this.list) {
             YangInstanceIdentifier yid =
                     pid.node(new NodeIdentifierWithPredicates(OuterList.QNAME, element.getIdentifier().getKeyValues()));
@@ -89,7 +87,6 @@ public class TxchainDomWrite extends DatastoreAbstractWriter implements Transact
                     }
                 });
                 tx = chain.newWriteOnlyTransaction();
-                dsType = getDataStoreType();
                 writeCnt = 0;
             }
         }
@@ -116,14 +113,14 @@ public class TxchainDomWrite extends DatastoreAbstractWriter implements Transact
     }
 
     @Override
-    public void onTransactionChainFailed(TransactionChain<?, ?> chain,
-            AsyncTransaction<?, ?> transaction, Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+            final AsyncTransaction<?, ?> transaction, final Throwable cause) {
         LOG.error("Broken chain {} in TxchainDomWrite, transaction {}, cause {}",
                 chain, transaction.getIdentifier(), cause);
     }
 
     @Override
-    public void onTransactionChainSuccessful(TransactionChain<?, ?> chain) {
+    public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
         LOG.info("Chain {} closed successfully", chain);
     }
 

©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.