BUG-7390: fix dsbenchmark
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxBaRead.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.dsbenchmark.simpletx;
10
11
12 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.CheckedFuture;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30 public class SimpletxBaRead extends DatastoreAbstractWriter {
31     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaRead.class);
32     private final DataBroker dataBroker;
33
34     public SimpletxBaRead(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
35             final long writesPerTx, final DataStore dataStore) {
36         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
37         this.dataBroker = dataBroker;
38         LOG.info("Created SimpletxBaRead");
39     }
40
41     @Override
42     public void createList() {
43         LOG.info("DatastoreRead: creating data in the data store");
44         // Dump the whole list into the data store in a single transaction
45         // with <outerListElem> PUTs on the transaction
46         SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker,
47                 StartTestInput.Operation.PUT,
48                 outerListElem,
49                 innerListElem,
50                 outerListElem,
51                 dataStore);
52         dd.createList();
53         dd.executeList();
54     }
55
56     @Override
57     public void executeList() {
58         final LogicalDatastoreType dsType = getDataStoreType();
59
60         try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
61             for (long l = 0; l < outerListElem; l++) {
62
63                 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
64                         .child(OuterList.class, new OuterListKey((int)l));
65                 Optional<OuterList> optionalDataObject;
66                 CheckedFuture<Optional<OuterList>, ReadFailedException> submitFuture = tx.read(dsType, iid);
67                 try {
68                     optionalDataObject = submitFuture.checkedGet();
69                     if (optionalDataObject != null && optionalDataObject.isPresent()) {
70                         OuterList outerList = optionalDataObject.get();
71
72                         String[] objectsArray = new String[outerList.getInnerList().size()];
73
74                         for (InnerList innerList : outerList.getInnerList()) {
75                             if (objectsArray[innerList.getName()] != null) {
76                                 LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
77                                     innerList.getValue());
78                             }
79                             objectsArray[innerList.getName()] = innerList.getValue();
80                         }
81                         for (int i = 0; i < outerList.getInnerList().size(); i++) {
82                             String itemStr = objectsArray[i];
83                             if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
84                                 LOG.error("innerList: name: {}, value: {}", i, itemStr);
85                                 break;
86                             }
87                         }
88                         txOk++;
89                     } else {
90                         txError++;
91                     }
92                 } catch (ReadFailedException e) {
93                     LOG.warn("failed to ....", e);
94                     txError++;
95                 }
96             }
97         }
98     }
99 }

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