+
+ @Override
+ public Snapshot getRestoreFromSnapshot() {
+ return restoreFromSnapshot;
+ }
+
+ public static Props props(final String id, final Map<String, String> peerAddresses, final ConfigParams config) {
+ return builder().id(id).peerAddresses(peerAddresses).config(config).props();
+ }
+
+ public static Props props(final String id, final Map<String, String> peerAddresses,
+ final ConfigParams config, final DataPersistenceProvider dataPersistenceProvider) {
+ return builder().id(id).peerAddresses(peerAddresses).config(config)
+ .dataPersistenceProvider(dataPersistenceProvider).props();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class AbstractBuilder<T extends AbstractBuilder<T, A>, A extends MockRaftActor> {
+ private Map<String, String> peerAddresses = Collections.emptyMap();
+ private String id;
+ private ConfigParams config;
+ private DataPersistenceProvider dataPersistenceProvider;
+ private ActorRef roleChangeNotifier;
+ private RaftActorSnapshotMessageSupport snapshotMessageSupport;
+ private Snapshot restoreFromSnapshot;
+ private Optional<Boolean> persistent = Optional.absent();
+ private final Class<A> actorClass;
+ private Function<Runnable, Void> pauseLeaderFunction;
+ private RaftActorSnapshotCohort snapshotCohort;
+
+ protected AbstractBuilder(final Class<A> actorClass) {
+ this.actorClass = actorClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ private T self() {
+ return (T) this;
+ }
+
+ public T id(final String newId) {
+ this.id = newId;
+ return self();
+ }
+
+ public T peerAddresses(final Map<String, String> newPeerAddresses) {
+ this.peerAddresses = newPeerAddresses;
+ return self();
+ }
+
+ public T config(final ConfigParams newConfig) {
+ this.config = newConfig;
+ return self();
+ }
+
+ public T dataPersistenceProvider(final DataPersistenceProvider newDataPersistenceProvider) {
+ this.dataPersistenceProvider = newDataPersistenceProvider;
+ return self();
+ }
+
+ public T roleChangeNotifier(final ActorRef newRoleChangeNotifier) {
+ this.roleChangeNotifier = newRoleChangeNotifier;
+ return self();
+ }
+
+ public T snapshotMessageSupport(final RaftActorSnapshotMessageSupport newSnapshotMessageSupport) {
+ this.snapshotMessageSupport = newSnapshotMessageSupport;
+ return self();
+ }
+
+ public T restoreFromSnapshot(final Snapshot newRestoreFromSnapshot) {
+ this.restoreFromSnapshot = newRestoreFromSnapshot;
+ return self();
+ }
+
+ public T persistent(final Optional<Boolean> newPersistent) {
+ this.persistent = newPersistent;
+ return self();
+ }
+
+ public T pauseLeaderFunction(final Function<Runnable, Void> newPauseLeaderFunction) {
+ this.pauseLeaderFunction = newPauseLeaderFunction;
+ return self();
+ }
+
+ public T snapshotCohort(final RaftActorSnapshotCohort newSnapshotCohort) {
+ this.snapshotCohort = newSnapshotCohort;
+ return self();
+ }
+
+ public Props props() {
+ return Props.create(actorClass, this);
+ }
+ }
+
+ public static class Builder extends AbstractBuilder<Builder, MockRaftActor> {
+ Builder() {
+ super(MockRaftActor.class);
+ }
+ }
+
+ public static class MockSnapshotState implements Snapshot.State {
+ private static final long serialVersionUID = 1L;
+
+ private final List<Object> state;
+
+ public MockSnapshotState(final List<Object> state) {
+ this.state = state;
+ }
+
+ public List<Object> getState() {
+ return state;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (state == null ? 0 : state.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MockSnapshotState other = (MockSnapshotState) obj;
+ if (state == null) {
+ if (other.state != null) {
+ return false;
+ }
+ } else if (!state.equals(other.state)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "MockSnapshotState [state=" + state + "]";
+ }
+ }
+}