import static org.mockito.Mockito.mock;
import akka.actor.ActorRef;
import akka.actor.Props;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.ByteArrayInputStream;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, RaftActorSnapshotCohort {
-
public static final short PAYLOAD_VERSION = 5;
final RaftActor actorDelegate;
private RaftActorSnapshotMessageSupport snapshotMessageSupport;
private final byte[] restoreFromSnapshot;
final CountDownLatch snapshotCommitted = new CountDownLatch(1);
+ private final Function<Runnable, Void> pauseLeaderFunction;
protected MockRaftActor(AbstractBuilder<?, ?> builder) {
super(builder.id, builder.peerAddresses, Optional.fromNullable(builder.config), PAYLOAD_VERSION);
roleChangeNotifier = builder.roleChangeNotifier;
snapshotMessageSupport = builder.snapshotMessageSupport;
restoreFromSnapshot = builder.restoreFromSnapshot;
+ pauseLeaderFunction = builder.pauseLeaderFunction;
}
public void setRaftActorRecoverySupport(RaftActorRecoverySupport support) {
}
}
+ @Override
+ protected void pauseLeader(Runnable operation) {
+ if(pauseLeaderFunction != null) {
+ pauseLeaderFunction.apply(operation);
+ } else {
+ super.pauseLeader(operation);
+ }
+ }
+
public static Object toObject(byte[] bs) throws ClassNotFoundException, IOException {
Object obj = null;
ByteArrayInputStream bis = null;
private byte[] restoreFromSnapshot;
private Optional<Boolean> persistent = Optional.absent();
private final Class<A> actorClass;
+ private Function<Runnable, Void> pauseLeaderFunction;
protected AbstractBuilder(Class<A> actorClass) {
this.actorClass = actorClass;
return self();
}
+ public T pauseLeaderFunction(Function<Runnable, Void> pauseLeaderFunction) {
+ this.pauseLeaderFunction = pauseLeaderFunction;
+ return self();
+ }
+
public Props props() {
return Props.create(actorClass, this);
}