Fixup checkstyle
[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 package org.opendaylight.dsbenchmark.simpletx;
9
10 import com.google.common.util.concurrent.FluentFuture;
11 import java.util.Optional;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.ReadTransaction;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterListKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.outer.list.InnerList;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class SimpletxBaRead extends DatastoreAbstractWriter {
28     private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaRead.class);
29     private final DataBroker dataBroker;
30
31     public SimpletxBaRead(final DataBroker dataBroker, final int outerListElem, final int innerListElem,
32             final long writesPerTx, final DataStore dataStore) {
33         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
34         this.dataBroker = dataBroker;
35         LOG.debug("Created SimpletxBaRead");
36     }
37
38     @Override
39     public void createList() {
40         LOG.debug("DatastoreRead: creating data in the data store");
41         // Dump the whole list into the data store in a single transaction
42         // with <outerListElem> PUTs on the transaction
43         SimpletxBaWrite dd = new SimpletxBaWrite(dataBroker,
44                 StartTestInput.Operation.PUT,
45                 outerListElem,
46                 innerListElem,
47                 outerListElem,
48                 dataStore);
49         dd.createList();
50         dd.executeList();
51     }
52
53     @Override
54     public void executeList() {
55         final LogicalDatastoreType dsType = getDataStoreType();
56
57         try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
58             for (long l = 0; l < outerListElem; l++) {
59
60                 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
61                         .child(OuterList.class, new OuterListKey((int)l));
62                 Optional<OuterList> optionalDataObject;
63                 FluentFuture<Optional<OuterList>> submitFuture = tx.read(dsType, iid);
64                 try {
65                     optionalDataObject = submitFuture.get();
66                     if (optionalDataObject != null && optionalDataObject.isPresent()) {
67                         OuterList outerList = optionalDataObject.get();
68
69                         String[] objectsArray = new String[outerList.getInnerList().size()];
70
71                         for (InnerList innerList : outerList.getInnerList().values()) {
72                             if (objectsArray[innerList.getName()] != null) {
73                                 LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
74                                     innerList.getValue());
75                             }
76                             objectsArray[innerList.getName()] = innerList.getValue();
77                         }
78                         for (int i = 0; i < outerList.getInnerList().size(); i++) {
79                             String itemStr = objectsArray[i];
80                             if (!itemStr.contentEquals("Item-" + String.valueOf(l) + "-" + String.valueOf(i))) {
81                                 LOG.error("innerList: name: {}, value: {}", i, itemStr);
82                                 break;
83                             }
84                         }
85                         txOk++;
86                     } else {
87                         txError++;
88                     }
89                 } catch (final InterruptedException | ExecutionException e) {
90                     LOG.warn("failed to ....", e);
91                     txError++;
92                 }
93             }
94         }
95     }
96 }