Improve segmented journal actor metrics
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / txchain / TxchainBaRead.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.txchain;
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 TxchainBaRead extends DatastoreAbstractWriter {
28     private static final Logger LOG = LoggerFactory.getLogger(TxchainBaRead.class);
29     private final DataBroker bindingDataBroker;
30
31     public TxchainBaRead(final DataBroker bindingDataBroker, final int outerListElem, final int innerListElem,
32             final long writesPerTx, final DataStore dataStore) {
33         super(StartTestInput.Operation.DELETE, outerListElem, innerListElem, writesPerTx, dataStore);
34         this.bindingDataBroker = bindingDataBroker;
35         LOG.debug("Created TxchainBaRead");
36     }
37
38     @Override
39     public void createList() {
40         LOG.debug("TxchainBaRead: reading data in the data store");
41
42         // Dump the whole list into the data store in a single transaction
43         // with <outerListElem> PUTs on the transaction
44         TxchainBaWrite dd = new TxchainBaWrite(bindingDataBroker, StartTestInput.Operation.PUT, outerListElem,
45             innerListElem, outerListElem, dataStore);
46         dd.createList();
47         dd.executeList();
48     }
49
50     @Override
51     public void executeList() {
52         final LogicalDatastoreType dsType = getDataStoreType();
53
54         try (ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
55             for (long l = 0; l < outerListElem; l++) {
56
57                 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
58                         .child(OuterList.class, new OuterListKey((int) l));
59                 FluentFuture<Optional<OuterList>> submitFuture = tx.read(dsType, iid);
60
61                 try {
62                     Optional<OuterList> optionalDataObject = submitFuture.get();
63                     if (optionalDataObject != null && optionalDataObject.isPresent()) {
64                         OuterList outerList = optionalDataObject.orElseThrow();
65
66                         String[] objectsArray = new String[outerList.nonnullInnerList().size()];
67                         for (InnerList innerList : outerList.nonnullInnerList().values()) {
68                             if (objectsArray[innerList.getName()] != null) {
69                                 LOG.error("innerList: DUPLICATE name: {}, value: {}", innerList.getName(),
70                                     innerList.getValue());
71                             }
72                             objectsArray[innerList.getName()] = innerList.getValue();
73                         }
74                         for (int i = 0; i < outerList.nonnullInnerList().size(); i++) {
75                             String itemStr = objectsArray[i];
76                             if (!itemStr.contentEquals("Item-" + l + "-" + i)) {
77                                 LOG.error("innerList: name: {}, value: {}", i, itemStr);
78                                 break;
79                             }
80                         }
81                         txOk++;
82                     } else {
83                         txError++;
84                     }
85                 } catch (final InterruptedException | ExecutionException e) {
86                     LOG.warn("failed to ....", e);
87                     txError++;
88                 }
89             }
90         }
91     }
92 }