Get rid of CheckedFutures 22/74822/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 4 Aug 2018 00:07:58 +0000 (02:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 4 Aug 2018 00:09:12 +0000 (02:09 +0200)
We do not really need them, so let's replace them where we can.

Change-Id: I06dd05d60018a814fb0610096aa8fe5709669980
JIRA: MDSAL-229
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/extractor/DirectGetterRouteContextExtractor.java
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/extractor/GetValueRouteContextExtractor.java
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/impl/data/tree/BindingDOMDataTreeListenerAdapter.java
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/impl/notification/NotificationListenerInvoker.java
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/impl/operation/invoker/OperationMethodInvoker.java
binding2/mdsal-binding2-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/spi/AbstractForwardedTransaction.java
binding2/mdsal-binding2-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/javav2/dom/adapter/test/BindingTestContext.java
binding2/mdsal-binding2-runtime/src/main/java/org/opendaylight/mdsal/binding/javav2/runtime/context/BindingRuntimeContext.java
binding2/mdsal-binding2-runtime/src/main/java/org/opendaylight/mdsal/binding/javav2/runtime/context/ModuleInfoBackedContext.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/CommitCoordinationTaskTest.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMTransactionChainAdapterTest.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TransactionChainReadTransactionTest.java

index 9ea627cbde7b471c747e98e3e293cf15c5a48775..61e2526166a0eb5fafad4dd73d567a35ba8e7e8b 100644 (file)
@@ -39,7 +39,8 @@ final class DirectGetterRouteContextExtractor extends ContextReferenceExtractor
         try {
             return (InstanceIdentifier<? extends TreeNode>) handle.invokeExact(obj);
         } catch (final Throwable e) {
-            throw Throwables.propagate(e);
+            Throwables.throwIfUnchecked(e);
+            throw new RuntimeException(e);
         }
     }
 }
\ No newline at end of file
index 114a51dd4e990963b86c4d7cd5d1827bc9a476e2..1a5ad18cc058a89f369888cbe8f404e3b71f05e2 100644 (file)
@@ -47,7 +47,8 @@ final class GetValueRouteContextExtractor extends ContextReferenceExtractor {
             }
             return null;
         } catch (final Throwable e) {
-            throw Throwables.propagate(e);
+            Throwables.throwIfUnchecked(e);
+            throw new RuntimeException(e);
         }
     }
 }
index 9353920827d789f6ea5fc5efaf1fcee74cea3c06..c75c89e8c78ff5d091c782ebe84a0f529a5c0f1b 100644 (file)
@@ -85,7 +85,7 @@ public class BindingDOMDataTreeListenerAdapter implements DOMDataTreeListener {
         delegate.onDataTreeFailed(bindingCauses);
     }
 
-    private DataTreeListeningException mapException(final DOMDataTreeListeningException cause) {
+    private static DataTreeListeningException mapException(final DOMDataTreeListeningException cause) {
         // FIXME: Extend logic
         return new DataTreeListeningException(cause.getMessage(), cause);
     }
index 511660f9ec679ed3ff05656928beb42ee894d25e..8156d8d891fe429a48e873ae27eaa2f3b75f28f5 100644 (file)
@@ -120,7 +120,8 @@ public final class NotificationListenerInvoker {
         try {
             invoker.invokeExact(impl, input);
         } catch (final Throwable e) {
-            throw Throwables.propagate(e);
+            Throwables.throwIfUnchecked(e);
+            throw new RuntimeException(e);
         }
     }
 }
index c1549ad3ee352654cc4d1922ef05ca94dd84baad..2c1bcad997a7452f92f1c2154f3259884d6a0b66 100644 (file)
@@ -46,7 +46,8 @@ abstract class OperationMethodInvoker {
         try {
             return (Future<RpcResult<?>>) handle.invokeExact(args);
         } catch (final Throwable e) {
-            throw Throwables.propagate(e);
+            Throwables.throwIfUnchecked(e);
+            throw new RuntimeException(e);
         }
     }
 }
index 50ae0156d04fc6bae186a486eb5e76a3bb34b0b4..f35df4fbf24865adbc694393759e50affb0c5c01 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.mdsal.binding.javav2.dom.adapter.spi;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 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.MoreExecutors;
 import javax.annotation.Nonnull;
 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.BindingToNormalizedNodeCodec;
@@ -18,8 +18,6 @@ import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
 import org.opendaylight.mdsal.common.api.AsyncTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
-import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
 import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.concepts.Identifiable;
@@ -67,13 +65,13 @@ public abstract class AbstractForwardedTransaction<
         return codec;
     }
 
