Default AsyncWriteTransaction.submit() 47/71547/6
authorTom Pantelis <tompantelis@gmail.com>
Mon, 30 Apr 2018 01:22:36 +0000 (21:22 -0400)
committerRobert Varga <nite@hq.sk>
Tue, 15 May 2018 17:37:49 +0000 (17:37 +0000)
Now that all downstream implementations implement commit(), the deprecated
submit() method can be defaulted instead instead of commit().

Change-Id: Idd684bc3fdc7d4f048257154988ef1f7c7811e97
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
19 files changed:
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/AbstractTracingWriteTransaction.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingReadWriteTransaction.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingWriteTransaction.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingReadWriteTransaction.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/ForwardingWriteTransaction.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMWriteTransactionAdapter.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/WriteTransactionTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/CrossBrokerMountPointTest.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/compat/LegacyDOMDataBrokerAdapter.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/compat/LegacyDOMDataBrokerAdapterTest.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMForwardedWriteTransaction.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransaction.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/PingPongTransactionChain.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/legacy/sharded/adapter/ShardedDOMDataBrokerDelegatingReadWriteTransaction.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/legacy/sharded/adapter/ShardedDOMDataBrokerDelegatingWriteTransaction.java
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/ForwardingDOMDataReadWriteTransaction.java
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/ForwardingDOMDataWriteTransaction.java

index f7dd4d7..3d98b79 100644 (file)
@@ -8,14 +8,12 @@
 package org.opendaylight.controller.md.sal.trace.dom.impl;
 
 import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -96,12 +94,6 @@ abstract class AbstractTracingWriteTransaction implements DOMDataWriteTransactio
         delegate.delete(store, yiid);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        logOps();
-        return delegate.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         logOps();
index 6fbe58b..82c1a3b 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.FluentFuture;
 import java.util.Objects;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTracked;
 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedRegistry;
@@ -47,12 +46,6 @@ class TracingReadWriteTransaction
         return delegate.exists(store, yiid);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        closeTracker.removeFromTrackedRegistry();
-        return super.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         closeTracker.removeFromTrackedRegistry();
index 4d33a46..5fe313f 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.controller.md.sal.trace.dom.impl;
 
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTracked;
 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedRegistry;
@@ -27,12 +25,6 @@ class TracingWriteTransaction extends AbstractTracingWriteTransaction
         this.closeTracker = new CloseTrackedTrait<>(writeTransactionsRegistry, this);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        closeTracker.removeFromTrackedRegistry();
-        return super.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         closeTracker.removeFromTrackedRegistry();
index a21268d..641e77b 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -74,11 +73,6 @@ public class ForwardingReadWriteTransaction extends ForwardingObject implements
         delegate.merge(store, path, data, createMissingParents);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return delegate.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return delegate.commit();
index 801732d..99dbe36 100644 (file)
@@ -8,10 +8,8 @@
 package org.opendaylight.controller.md.sal.binding.api;
 
 import com.google.common.collect.ForwardingObject;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -66,11 +64,6 @@ public class ForwardingWriteTransaction extends ForwardingObject implements Writ
         return delegate.cancel();
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return delegate.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return delegate.commit();
index 142ad4a..eeb519f 100644 (file)
@@ -7,20 +7,15 @@
  */
 package org.opendaylight.controller.md.sal.binding.impl;
 
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.List;
 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.controller.md.sal.common.impl.util.compat.DataNormalizationException;
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper;
 import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -71,12 +66,6 @@ class BindingDOMWriteTransactionAdapter<T extends DOMDataWriteTransaction> exten
         doDelete(store, path);
     }
 
