X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=benchmark%2Fdsbenchmark%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fdsbenchmark%2Fsimpletx%2FSimpletxBaWrite.java;fp=benchmark%2Fdsbenchmark%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fdsbenchmark%2Fsimpletx%2FSimpletxBaWrite.java;h=f811c4b6b63160e41d7065c50d3743620f914728;hb=bc740310bca93dcefcf546f7c4a627d8153b3739;hp=0000000000000000000000000000000000000000;hpb=a7517a9b9c40dee08cff8be2febaa2d369012e48;p=controller.git diff --git a/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java new file mode 100644 index 0000000000..f811c4b6b6 --- /dev/null +++ b/benchmark/dsbenchmark/src/main/java/org/opendaylight/dsbenchmark/simpletx/SimpletxBaWrite.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Cisco Systems and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.dsbenchmark.simpletx; + +import java.util.List; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.dsbenchmark.BaListBuilder; +import org.opendaylight.dsbenchmark.DatastoreAbstractWriter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.test.exec.OuterList; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpletxBaWrite extends DatastoreAbstractWriter { + private static final Logger LOG = LoggerFactory.getLogger(SimpletxBaWrite.class); + private final DataBroker dataBroker; + private List list; + + public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper, + int outerListElem, int innerListElem, long writesPerTx) { + super(oper, outerListElem, innerListElem, writesPerTx); + this.dataBroker = dataBroker; + LOG.info("Created SimpletxBaWrite"); + } + + @Override + public void createList() { + list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem); + } + + @Override + public void executeList() { + WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + long writeCnt = 0; + + for (OuterList element : this.list) { + InstanceIdentifier iid = InstanceIdentifier.create(TestExec.class) + .child(OuterList.class, element.getKey()); + if (oper == StartTestInput.Operation.PUT) { + tx.put(LogicalDatastoreType.CONFIGURATION, iid, element); + } else { + tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element); + } + + writeCnt++; + + if (writeCnt == writesPerTx) { + try { + tx.submit().checkedGet(); + txOk++; + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + txError++; + } + tx = dataBroker.newWriteOnlyTransaction(); + writeCnt = 0; + } + } + + if (writeCnt != 0) { + try { + tx.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + LOG.error("Transaction failed: {}", e.toString()); + } + } + } + +}