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%2Fdatabroker%2Factors%2Fdds%2FVotingFutureTest.java;h=c2c55a4a73c678a2341aeb15d3f6a01603844fd0;hp=85d6582ecfd93e89ed15e50dfb3b3b7942c5cec5;hb=ddb42663a4a53d8440d33f955a5944184f3b602d;hpb=a6ee12d91ddadc775123a40a11c3a3bae7373ebe diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFutureTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFutureTest.java index 85d6582ecf..c2c55a4a73 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFutureTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFutureTest.java @@ -7,6 +7,10 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; +import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertFutureEquals; +import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException; +import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.getWithTimeout; + import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -20,8 +24,6 @@ import org.junit.Test; public class VotingFutureTest { - private static final int TIMEOUT = 3; - private Object result; private ScheduledExecutorService executor; private VotingFuture future; @@ -42,7 +44,7 @@ public class VotingFutureTest { public void testTrivialCases() throws Exception { final VotingFuture oneYesVoteFuture = new VotingFuture<>(result, 1); oneYesVoteFuture.voteYes(); - checkSuccess(oneYesVoteFuture, result); + assertFutureEquals(result, oneYesVoteFuture); final VotingFuture oneNoVoteFuture = new VotingFuture<>(result, 1); final RuntimeException cause = new RuntimeException("fail"); oneNoVoteFuture.voteNo(cause); @@ -54,7 +56,7 @@ public class VotingFutureTest { future.voteYes(); future.voteYes(); future.voteYes(); - checkSuccess(future, result); + assertFutureEquals(result, future); } @Test @@ -66,7 +68,7 @@ public class VotingFutureTest { voted.set(true); future.voteYes(); }, 1, TimeUnit.SECONDS); - checkSuccess(future, result); + assertFutureEquals(result, future); Assert.assertTrue("Future completed before vote", voted.get()); } @@ -118,30 +120,18 @@ public class VotingFutureTest { final RuntimeException cause2 = new RuntimeException("fail"); future.voteNo(cause1); future.voteNo(cause2); - try { - future.get(TIMEOUT, TimeUnit.SECONDS); - Assert.fail("ExecutionException expected"); - } catch (final ExecutionException e) { - //first no is set as cause - Assert.assertEquals(cause1, e.getCause()); - //subsequent no causes are added as suppressed - final Throwable[] suppressed = e.getCause().getSuppressed(); - Assert.assertEquals(1, suppressed.length); - Assert.assertEquals(cause2, suppressed[0]); - } - } - - private static void checkException(final Future future, final RuntimeException cause) throws Exception { - try { - future.get(TIMEOUT, TimeUnit.SECONDS); - Assert.fail("ExecutionException expected"); - } catch (final ExecutionException e) { - Assert.assertEquals(cause, e.getCause()); - } + final Throwable thrown = assertOperationThrowsException(() -> getWithTimeout(future), ExecutionException.class); + //first no is set as cause + Assert.assertEquals(cause1, thrown.getCause()); + //subsequent no causes are added as suppressed + final Throwable[] suppressed = thrown.getCause().getSuppressed(); + Assert.assertEquals(1, suppressed.length); + Assert.assertEquals(cause2, suppressed[0]); } - private static void checkSuccess(final Future future, final Object result) throws Exception { - Assert.assertEquals(result, future.get(TIMEOUT, TimeUnit.SECONDS)); + private static void checkException(final Future future, final RuntimeException cause) throws Exception { + final Throwable thrown = assertOperationThrowsException(() -> getWithTimeout(future), ExecutionException.class); + Assert.assertEquals(cause, thrown.getCause()); } } \ No newline at end of file