-    protected final <D extends TreeNode> CheckedFuture<Optional<D>, ReadFailedException> doRead(
+    protected final <D extends TreeNode> FluentFuture<Optional<D>> doRead(
             final DOMDataTreeReadTransaction readTx, final LogicalDatastoreType store,
             final InstanceIdentifier<D> path) {
         Preconditions.checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path);
 
-        return MappingCheckedFuture.create(readTx.read(store, codec.toYangInstanceIdentifierBlocking(path))
+        return readTx.read(store, codec.toYangInstanceIdentifierBlocking(path))
             .transform(Optional::fromJavaUtil, MoreExecutors.directExecutor())
-            .transform(codec.deserializeFunction(path), MoreExecutors.directExecutor()), ReadFailedException.MAPPER);
+            .transform(codec.deserializeFunction(path), MoreExecutors.directExecutor());
     }
 }
index 6a0ea2b6ae25fc9160e9a798a983a8f7deaec552..dcf9d8e241a506b0eddbfc04aeb8a7acf0a36859 100644 (file)
@@ -143,7 +143,7 @@ public class BindingTestContext implements AutoCloseable {
         mockSchemaService.changeSchema(getContext(moduleInfos));
     }
 
-    private SchemaContext getContext(final ImmutableSet<YangModuleInfo> moduleInfos) {
+    private static SchemaContext getContext(final ImmutableSet<YangModuleInfo> moduleInfos) {
         final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
         ctx.addModuleInfos(moduleInfos);
         return ctx.tryToCreateSchemaContext().get();
index cc1f991a9edaadbdafe1676b0eab0d225554ae98..6ed1f56444ea63637cc48384e5e2b46eb34836e7 100755 (executable)
@@ -24,7 +24,6 @@ import java.util.AbstractMap.SimpleEntry;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -429,7 +428,7 @@ public class BindingRuntimeContext implements Immutable {
         }
     }
 
-    private boolean isLocalAugment(final AugmentationTarget container, final AugmentationSchemaNode augment) {
+    private static boolean isLocalAugment(final AugmentationTarget container, final AugmentationSchemaNode augment) {
         Preconditions.checkState(container instanceof SchemaNode);
         final QName root = ((SchemaNode) container).getPath().getPathFromRoot().iterator().next();
         // findFirst makes no sense but just pick up one child to judge whether the target node is
index a321f9147d3b76bbc90ef2ddfae74d2660a39385..671229532416dfdded33ebb75cd38815b2e950e9 100644 (file)
@@ -11,8 +11,8 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Optional;
 import com.google.common.io.ByteSource;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
@@ -184,22 +184,24 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy
         return registration;
     }
 
-    @Override public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
+    @Override
+    public ListenableFuture<? extends YangTextSchemaSource> getSource(
         final SourceIdentifier sourceIdentifier) {
         final YangModuleInfo yangModuleInfo = sourceIdentifierToModuleInfo.get(sourceIdentifier);
 
         if (yangModuleInfo == null) {
-            LOG.debug("Unknown schema source requested: {}, available sources: {}", sourceIdentifier, sourceIdentifierToModuleInfo.keySet());
-            return Futures
-                .immediateFailedCheckedFuture(new SchemaSourceException("Unknown schema source: " + sourceIdentifier));
+            LOG.debug("Unknown schema source requested: {}, available sources: {}", sourceIdentifier,
+                sourceIdentifierToModuleInfo.keySet());
+            return Futures.immediateFailedFuture(new SchemaSourceException("Unknown schema source: "
+                + sourceIdentifier));
         }
 
-        return Futures
-            .immediateCheckedFuture(YangTextSchemaSource.delegateForByteSource(sourceIdentifier, new ByteSource() {
-                @Override public InputStream openStream() throws IOException {
-                        return yangModuleInfo.getModuleSourceStream();
-                }
-            }));
+        return Futures.immediateFuture(YangTextSchemaSource.delegateForByteSource(sourceIdentifier, new ByteSource() {
+            @Override
+            public InputStream openStream() throws IOException {
+                return yangModuleInfo.getModuleSourceStream();
+            }
+        }));
     }
 
     private static class YangModuleInfoRegistration extends AbstractObjectRegistration<YangModuleInfo> {
index a1cca509bfe8c743255df75e5cbb1bc5904347be..3cf8b485b24f87be7e52287ac980fd2348343ca0 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.mdsal.dom.broker;
 
-import static com.google.common.util.concurrent.Futures.immediateFailedCheckedFuture;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
@@ -18,6 +17,7 @@ import org.junit.Test;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 
 public class CommitCoordinationTaskTest {
 
@@ -33,36 +33,36 @@ public class CommitCoordinationTaskTest {
 
     @Test(expected = TransactionCommitFailedException.class)
     public void canCommitBlockingWithFail() throws Exception {
-        doReturn(Futures.immediateCheckedFuture(null)).when(cohort).abort();
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(cohort).abort();
 
-        doReturn(Futures.immediateCheckedFuture(Boolean.FALSE)).when(cohort).canCommit();
+        doReturn(FluentFutures.immediateFalseFluentFuture()).when(cohort).canCommit();
         task.call();
     }
 
     @Test(expected = TransactionCommitFailedException.class)
     public void canCommitBlockingWithFailException() throws Exception {
-        doReturn(Futures.immediateCheckedFuture(null)).when(cohort).abort();
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(cohort).abort();
 
-        doReturn(immediateFailedCheckedFuture(new InterruptedException())).when(cohort).canCommit();
+        doReturn(Futures.immediateFailedFuture(new InterruptedException())).when(cohort).canCommit();
         task.call();
     }
 
     @Test(expected = TransactionCommitFailedException.class)
     public void preCommitBlockingWithFail() throws Exception {
-        doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(cohort).canCommit();
-        doReturn(Futures.immediateCheckedFuture(null)).when(cohort).abort();
+        doReturn(FluentFutures.immediateTrueFluentFuture()).when(cohort).canCommit();
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(cohort).abort();
 
-        doReturn(immediateFailedCheckedFuture(new InterruptedException())).when(cohort).preCommit();
+        doReturn(Futures.immediateFailedFuture(new InterruptedException())).when(cohort).preCommit();
         task.call();
     }
 
     @Test(expected = TransactionCommitFailedException.class)
     public void commitBlockingWithFail() throws Exception {
-        doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(cohort).canCommit();
-        doReturn(Futures.immediateCheckedFuture(null)).when(cohort).preCommit();
-        doReturn(Futures.immediateCheckedFuture(null)).when(cohort).abort();
+        doReturn(FluentFutures.immediateTrueFluentFuture()).when(cohort).canCommit();
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(cohort).preCommit();
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(cohort).abort();
 
-        doReturn(immediateFailedCheckedFuture(new InterruptedException())).when(cohort).commit();
+        doReturn(Futures.immediateFailedFuture(new InterruptedException())).when(cohort).commit();
         task.call();
     }
 }
\ No newline at end of file
index 3b3e7da7afc2229c6071b2eb73b91b64da238aa0..536055eff39c1102d63d412d437c9f67bb7c144d 100644 (file)
@@ -17,8 +17,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
 
-import com.google.common.util.concurrent.Futures;
 import org.junit.Test;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.TransactionChainListener;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
@@ -66,13 +66,12 @@ public class ShardedDOMTransactionChainAdapterTest {
         verify(cursor).delete(any());
 
         doNothing().when(cursor).close();
-        doReturn(Futures.immediateCheckedFuture(null)).when(transaction).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(transaction).commit();
         doReturn(true).when(transaction).cancel();
         assertTrue(writeTransaction.cancel());
         transactionChainAdapter.closeWriteTransaction(FluentFutures.immediateNullFluentFuture());
 
-        transactionChainAdapter =
-                new ShardedDOMTransactionChainAdapter(identifier, dataTreeService, chainListener);
+        transactionChainAdapter = new ShardedDOMTransactionChainAdapter(identifier, dataTreeService, chainListener);
         writeTransaction = transactionChainAdapter.newWriteOnlyTransaction();
         writeTransaction.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
         assertNotNull(writeTransaction.commit());
index f8d063a4aac48810ed02cdff6cdfa29c2efcd3e0..72ef31aabe6b60391e358060180f225d54161e72 100644 (file)
@@ -17,7 +17,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.Futures;
 import org.junit.Test;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -45,13 +44,13 @@ public class TransactionChainReadTransactionTest {
         verify(readTransaction).close();
         verify(chainAdapter).closeReadTransaction();
 
-        doReturn(Futures.immediateCheckedFuture(null)).when(readTransaction).read(any(), any());
+        doReturn(FluentFutures.immediateNullFluentFuture()).when(readTransaction).read(any(), any());
         assertNotNull(transactionChainReadTransaction.exists(
                 LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY));
         transactionChainReadTransaction.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
         verify(readTransaction, atLeastOnce()).read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
 
-        doReturn(Futures.immediateFailedCheckedFuture(
+        doReturn(FluentFutures.immediateFailedFluentFuture(
                 new NullPointerException())).when(readTransaction).read(any(), any());
         doNothing().when(chainAdapter).transactionFailed(any(), any());
         assertNotNull(transactionChainReadTransaction.read(