Convert mdsal submit() calls to commit() 71/72171/4
authorTom Pantelis <tompantelis@gmail.com>
Tue, 22 May 2018 16:29:28 +0000 (12:29 -0400)
committerRobert Varga <nite@hq.sk>
Fri, 1 Jun 2018 12:39:30 +0000 (12:39 +0000)
Change-Id: I097c9604272a5be350ba7949091e5f3f20b56f26
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBrokerWriteTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/AbstractDOMBrokerWriteTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java

index c109165..21d391c 100644 (file)
@@ -10,10 +10,8 @@ package org.opendaylight.controller.cluster.databroker;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.MoreExecutors;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -22,8 +20,6 @@ import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
@@ -128,12 +124,6 @@ public abstract class AbstractDOMBrokerWriteTransaction<T extends DOMStoreWriteT
         return future.cancel(false);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return MappingCheckedFuture.create(commit().transform(ignored -> null,
-                MoreExecutors.directExecutor()), TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
-    }
-
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
     public FluentFuture<? extends CommitInfo> commit() {
index 1ad1b34..358dbf0 100644 (file)
@@ -10,14 +10,16 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
 
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.concurrent.ExecutionException;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
@@ -54,37 +56,37 @@ public class AbstractDOMBrokerWriteTransactionTest {
     }
 
     @Test
-    public void readyRuntimeExceptionAndCancel() {
+    public void readyRuntimeExceptionAndCancel() throws InterruptedException {
         RuntimeException thrown = new RuntimeException();
         doThrow(thrown).when(domStoreWriteTransaction).ready();
         AbstractDOMBrokerWriteTransactionTestImpl abstractDOMBrokerWriteTransactionTestImpl =
                 new AbstractDOMBrokerWriteTransactionTestImpl();
 
-        CheckedFuture<Void, TransactionCommitFailedException> submitFuture =
-                abstractDOMBrokerWriteTransactionTestImpl.submit();
+        FluentFuture<? extends CommitInfo> submitFuture = abstractDOMBrokerWriteTransactionTestImpl.commit();
         try {
-            submitFuture.checkedGet();
+            submitFuture.get();
             Assert.fail("TransactionCommitFailedException expected");
-        } catch (TransactionCommitFailedException e) {
-            assertTrue(e.getCause() == thrown);
+        } catch (ExecutionException e) {
+            assertTrue(e.getCause() instanceof TransactionCommitFailedException);
+            assertTrue(e.getCause().getCause() == thrown);
             abstractDOMBrokerWriteTransactionTestImpl.cancel();
         }
     }
 
     @Test
-    public void submitRuntimeExceptionAndCancel() {
+    public void submitRuntimeExceptionAndCancel() throws InterruptedException {
         RuntimeException thrown = new RuntimeException();
         doThrow(thrown).when(abstractDOMTransactionFactory).commit(any(), any());
         AbstractDOMBrokerWriteTransactionTestImpl abstractDOMBrokerWriteTransactionTestImpl
                 = new AbstractDOMBrokerWriteTransactionTestImpl();
 
-        CheckedFuture<Void, TransactionCommitFailedException> submitFuture =
-                abstractDOMBrokerWriteTransactionTestImpl.submit();
+        FluentFuture<? extends CommitInfo> submitFuture = abstractDOMBrokerWriteTransactionTestImpl.commit();
         try {
-            submitFuture.checkedGet();
+            submitFuture.get();
             Assert.fail("TransactionCommitFailedException expected");
-        } catch (TransactionCommitFailedException e) {
-            assertTrue(e.getCause() == thrown);
+        } catch (ExecutionException e) {
+            assertTrue(e.getCause() instanceof TransactionCommitFailedException);
+            assertTrue(e.getCause().getCause() == thrown);
             abstractDOMBrokerWriteTransactionTestImpl.cancel();
         }
     }
index acf08eb..bf551bb 100644 (file)
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
 
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -459,7 +458,7 @@ public class ConcurrentDOMDataBrokerTest {
 
             domDataReadWriteTransaction.delete(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
 
-            domDataReadWriteTransaction.submit();
+            domDataReadWriteTransaction.commit();
 
             assertTrue(latch.await(10, TimeUnit.SECONDS));
 
@@ -509,7 +508,7 @@ public class ConcurrentDOMDataBrokerTest {
             domDataReadWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY,
                     mock(NormalizedNode.class));
 
-            domDataReadWriteTransaction.submit();
+            domDataReadWriteTransaction.commit();
 
             assertTrue(latch.await(10, TimeUnit.SECONDS));
 
@@ -563,15 +562,13 @@ public class ConcurrentDOMDataBrokerTest {
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
                 futureExecutor)) {
 
-            CheckedFuture<Void, TransactionCommitFailedException> submit1 =
-                    dataBroker.newWriteOnlyTransaction().submit();
+            FluentFuture<? extends CommitInfo> submit1 = dataBroker.newWriteOnlyTransaction().commit();
 
             assertNotNull(submit1);
 
             submit1.get();
 
-            CheckedFuture<Void, TransactionCommitFailedException> submit2 =
-                    dataBroker.newReadWriteTransaction().submit();
+            FluentFuture<? extends CommitInfo> submit2 = dataBroker.newReadWriteTransaction().commit();
 
             assertNotNull(submit2);
 
index 3d59ebb..482021a 100644 (file)
@@ -71,7 +71,6 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.mdsal.common.api.TransactionChainClosedException;
 import org.opendaylight.mdsal.common.api.TransactionChainListener;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
@@ -931,12 +930,12 @@ public class DistributedDataStoreIntegrationTest {
                     final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
                     DOMTransactionChain txChain = broker.createTransactionChain(listener);
 
-                    final List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
+                    final List<ListenableFuture<?>> futures = new ArrayList<>();
 
                     final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                     writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
                     writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                    futures.add(writeTx.submit());
+                    futures.add(writeTx.commit());
 
                     int numCars = 100;
                     for (int i = 0; i < numCars; i++) {
@@ -945,11 +944,11 @@ public class DistributedDataStoreIntegrationTest {
                         rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
                                 CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
 
-                        futures.add(rwTx.submit());
+                        futures.add(rwTx.commit());
                     }
 
-                    for (final CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
-                        f.checkedGet();
+                    for (final ListenableFuture<?> f : futures) {
+                        f.get(5, TimeUnit.SECONDS);
                     }
 
                     final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
@@ -1102,9 +1101,9 @@ public class DistributedDataStoreIntegrationTest {
                     writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
 
                     try {
-                        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+                        writeTx.commit().get(5, TimeUnit.SECONDS);
                         fail("Expected TransactionCommitFailedException");
-                    } catch (final TransactionCommitFailedException e) {
+                    } catch (final ExecutionException e) {
                         // Expected
                     }
 
@@ -1148,9 +1147,9 @@ public class DistributedDataStoreIntegrationTest {
                     // succeeds b/c deep validation is not
                     // done for put for performance reasons.
                     try {
-                        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+                        writeTx.commit().get(5, TimeUnit.SECONDS);
                         fail("Expected TransactionCommitFailedException");
-                    } catch (final TransactionCommitFailedException e) {
+                    } catch (final ExecutionException e) {
                         // Expected
                     }
 
index 9b2edfa..aaab6b1 100644 (file)
@@ -82,7 +82,6 @@ import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelpe
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.TransactionChainListener;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
@@ -525,9 +524,9 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
 
         try {
-            writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+            writeTx.commit().get(5, TimeUnit.SECONDS);
             fail("Expected TransactionCommitFailedException");
-        } catch (final TransactionCommitFailedException e) {
+        } catch (final ExecutionException e) {
             // Expected
         }
 
@@ -562,9 +561,9 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
 
         try {
-            writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+            writeTx.commit().get(5, TimeUnit.SECONDS);
             fail("Expected TransactionCommitFailedException");
-        } catch (final TransactionCommitFailedException e) {
+        } catch (final ExecutionException e) {
             // Expected
         }
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.