From 20d1f40ffea1fa0782ea579533d29177832591a4 Mon Sep 17 00:00:00 2001 From: Moiz Raja Date: Fri, 24 Apr 2015 08:02:33 -0700 Subject: [PATCH] Fix NoSuchElementException thrown when transaction is empty Change-Id: I5d2c26a1ff3d8f5b8ace893b7206da2d23bf637c Signed-off-by: Moiz Raja --- .../datastore/ConcurrentDOMDataBroker.java | 4 ++++ .../ConcurrentDOMDataBrokerTest.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) 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(); + } + } -- 2.36.6