X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FAbstractTransactionProxyTest.java;h=2dd62ab72da29e0bed352eed95a79eb989faadbe;hp=afa4627db6f1eb24c4c30e55f14ae7a7351f468a;hb=12fcdfe39aa26dcba7fd3bb4d4c68e3d02e65c51;hpb=e9fc7e7ed2b13d274518d6a872ab67749ef4507a diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java index afa4627db6..2dd62ab72d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; @@ -29,15 +30,15 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; 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.typesafe.config.Config; import com.typesafe.config.ConfigFactory; -import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.AfterClass; import org.junit.Before; @@ -75,8 +76,8 @@ import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration; import org.opendaylight.controller.cluster.raft.utils.DoNothingActor; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.ReadFailedException; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -98,10 +99,10 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { private final Configuration configuration = new MockConfiguration() { Map strategyMap = ImmutableMap.builder().put( - "junk", new ShardStrategy() { + TestModel.JUNK_QNAME.getLocalName(), new ShardStrategy() { @Override public String findShard(final YangInstanceIdentifier path) { - return "junk"; + return TestModel.JUNK_QNAME.getLocalName(); } @Override @@ -109,10 +110,10 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { return YangInstanceIdentifier.EMPTY; } }).put( - "cars", new ShardStrategy() { + CarsModel.BASE_QNAME.getLocalName(), new ShardStrategy() { @Override public String findShard(final YangInstanceIdentifier path) { - return "cars"; + return CarsModel.BASE_QNAME.getLocalName(); } @Override @@ -129,9 +130,9 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { @Override public String getModuleNameFromNameSpace(final String nameSpace) { if (TestModel.JUNK_QNAME.getNamespace().toASCIIString().equals(nameSpace)) { - return "junk"; + return TestModel.JUNK_QNAME.getLocalName(); } else if (CarsModel.BASE_QNAME.getNamespace().toASCIIString().equals(nameSpace)) { - return "cars"; + return CarsModel.BASE_QNAME.getLocalName(); } return null; } @@ -154,7 +155,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { .operationTimeoutInSeconds(operationTimeoutInSeconds); @BeforeClass - public static void setUpClass() throws IOException { + public static void setUpClass() { Config config = ConfigFactory.parseMap(ImmutableMap.builder() .put("akka.actor.default-dispatcher.type", @@ -164,7 +165,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { } @AfterClass - public static void tearDownClass() throws IOException { + public static void tearDownClass() { TestKit.shutdownActorSystem(system); system = null; } @@ -386,23 +387,15 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest { shardName); } - @SuppressWarnings("checkstyle:avoidHidingCauseException") - protected void propagateReadFailedExceptionCause(final CheckedFuture future) - throws Exception { + @SuppressWarnings({"checkstyle:avoidHidingCauseException", "checkstyle:IllegalThrows"}) + protected void propagateReadFailedExceptionCause(final FluentFuture future) throws Throwable { try { - future.checkedGet(5, TimeUnit.SECONDS); + future.get(5, TimeUnit.SECONDS); fail("Expected ReadFailedException"); - } catch (ReadFailedException e) { - assertNotNull("Expected a cause", e.getCause()); - Throwable cause; - if (e.getCause().getCause() != null) { - cause = e.getCause().getCause(); - } else { - cause = e.getCause(); - } - - Throwables.propagateIfPossible(cause, Exception.class); - throw new RuntimeException(cause); + } catch (ExecutionException e) { + final Throwable cause = e.getCause(); + assertTrue("Unexpected cause: " + cause.getClass(), cause instanceof ReadFailedException); + throw Throwables.getRootCause(cause); } }