2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import java.util.concurrent.TimeUnit;
11 import org.junit.Assert;
12 import org.opendaylight.controller.cluster.raft.client.messages.FindLeader;
13 import org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply;
14 import com.google.common.util.concurrent.Uninterruptibles;
15 import scala.concurrent.Await;
16 import scala.concurrent.Future;
17 import scala.concurrent.duration.Duration;
18 import akka.actor.ActorRef;
19 import akka.actor.ActorSystem;
20 import akka.pattern.Patterns;
21 import akka.testkit.JavaTestKit;
22 import akka.util.Timeout;
24 class ShardTestKit extends JavaTestKit {
26 ShardTestKit(ActorSystem actorSystem) {
30 protected void waitForLogMessage(final Class logLevel, ActorRef subject, String logMessage){
31 // Wait for a specific log message to show up
32 final boolean result =
33 new JavaTestKit.EventFilter<Boolean>(logLevel
36 protected Boolean run() {
39 }.from(subject.path().toString())
41 .occurrences(1).exec();
43 Assert.assertEquals(true, result);
47 protected void waitUntilLeader(ActorRef shard) {
48 for(int i = 0; i < 20 * 5; i++) {
49 Future<Object> future = Patterns.ask(shard, new FindLeader(), new Timeout(5, TimeUnit.SECONDS));
51 FindLeaderReply resp = (FindLeaderReply)Await.result(future, Duration.create(5, TimeUnit.SECONDS));
52 if(resp.getLeaderActor() != null) {
55 } catch (Exception e) {
59 Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
62 Assert.fail("Leader not found for shard " + shard.path());