X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FMockRaftActor.java;h=61a673057d48dd19379905571e5724f83ad2407f;hb=4842cd28aa49cdd492d7c49ed06fef00208e1cd7;hp=ae26383283e00b12b3a4c72eb7c955519f61f937;hpb=aafb8cb044e992dd784d1f4f66508599cc4cd588;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java index ae26383283..61a673057d 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java @@ -15,7 +15,6 @@ import akka.actor.ActorRef; import akka.actor.Props; import com.google.common.base.Function; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.common.io.ByteSource; import com.google.common.util.concurrent.Uninterruptibles; import java.io.IOException; @@ -26,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.annotation.Nonnull; import org.apache.commons.lang3.SerializationUtils; import org.opendaylight.controller.cluster.DataPersistenceProvider; import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior; @@ -50,10 +48,10 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, final CountDownLatch snapshotCommitted = new CountDownLatch(1); private final Function pauseLeaderFunction; - protected MockRaftActor(AbstractBuilder builder) { + protected MockRaftActor(final AbstractBuilder builder) { super(builder.id, builder.peerAddresses != null ? builder.peerAddresses : Collections.emptyMap(), Optional.fromNullable(builder.config), PAYLOAD_VERSION); - state = new ArrayList<>(); + state = Collections.synchronizedList(new ArrayList<>()); this.actorDelegate = mock(RaftActor.class); this.recoveryCohortDelegate = mock(RaftActorRecoveryCohort.class); @@ -72,7 +70,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, pauseLeaderFunction = builder.pauseLeaderFunction; } - public void setRaftActorRecoverySupport(RaftActorRecoverySupport support) { + public void setRaftActorRecoverySupport(final RaftActorRecoverySupport support) { raftActorRecoverySupport = support; } @@ -100,7 +98,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, try { assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS)); } catch (InterruptedException e) { - Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -108,7 +106,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, try { assertEquals("Behavior initialized", true, initializeBehaviorComplete.await(5, TimeUnit.SECONDS)); } catch (InterruptedException e) { - Throwables.propagate(e); + throw new RuntimeException(e); } } @@ -127,7 +125,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - protected void applyState(ActorRef clientActor, Identifier identifier, Object data) { + protected void applyState(final ActorRef clientActor, final Identifier identifier, final Object data) { actorDelegate.applyState(clientActor, identifier, data); LOG.info("{}: applyState called: {}", persistenceId(), data); @@ -135,7 +133,6 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - @Nonnull protected RaftActorRecoveryCohort getRaftActorRecoveryCohort() { return this; } @@ -146,11 +143,11 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public void startLogRecoveryBatch(int maxBatchSize) { + public void startLogRecoveryBatch(final int maxBatchSize) { } @Override - public void appendRecoveredLogEntry(Payload data) { + public void appendRecoveredLogEntry(final Payload data) { state.add(data); } @@ -171,12 +168,12 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public void applyRecoverySnapshot(Snapshot.State newState) { + public void applyRecoverySnapshot(final Snapshot.State newState) { recoveryCohortDelegate.applyRecoverySnapshot(newState); applySnapshotState(newState); } - private void applySnapshotState(Snapshot.State newState) { + private void applySnapshotState(final Snapshot.State newState) { if (newState instanceof MockSnapshotState) { state.clear(); state.addAll(((MockSnapshotState)newState).getState()); @@ -184,20 +181,20 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public void createSnapshot(ActorRef actorRef, java.util.Optional installSnapshotStream) { + public void createSnapshot(final ActorRef actorRef, final java.util.Optional installSnapshotStream) { LOG.info("{}: createSnapshot called", persistenceId()); snapshotCohortDelegate.createSnapshot(actorRef, installSnapshotStream); } @Override - public void applySnapshot(Snapshot.State newState) { + public void applySnapshot(final Snapshot.State newState) { LOG.info("{}: applySnapshot called", persistenceId()); applySnapshotState(newState); snapshotCohortDelegate.applySnapshot(newState); } @Override - public Snapshot.State deserializeSnapshot(ByteSource snapshotBytes) { + public Snapshot.State deserializeSnapshot(final ByteSource snapshotBytes) { try { return (Snapshot.State) SerializationUtils.deserialize(snapshotBytes.read()); } catch (IOException e) { @@ -205,11 +202,6 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } } - @Override - public Snapshot.State deserializePreCarbonSnapshot(byte[] from) { - return new MockSnapshotState(SerializationUtils.deserialize(from)); - } - @Override protected void onStateChanged() { actorDelegate.onStateChanged(); @@ -224,7 +216,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, return this.getId(); } - protected void newBehavior(RaftActorBehavior newBehavior) { + protected void newBehavior(final RaftActorBehavior newBehavior) { self().tell(newBehavior, ActorRef.noSender()); } @@ -242,7 +234,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - protected void pauseLeader(Runnable operation) { + protected void pauseLeader(final Runnable operation) { if (pauseLeaderFunction != null) { pauseLeaderFunction.apply(operation); } else { @@ -250,7 +242,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } } - public static List fromState(Snapshot.State from) { + public static List fromState(final Snapshot.State from) { if (from instanceof MockSnapshotState) { return ((MockSnapshotState)from).getState(); } @@ -267,12 +259,12 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, return restoreFromSnapshot; } - public static Props props(final String id, final Map peerAddresses, ConfigParams config) { + public static Props props(final String id, final Map peerAddresses, final ConfigParams config) { return builder().id(id).peerAddresses(peerAddresses).config(config).props(); } public static Props props(final String id, final Map peerAddresses, - ConfigParams config, DataPersistenceProvider dataPersistenceProvider) { + final ConfigParams config, final DataPersistenceProvider dataPersistenceProvider) { return builder().id(id).peerAddresses(peerAddresses).config(config) .dataPersistenceProvider(dataPersistenceProvider).props(); } @@ -294,7 +286,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, private Function pauseLeaderFunction; private RaftActorSnapshotCohort snapshotCohort; - protected AbstractBuilder(Class actorClass) { + protected AbstractBuilder(final Class actorClass) { this.actorClass = actorClass; } @@ -303,52 +295,52 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, return (T) this; } - public T id(String newId) { + public T id(final String newId) { this.id = newId; return self(); } - public T peerAddresses(Map newPeerAddresses) { + public T peerAddresses(final Map newPeerAddresses) { this.peerAddresses = newPeerAddresses; return self(); } - public T config(ConfigParams newConfig) { + public T config(final ConfigParams newConfig) { this.config = newConfig; return self(); } - public T dataPersistenceProvider(DataPersistenceProvider newDataPersistenceProvider) { + public T dataPersistenceProvider(final DataPersistenceProvider newDataPersistenceProvider) { this.dataPersistenceProvider = newDataPersistenceProvider; return self(); } - public T roleChangeNotifier(ActorRef newRoleChangeNotifier) { + public T roleChangeNotifier(final ActorRef newRoleChangeNotifier) { this.roleChangeNotifier = newRoleChangeNotifier; return self(); } - public T snapshotMessageSupport(RaftActorSnapshotMessageSupport newSnapshotMessageSupport) { + public T snapshotMessageSupport(final RaftActorSnapshotMessageSupport newSnapshotMessageSupport) { this.snapshotMessageSupport = newSnapshotMessageSupport; return self(); } - public T restoreFromSnapshot(Snapshot newRestoreFromSnapshot) { + public T restoreFromSnapshot(final Snapshot newRestoreFromSnapshot) { this.restoreFromSnapshot = newRestoreFromSnapshot; return self(); } - public T persistent(Optional newPersistent) { + public T persistent(final Optional newPersistent) { this.persistent = newPersistent; return self(); } - public T pauseLeaderFunction(Function newPauseLeaderFunction) { + public T pauseLeaderFunction(final Function newPauseLeaderFunction) { this.pauseLeaderFunction = newPauseLeaderFunction; return self(); } - public T snapshotCohort(RaftActorSnapshotCohort newSnapshotCohort) { + public T snapshotCohort(final RaftActorSnapshotCohort newSnapshotCohort) { this.snapshotCohort = newSnapshotCohort; return self(); } @@ -359,7 +351,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } public static class Builder extends AbstractBuilder { - private Builder() { + Builder() { super(MockRaftActor.class); } } @@ -369,7 +361,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, private final List state; - public MockSnapshotState(List state) { + public MockSnapshotState(final List state) { this.state = state; } @@ -386,7 +378,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort, } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; }