2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.dsbenchmark.txchain;
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;
27 public class TxchainBaRead extends DatastoreAbstractWriter {
28 private static final Logger LOG = LoggerFactory.getLogger(TxchainBaRead.class);
29 private final DataBroker bindingDataBroker;
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");
39 public void createList() {
40 LOG.debug("TxchainBaRead: reading data in the data store");
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);
51 public void executeList() {
52 final LogicalDatastoreType dsType = getDataStoreType();
54 try (ReadTransaction tx = bindingDataBroker.newReadOnlyTransaction()) {
55 for (long l = 0; l < outerListElem; l++) {
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);
62 Optional<OuterList> optionalDataObject = submitFuture.get();
63 if (optionalDataObject != null && optionalDataObject.isPresent()) {
64 OuterList outerList = optionalDataObject.orElseThrow();
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());
72 objectsArray[innerList.getName()] = innerList.getValue();
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);
85 } catch (final InterruptedException | ExecutionException e) {
86 LOG.warn("failed to ....", e);