-    @Override
-    public CheckedFuture<Void,TransactionCommitFailedException> submit() {
-        return MappingCheckedFuture.create(commit().transform(ignored -> null,
-                MoreExecutors.directExecutor()), TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return doCommit();
index 9885146..470eeb4 100644 (file)
@@ -7,16 +7,18 @@
  */
 package org.opendaylight.controller.md.sal.binding.impl.test;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.base.Optional;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
@@ -32,19 +34,37 @@ public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
     private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
 
     @Test
-    public void test() throws InterruptedException, ExecutionException {
+    @Deprecated
+    public void testSubmit() throws InterruptedException, ExecutionException, TimeoutException {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
         writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
-        writeTx.submit().get();
+        writeTx.submit().get(5, TimeUnit.SECONDS);
+
+        ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
+        Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
+        assertTrue("List node must exists after commit", listNode.isPresent());
+        assertEquals("List node", NODE, listNode.get());
+    }
+
+    @Test
+    public void testCommit() throws InterruptedException, ExecutionException, TimeoutException {
+        WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+        writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
+        writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
+        writeTx.commit().get(5, TimeUnit.SECONDS);
+
+        ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
+        Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
+        assertTrue("List node must exists after commit", listNode.isPresent());
+        assertEquals("List node", NODE, listNode.get());
     }
 
     @Test
-    public void testPutCreateParentsSuccess()
-            throws TransactionCommitFailedException, InterruptedException, ExecutionException {
+    public void testPutCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
-        writeTx.submit().checkedGet();
+        writeTx.commit().get(5, TimeUnit.SECONDS);
 
         ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
         Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
@@ -54,11 +74,10 @@ public class WriteTransactionTest extends AbstractConcurrentDataBrokerTest {
     }
 
     @Test
-    public void testMergeCreateParentsSuccess()
-            throws TransactionCommitFailedException, InterruptedException, ExecutionException {
+    public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException, TimeoutException {
         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
-        writeTx.submit().checkedGet();
+        writeTx.commit().get(5, TimeUnit.SECONDS);
 
         ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
         Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
index 314ee4b..d779a69 100644 (file)
@@ -28,7 +28,6 @@ import org.opendaylight.controller.md.sal.binding.api.MountPointService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
@@ -198,11 +197,6 @@ public class CrossBrokerMountPointTest {
                             throw new UnsupportedOperationException();
                         }
 
-                        @Override
-                        public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-                            throw new UnsupportedOperationException();
-                        }
-
                         @Override
                         public FluentFuture<? extends CommitInfo> commit() {
                             throw new UnsupportedOperationException();
index 57fbf89..eafa2dc 100644 (file)
@@ -14,7 +14,9 @@ import com.google.common.util.concurrent.MoreExecutors;
 import javax.annotation.CheckReturnValue;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.concepts.Path;
+import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
 
 /**
  * Write transaction provides mutation capabilities for a data tree.
@@ -339,7 +341,10 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      */
     @Deprecated
     @CheckReturnValue
-    CheckedFuture<Void,TransactionCommitFailedException> submit();
+    default CheckedFuture<Void, TransactionCommitFailedException> submit() {
+        return MappingCheckedFuture.create(commit().transform(ignored -> null, MoreExecutors.directExecutor()),
+                SUBMIT_EXCEPTION_MAPPER);
+    }
 
     /**
      * Submits this transaction to be asynchronously applied to update the logical data tree. The returned
@@ -371,8 +376,17 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * @throws IllegalStateException if the transaction is already committed or was canceled.
      */
     @CheckReturnValue
-    default @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
-        return FluentFuture.from(submit()).transformAsync(ignored -> CommitInfo.emptyFluentFuture(),
-            MoreExecutors.directExecutor());
-    }
+    @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
+
+    /**
+     * This only exists for reuse by the deprecated {@link #submit} method and is not intended for general use.
+     */
+    @Deprecated
+    ExceptionMapper<TransactionCommitFailedException> SUBMIT_EXCEPTION_MAPPER =
+        new ExceptionMapper<TransactionCommitFailedException>("submit", TransactionCommitFailedException.class) {
+            @Override
+            protected TransactionCommitFailedException newWithCause(String message, Throwable cause) {
+                return new TransactionCommitFailedException(message, cause);
+            }
+        };
 }
index d1a4078..8b3ff26 100644 (file)
@@ -16,6 +16,9 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
 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.MoreExecutors;
+import com.google.common.util.concurrent.SettableFuture;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
@@ -59,8 +62,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * @author Thomas Pantelis
  */
 public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMDataBroker {
-    private static final ExceptionMapper<TransactionCommitFailedException> SUBMIT_EX_MAPPER =
-            new ExceptionMapper<TransactionCommitFailedException>("submit", TransactionCommitFailedException.class) {
+    private static final ExceptionMapper<TransactionCommitFailedException> COMMIT_EX_MAPPER =
+            new ExceptionMapper<TransactionCommitFailedException>("commit", TransactionCommitFailedException.class) {
         @Override
         protected TransactionCommitFailedException newWithCause(String message, Throwable cause) {
             if (cause instanceof org.opendaylight.mdsal.common.api.OptimisticLockFailedException) {
@@ -177,7 +180,7 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
                     final org.opendaylight.mdsal.common.api.AsyncTransaction<?, ?> transaction, final Throwable cause) {
                 listener.onTransactionChainFailed(legacyChain.get(),
                         (AsyncTransaction) () -> transaction.getIdentifier(),
-                            cause instanceof Exception ? SUBMIT_EX_MAPPER.apply((Exception)cause) : cause);
+                            cause instanceof Exception ? COMMIT_EX_MAPPER.apply((Exception)cause) : cause);
             }
 
             @Override
@@ -298,14 +301,26 @@ public class LegacyDOMDataBrokerAdapter extends ForwardingObject implements DOMD
             return writeDelegate().cancel();
         }
 
-        @Override
-        public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-            return MappingCheckedFuture.create(writeDelegate().submit(), SUBMIT_EX_MAPPER);
-        }
-
         @Override
         public FluentFuture<? extends CommitInfo> commit() {
-            return writeDelegate().commit();
+            final SettableFuture<CommitInfo> resultFuture = SettableFuture.create();
+            writeDelegate().commit().addCallback(new FutureCallback<CommitInfo>() {
+                @Override
+                public void onSuccess(CommitInfo result) {
+                    resultFuture.set(result);
+                }
+
+                @Override
+                public void onFailure(Throwable ex) {
+                    if (ex instanceof Exception) {
+                        resultFuture.setException(COMMIT_EX_MAPPER.apply((Exception)ex));
+                    } else {
+                        resultFuture.setException(ex);
+                    }
+                }
+            }, MoreExecutors.directExecutor());
+
+            return resultFuture;
         }
     }
 
index b6e7682..738a87c 100644 (file)
@@ -24,13 +24,13 @@ import static org.mockito.Mockito.verify;
 import com.google.common.base.Optional;
 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.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
-import org.eclipse.jdt.annotation.NonNull;
+import java.util.concurrent.TimeoutException;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -59,7 +59,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeCommitCohortRegistr
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistration;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
@@ -198,8 +197,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         tx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
         verify(mockWriteTx).delete(TestModel.TEST_PATH);
 
-        CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
-        submitFuture.get(5, TimeUnit.SECONDS);
+        tx.commit().get(5, TimeUnit.SECONDS);
 
         InOrder inOrder = inOrder(mockCommitCohort);
         inOrder.verify(mockCommitCohort).canCommit();
@@ -223,8 +221,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         try {
             tx = adapter.newWriteOnlyTransaction();
             tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
-            submitFuture = tx.submit();
-            submitFuture.checkedGet(5, TimeUnit.SECONDS);
+            commit(tx);
             fail("Expected OptimisticLockFailedException");
         } catch (OptimisticLockFailedException e) {
             assertEquals("getMessage", errorMsg, e.getMessage());
@@ -241,8 +238,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         try {
             tx = adapter.newWriteOnlyTransaction();
             tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
-            submitFuture = tx.submit();
-            submitFuture.checkedGet(5, TimeUnit.SECONDS);
+            commit(tx);
             fail("Expected TransactionCommitFailedException");
         } catch (TransactionCommitFailedException e) {
             assertEquals("getMessage", errorMsg, e.getMessage());
@@ -258,8 +254,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         try {
             tx = adapter.newWriteOnlyTransaction();
             tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
-            submitFuture = tx.submit();
-            submitFuture.checkedGet(5, TimeUnit.SECONDS);
+            commit(tx);
             fail("Expected TransactionCommitFailedException");
         } catch (TransactionCommitFailedException e) {
             assertEquals("getCause type", DataStoreUnavailableException.class, e.getCause().getClass());
@@ -275,8 +270,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         try {
             tx = adapter.newWriteOnlyTransaction();
             tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
-            submitFuture = tx.submit();
-            submitFuture.checkedGet(5, TimeUnit.SECONDS);
+            commit(tx);
             fail("Expected TransactionCommitFailedException");
         } catch (TransactionCommitFailedException e) {
             assertEquals("getCause", cause, e.getCause());
@@ -296,8 +290,7 @@ public class LegacyDOMDataBrokerAdapterTest {
         tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
         verify(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
 
-        CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
-        submitFuture.get(5, TimeUnit.SECONDS);
+        tx.commit().get(5, TimeUnit.SECONDS);
 
         InOrder inOrder = inOrder(mockCommitCohort);
         inOrder.verify(mockCommitCohort).canCommit();
@@ -330,8 +323,7 @@ public class LegacyDOMDataBrokerAdapterTest {
 
         writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
         verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
-        CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
-        submitFuture.get(5, TimeUnit.SECONDS);
+        writeTx.commit().get(5, TimeUnit.SECONDS);
 
         InOrder inOrder = inOrder(mockCommitCohort);
         inOrder.verify(mockCommitCohort).canCommit();
@@ -361,7 +353,7 @@ public class LegacyDOMDataBrokerAdapterTest {
 
         try {
             writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
-            writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+            commit(writeTx);
             fail("Expected TransactionCommitFailedException");
         } catch (TransactionCommitFailedException e) {
             // expected
@@ -456,19 +448,46 @@ public class LegacyDOMDataBrokerAdapterTest {
     }
 
     @Test
-    public void testCommit() throws Exception {
+    @Deprecated
+    public void testSubmit() throws Exception {
         DOMDataWriteTransaction tx = adapter.newWriteOnlyTransaction();
 
         tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
         verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
 
-        @NonNull FluentFuture<? extends @NonNull CommitInfo> commitFuture = tx.commit();
-        commitFuture.get(5, TimeUnit.SECONDS);
+        tx.submit().get(5, TimeUnit.SECONDS);
 
         InOrder inOrder = inOrder(mockCommitCohort);
         inOrder.verify(mockCommitCohort).canCommit();
         inOrder.verify(mockCommitCohort).preCommit();
         inOrder.verify(mockCommitCohort).commit();
+
+        String errorMsg = "mock OptimisticLockFailedException";
+        Throwable cause = new ConflictingModificationAppliedException(TestModel.TEST_PATH, "mock");
+        doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException(
+                errorMsg, cause))).when(mockCommitCohort).canCommit();
+
+        try {
+            tx = adapter.newWriteOnlyTransaction();
+            tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
+            commit(tx);
+            fail("Expected TransactionCommitFailedException");
+        } catch (TransactionCommitFailedException e) {
+            assertEquals("getMessage", errorMsg, e.getMessage());
+            assertEquals("getCause", cause, e.getCause());
+        }
+    }
+
+    @SuppressWarnings("checkstyle:AvoidHidingCauseException")
+    private static void commit(DOMDataWriteTransaction tx)
+            throws TransactionCommitFailedException, InterruptedException, TimeoutException {
+        try {
+            tx.commit().get(5, TimeUnit.SECONDS);
+        } catch (ExecutionException e) {
+            assertTrue("Expected TransactionCommitFailedException. Actual: " + e.getCause(),
+                    e.getCause() instanceof TransactionCommitFailedException);
+            throw (TransactionCommitFailedException)e.getCause();
+        }
     }
 
     private interface TestDOMStore extends DistributedDataStoreInterface, DOMStoreTreeChangePublisher,
index 5c312cc..145bfe0 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.controller.md.sal.dom.broker.impl;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Supplier;
-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.ListenableFuture;
@@ -19,12 +18,10 @@ import java.util.Map;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -130,12 +127,6 @@ class DOMForwardedWriteTransaction<T extends DOMStoreWriteTransaction> extends
         return future.cancel(false);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return MappingCheckedFuture.create(doCommit(() -> null),
-                TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return FluentFuture.from(doCommit(CommitInfo::empty));
index fad3c1c..2275a6b 100644 (file)
@@ -39,7 +39,7 @@ final class PingPongTransaction implements FutureCallback<CommitInfo> {
         return frontendTransaction;
     }
 
-    ListenableFuture<CommitInfo> getSubmitFuture() {
+    ListenableFuture<CommitInfo> getCommitFuture() {
         return future;
     }
 
index 8cda1d5..adcf8aa 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
@@ -33,7 +32,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.dom.spi.ForwardingDOMDataReadWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -450,17 +448,11 @@ public final class PingPongTransactionChain implements DOMTransactionChain {
                 return tx.getTransaction();
             }
 
-            @Override
-            public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-                return MappingCheckedFuture.create(commit().transform(ignored -> null,
-                        MoreExecutors.directExecutor()), TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
-            }
-
             @Override
             public FluentFuture<? extends CommitInfo> commit() {
                 readyTransaction(tx);
                 isOpen = false;
-                return FluentFuture.from(tx.getSubmitFuture()).transformAsync(
+                return FluentFuture.from(tx.getCommitFuture()).transformAsync(
                     ignored -> CommitInfo.emptyFluentFuture(), MoreExecutors.directExecutor());
             }
 
index 380f9d5..8c4ac63 100644 (file)
@@ -29,7 +29,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
@@ -108,11 +107,6 @@ class ShardedDOMDataBrokerDelegatingReadWriteTransaction implements DOMDataReadW
         writeTxDelegate.delete(store, path);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return writeTxDelegate.submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return writeTxDelegate.commit();
index 7ff6728..853aa71 100644 (file)
@@ -10,13 +10,9 @@ package org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapte
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.Futures;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -54,11 +50,6 @@ class ShardedDOMDataBrokerDelegatingWriteTransaction implements DOMDataWriteTran
         delegateTx.delete(LegacyShardedDOMDataBrokerAdapterUtils.translateDataStoreType(store), path);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return Futures.makeChecked(delegateTx.submit(), TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return delegateTx.commit();
index 07ca545..519c364 100644 (file)
@@ -30,6 +30,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 import org.junit.After;
 import org.junit.Before;
@@ -133,7 +134,7 @@ public class DOMBrokerTest {
     }
 
     @Test(timeout = 10000)
-    public void testTransactionCommit() throws InterruptedException, ExecutionException {
+    public void testTransactionCommit() throws InterruptedException, ExecutionException, TimeoutException {
 
         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
         assertNotNull(writeTx);
@@ -152,7 +153,35 @@ public class DOMBrokerTest {
                 .read(OPERATIONAL, TestModel.TEST_PATH);
         assertTrue(writeTxContainer.get().isPresent());
 
-        writeTx.submit().get();
+        writeTx.commit().get(5, TimeUnit.SECONDS);
+
+        Optional<NormalizedNode<?, ?>> afterCommitRead = domBroker.newReadOnlyTransaction()
+                .read(OPERATIONAL, TestModel.TEST_PATH).get();
+        assertTrue(afterCommitRead.isPresent());
+    }
+
+    @Test(timeout = 10000)
+    @Deprecated
+    public void testTransactionSubmit() throws InterruptedException, ExecutionException, TimeoutException {
+
+        DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
+        assertNotNull(writeTx);
+        /**
+         *
+         * Writes /test in writeTx
+         *
+         */
+        writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+
+        /**
+         * Reads /test from writeTx Read should return container.
+         *
+         */
+        ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx
+                .read(OPERATIONAL, TestModel.TEST_PATH);
+        assertTrue(writeTxContainer.get().isPresent());
+
+        writeTx.submit().get(5, TimeUnit.SECONDS);
 
         Optional<NormalizedNode<?, ?>> afterCommitRead = domBroker.newReadOnlyTransaction()
                 .read(OPERATIONAL, TestModel.TEST_PATH).get();
@@ -160,7 +189,8 @@ public class DOMBrokerTest {
     }
 
     @Test(expected = TransactionCommitFailedException.class)
-    public void testRejectedCommit() throws Exception {
+    @SuppressWarnings({"checkstyle:IllegalThrows", "checkstyle:AvoidHidingCauseException"})
+    public void testRejectedCommit() throws Throwable {
 
         commitExecutor.delegate = Mockito.mock(ExecutorService.class);
         Mockito.doThrow(new RejectedExecutionException("mock")).when(commitExecutor.delegate)
@@ -174,7 +204,11 @@ public class DOMBrokerTest {
         DOMDataReadWriteTransaction writeTx = domBroker.newReadWriteTransaction();
         writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+        try {
+            writeTx.commit().get(5, TimeUnit.SECONDS);
+        } catch (ExecutionException e) {
+            throw e.getCause();
+        }
     }
 
     /**
@@ -235,7 +269,7 @@ public class DOMBrokerTest {
                         caughtCommitEx.set(throwable);
                         commitCompletedLatch.countDown();
                     }
-                });
+                }, MoreExecutors.directExecutor());
 
                 super.onDataChanged(change);
             }
@@ -279,7 +313,7 @@ public class DOMBrokerTest {
                 DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
                 writeTx.put(OPERATIONAL, TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME));
                 try {
-                    writeTx.submit().get();
+                    writeTx.commit().get();
                 } catch (ExecutionException e) {
                     caughtCommitEx.set(e.getCause());
                 } catch (Exception e) {
@@ -315,7 +349,7 @@ public class DOMBrokerTest {
         final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
         new Thread(() -> {
             try {
-                writeTx.submit();
+                writeTx.commit();
             } catch (Throwable e) {
                 caughtEx.set(e);
             }
index 7f450a4..671e0f8 100644 (file)
@@ -14,7 +14,6 @@ import com.google.common.util.concurrent.FluentFuture;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -68,11 +67,6 @@ public abstract class ForwardingDOMDataReadWriteTransaction extends ForwardingOb
         delegate().delete(store, path);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return delegate().submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return delegate().commit();
index 474c151..4ef889f 100644 (file)
@@ -8,11 +8,9 @@
 package org.opendaylight.controller.md.sal.dom.spi;
 
 import com.google.common.collect.ForwardingObject;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FluentFuture;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -53,11 +51,6 @@ public abstract class ForwardingDOMDataWriteTransaction extends ForwardingObject
         delegate().delete(store, path);
     }
 
-    @Override
-    public CheckedFuture<Void, TransactionCommitFailedException> submit() {
-        return delegate().submit();
-    }
-
     @Override
     public FluentFuture<? extends CommitInfo> commit() {
         return delegate().commit();

©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.