X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardTestKit.java;h=8f3231b4179ce2c3b086fe083c61fcf55f084574;hb=4aafd13eccad285b5bb3ee277b0fb0b8721612bc;hp=ae607b9b3da214094d44833de1aea900ecb36d69;hpb=6050fd28f2def659abb5bc9d7127eb748b5fb32a;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java index ae607b9b3d..8f3231b417 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java @@ -46,7 +46,7 @@ public class ShardTestKit extends JavaTestKit { } - public String waitUntilLeader(ActorRef shard) { + public static String waitUntilLeader(ActorRef shard) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); for(int i = 0; i < 20 * 5; i++) { Future future = Patterns.ask(shard, new FindLeader(), new Timeout(duration)); @@ -71,6 +71,7 @@ public class ShardTestKit extends JavaTestKit { public void waitUntilNoLeader(ActorRef shard) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); + Object lastResponse = null; for(int i = 0; i < 20 * 5; i++) { Future future = Patterns.ask(shard, new FindLeader(), new Timeout(duration)); try { @@ -78,16 +79,25 @@ public class ShardTestKit extends JavaTestKit { if(resp.getLeaderActor() == null) { return; } + + lastResponse = resp.getLeaderActor(); } catch(TimeoutException e) { + lastResponse = e; } catch(Exception e) { System.err.println("FindLeader threw ex"); e.printStackTrace(); + lastResponse = e; } - Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); } - Assert.fail("Unexpected leader found for shard " + shard.path()); + if(lastResponse instanceof Throwable) { + throw (AssertionError)new AssertionError( + String.format("Unexpected error occurred from FindLeader for shard %s", shard.path())). + initCause((Throwable)lastResponse); + } + + Assert.fail(String.format("Unexpected leader %s found for shard %s", lastResponse, shard.path())); } } \ No newline at end of file