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%2FIntegrationTestKit.java;h=c3d216be9ca9d144c51741194c06bb0550919549;hb=6313c088fc7db266cc25b691e0cd909300fc8425;hp=ada0fba10eb5227f8bb2860ead76a600ccfaa7a4;hpb=88f763ec4ec2bcc1e0fd414ccb2f105f7490b8e9;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java index ada0fba10e..c3d216be9c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java @@ -14,6 +14,7 @@ import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.PoisonPill; import com.google.common.base.Optional; +import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.Callable; @@ -22,6 +23,7 @@ import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl; +import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; @@ -32,6 +34,9 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; 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; +import scala.concurrent.Await; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; public class IntegrationTestKit extends ShardTestKit { @@ -92,7 +97,7 @@ public class IntegrationTestKit extends ShardTestKit { for(String shardName: shardNames) { ActorRef shard = findLocalShard(actorContext, shardName); - assertNotNull("Shard was not created", shard); + assertNotNull("Shard was not created for " + shardName, shard); waitUntilLeader(shard); } @@ -101,13 +106,13 @@ public class IntegrationTestKit extends ShardTestKit { public void waitUntilNoLeader(ActorContext actorContext, String... shardNames) { for(String shardName: shardNames) { ActorRef shard = findLocalShard(actorContext, shardName); - assertNotNull("No local shard found", shard); + assertNotNull("No local shard found for " + shardName, shard); waitUntilNoLeader(shard); } } - private static ActorRef findLocalShard(ActorContext actorContext, String shardName) { + public static ActorRef findLocalShard(ActorContext actorContext, String shardName) { ActorRef shard = null; for(int i = 0; i < 20 * 5 && shard == null; i++) { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); @@ -119,6 +124,31 @@ public class IntegrationTestKit extends ShardTestKit { return shard; } + public static void verifyShardStats(DistributedDataStore datastore, String shardName, ShardStatsVerifier verifier) + throws Exception { + ActorContext actorContext = datastore.getActorContext(); + + Future future = actorContext.findLocalShardAsync(shardName); + ActorRef shardActor = Await.result(future, Duration.create(10, TimeUnit.SECONDS)); + + AssertionError lastError = null; + Stopwatch sw = Stopwatch.createStarted(); + while(sw.elapsed(TimeUnit.SECONDS) <= 5) { + ShardStats shardStats = (ShardStats)actorContext. + executeOperation(shardActor, Shard.GET_SHARD_MBEAN_MESSAGE); + + try { + verifier.verify(shardStats); + return; + } catch (AssertionError e) { + lastError = e; + Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); + } + } + + throw lastError; + } + void testWriteTransaction(DistributedDataStore dataStore, YangInstanceIdentifier nodePath, NormalizedNode nodeToWrite) throws Exception { @@ -204,4 +234,8 @@ public class IntegrationTestKit extends ShardTestKit { } }, expType); } + + public interface ShardStatsVerifier { + void verify(ShardStats stats); + } }