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%2FShardTest.java;h=431a266b148478a49766bd8f0cc173bc7b2e4062;hb=c74d5c2399e500fe3e690edc8cee497b1cb6f867;hp=ee112a40de9ed8c9869887e615629cc3076668de;hpb=aa16c6b860255d4509f240fbcb416b8d3d6c0232;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index ee112a40de..431a266b14 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -2,7 +2,9 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; +import akka.event.Logging; import akka.testkit.JavaTestKit; +import junit.framework.Assert; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain; @@ -38,19 +40,25 @@ public class ShardTest extends AbstractActorTest { getSystem().actorOf(props, "testCreateTransactionChain"); - // Wait for Shard to become a Leader - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + // Wait for a specific log message to show up + final boolean result = + new JavaTestKit.EventFilter(Logging.Info.class + ) { + protected Boolean run() { + return true; + } + }.from(subject.path().toString()) + .message("Switching from state Candidate to Leader") + .occurrences(1).exec(); + + Assert.assertEquals(true, result); new Within(duration("1 seconds")) { protected void run() { subject.tell(new CreateTransactionChain().toSerializable(), getRef()); - final String out = new ExpectMsg("match hint") { + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { // do not put code outside this method, will run afterwards protected String match(Object in) { if (in.getClass().equals(CreateTransactionChainReply.SERIALIZABLE_CLASS)){ @@ -91,7 +99,7 @@ public class ShardTest extends AbstractActorTest { getRef()); subject.tell(new RegisterChangeListener(TestModel.TEST_PATH, - getRef().path(), AsyncDataBroker.DataChangeScope.BASE).toSerializable(), + getRef().path(), AsyncDataBroker.DataChangeScope.BASE), getRef()); final Boolean notificationEnabled = new ExpectMsg("enable notification") { @@ -107,12 +115,12 @@ public class ShardTest extends AbstractActorTest { assertFalse(notificationEnabled); - final String out = new ExpectMsg("match hint") { + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { // do not put code outside this method, will run afterwards protected String match(Object in) { - if (in.getClass().equals(RegisterChangeListenerReply.SERIALIZABLE_CLASS)) { + if (in.getClass().equals(RegisterChangeListenerReply.class)) { RegisterChangeListenerReply reply = - RegisterChangeListenerReply.fromSerializable(getSystem(),in); + (RegisterChangeListenerReply) in; return reply.getListenerRegistrationPath() .toString(); } else { @@ -138,13 +146,18 @@ public class ShardTest extends AbstractActorTest { getSystem().actorOf(props, "testCreateTransaction"); - // Wait for Shard to become a Leader - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + // Wait for a specific log message to show up + final boolean result = + new JavaTestKit.EventFilter(Logging.Info.class + ) { + protected Boolean run() { + return true; + } + }.from(subject.path().toString()) + .message("Switching from state Candidate to Leader") + .occurrences(1).exec(); + Assert.assertEquals(true, result); new Within(duration("1 seconds")) { protected void run() { @@ -156,7 +169,7 @@ public class ShardTest extends AbstractActorTest { subject.tell(new CreateTransaction("txn-1", TransactionProxy.TransactionType.READ_ONLY.ordinal() ).toSerializable(), getRef()); - final String out = new ExpectMsg("match hint") { + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { // do not put code outside this method, will run afterwards protected String match(Object in) { if (in instanceof CreateTransactionReply) {