From: Tom Pantelis Date: Fri, 24 Apr 2015 15:57:37 +0000 (+0000) Subject: Merge "Fix NoSuchElementException thrown when transaction is empty" X-Git-Tag: release/lithium~214 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=9a6190b662c5f8de44df872b0ba7e8dd17f8da13;hp=b4713ee2aa4dc2d7a88fb3f972b9e69eeb185b14 Merge "Fix NoSuchElementException thrown when transaction is empty" --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBroker.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBroker.java index 06a43a6026..b48e5946da 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBroker.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBroker.java @@ -76,6 +76,10 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier()); + if(cohorts.isEmpty()){ + return Futures.immediateCheckedFuture(null); + } + final AsyncNotifyingSettableFuture clientSubmitFuture = new AsyncNotifyingSettableFuture(clientFutureCallbackExecutor); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBrokerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBrokerTest.java index 80e25a167d..f2536bfc2c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBrokerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ConcurrentDOMDataBrokerTest.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -31,6 +32,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -508,4 +510,23 @@ public class ConcurrentDOMDataBrokerTest { domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class)); } + @Test + public void testEmptyTransactionSubmitSucceeds() throws ExecutionException, InterruptedException { + DOMStore domStore = mock(DOMStore.class); + ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, + domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor); + + CheckedFuture submit1 = dataBroker.newWriteOnlyTransaction().submit(); + + assertNotNull(submit1); + + submit1.get(); + + CheckedFuture submit2 = dataBroker.newReadWriteTransaction().submit(); + + assertNotNull(submit2); + + submit2.get(); + } + }