From d7484e8061336c088ab8ed89b09ae3e254cf1ef4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 19 Apr 2017 15:59:22 +0200 Subject: [PATCH] BUG-5280: unwrap RuntimeRequestExceptions This patch adds the primitive to unwrap RuntimeRequestExceptions, so the underlying cause is propagated. Change-Id: I77771867a48eb5f63d35a6402aca6ad0bc5b12e3 Signed-off-by: Robert Varga --- .../cluster/access/concepts/RequestException.java | 10 ++++++++++ .../access/concepts/RuntimeRequestException.java | 8 ++++++-- .../actors/dds/AbstractProxyTransaction.java | 10 +++++----- .../actors/dds/AbstractShardBackendResolver.java | 3 +-- .../actors/dds/ClientTransactionCommitCohortTest.java | 5 +++-- .../actors/dds/ModuleShardBackendResolverTest.java | 3 +-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java index 5f525b0a9b..4f2a0585da 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java @@ -29,4 +29,14 @@ public abstract class RequestException extends Exception { } public abstract boolean isRetriable(); + + /** + * Unwraps the underlying failure. This method is overridden only in {@link RuntimeRequestException}. + * + * @return Underlying cause of the failure if exception is a {@link RuntimeRequestException}, or the exception + * itself. + */ + public Throwable unwrap() { + return this; + } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java index 2cf1828da4..a52396fd5d 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java @@ -21,13 +21,17 @@ public final class RuntimeRequestException extends RequestException { private static final long serialVersionUID = 1L; public RuntimeRequestException(final String message, final Throwable cause) { - super(message, cause); + super(message, Preconditions.checkNotNull(cause)); Preconditions.checkArgument(!Strings.isNullOrEmpty(message), "Exception message is mandatory"); - Preconditions.checkNotNull(cause); } @Override public boolean isRetriable() { return false; } + + @Override + public Throwable unwrap() { + return getCause(); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java index 27f9b47cd9..86d7f23741 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java @@ -316,7 +316,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause()); + ret.voteNo(((RequestFailure) t).getCause().unwrap()); } else { ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); } @@ -349,7 +349,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause()); + ret.setException(((RequestFailure) t).getCause().unwrap()); } else { ret.setException(new IllegalStateException("Unhandled response " + t.getClass())); } @@ -380,7 +380,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause()); + ret.voteNo(((RequestFailure) t).getCause().unwrap()); } else { ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); } @@ -411,7 +411,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause()); + ret.voteNo(((RequestFailure) t).getCause().unwrap()); } else { ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); } @@ -444,7 +444,7 @@ abstract class AbstractProxyTransaction implements Identifiable) t).getCause()); + ret.voteNo(((RequestFailure) t).getCause().unwrap()); } else { ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass())); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java index 51f96e18fd..93cf7931e5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractShardBackendResolver.java @@ -24,7 +24,6 @@ import org.opendaylight.controller.cluster.access.client.BackendInfoResolver; import org.opendaylight.controller.cluster.access.commands.ConnectClientRequest; import org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; -import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.RequestFailure; import org.opendaylight.controller.cluster.common.actor.ExplicitAsk; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; @@ -137,7 +136,7 @@ abstract class AbstractShardBackendResolver extends BackendInfoResolver) response).getCause(); + final Throwable cause = ((RequestFailure) response).getCause().unwrap(); LOG.debug("Connect attempt to {} failed to process", shardName, cause); future.completeExceptionally(cause); return; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java index f9eb6ed6af..6fde068c6e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java @@ -228,12 +228,13 @@ public class ClientTransactionCommitCohortTest { //reply fail to last transaction final TransactionTester last = transactions.get(transactions.size() - 1); expectFunction.accept(last); - final RuntimeRequestException cause = new RuntimeRequestException("fail", new RuntimeException()); + final RuntimeException e = new RuntimeException(); + final RuntimeRequestException cause = new RuntimeRequestException("fail", e); last.replyFailure(cause); //check future fail final ExecutionException exception = assertOperationThrowsException(() -> getWithTimeout(canCommit), ExecutionException.class); - Assert.assertEquals(cause, exception.getCause()); + Assert.assertEquals(e, exception.getCause()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java index d1c322f86a..f86f806369 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ModuleShardBackendResolverTest.java @@ -117,8 +117,7 @@ public class ModuleShardBackendResolverTest { final ExecutionException caught = TestUtils.assertOperationThrowsException(() -> TestUtils.getWithTimeout(stage.toCompletableFuture()), ExecutionException.class); - Assert.assertNotNull(caught.getCause()); - Assert.assertEquals(cause, caught.getCause().getCause()); + Assert.assertEquals(cause, caught.getCause()); } @Test -- 2.36.6