2 * Copyright (c) 2015 Cisco Systems 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
9 package org.opendaylight.dsbenchmark.simpletx;
11 import java.util.List;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.dsbenchmark.BaListBuilder;
14 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput.DataStore;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class SimpletxBaWrite extends DatastoreAbstractWriter {
27 private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaWrite.class);
28 private final DataBroker dataBroker;
29 private List<OuterList> list;
31 public SimpletxBaWrite(final DataBroker dataBroker, final StartTestInput.Operation oper,
32 final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
33 super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
34 this.dataBroker = dataBroker;
35 LOG.debug("Created SimpletxBaWrite");
39 public void createList() {
40 list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem);
44 public void executeList() {
45 final LogicalDatastoreType dsType = getDataStoreType();
47 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
50 for (OuterList element : this.list) {
51 InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
52 .child(OuterList.class, element.key());
53 if (oper == StartTestInput.Operation.PUT) {
54 tx.put(dsType, iid, element);
56 tx.merge(dsType, iid, element);
61 if (writeCnt == writesPerTx) {
65 } catch (final InterruptedException | ExecutionException e) {
66 LOG.error("Transaction failed", e);
69 tx = dataBroker.newWriteOnlyTransaction();
78 } catch (final InterruptedException | ExecutionException e) {
79 LOG.error("Transaction failed", e);