private Map<String, String> peerAddresses = new HashMap<>();
private ConfigParams configParams;
private boolean snapshotCaptureInitiated;
+ private SnapshotManager snapshotManager;
public MockRaftActorContext(){
- electionTerm = null;
-
- initReplicatedLog();
- }
-
- public MockRaftActorContext(String id, ActorSystem system, ActorRef actor){
- this.id = id;
- this.system = system;
- this.actor = actor;
-
- final String id1 = id;
electionTerm = new ElectionTerm() {
- /**
- * Identifier of the actor whose election term information this is
- */
- private final String id = id1;
private long currentTerm = 1;
private String votedFor = "";
};
configParams = new DefaultConfigParamsImpl();
+ }
+
+ public MockRaftActorContext(String id, ActorSystem system, ActorRef actor){
+ this();
+ this.id = id;
+ this.system = system;
+ this.actor = actor;
initReplicatedLog();
}
}
@Override
+ // FIXME : A lot of tests try to manipulate the replicated log by setting it using this method
+ // This is OK to do if the underlyingActor is not RafActor or a derived class. If not then you should not
+ // used this way to manipulate the log because the RaftActor actually has a field replicatedLog
+ // which it creates internally and sets on the RaftActorContext
+ // The only right way to manipulate the replicated log therefore is to get it from either the RaftActor
+ // or the RaftActorContext and modify the entries in there instead of trying to replace it by using this setter
+ // Simple assertion that will fail if you do so
+ // ReplicatedLog log = new ReplicatedLogImpl();
+ // raftActor.underlyingActor().getRaftActorContext().setReplicatedLog(log);
+ // assertEquals(log, raftActor.underlyingActor().getReplicatedLog())
public void setReplicatedLog(ReplicatedLog replicatedLog) {
this.replicatedLog = replicatedLog;
}
}
@Override
- public void setSnapshotCaptureInitiated(boolean snapshotCaptureInitiated) {
- this.snapshotCaptureInitiated = snapshotCaptureInitiated;
- }
-
- @Override
- public boolean isSnapshotCaptureInitiated() {
- return snapshotCaptureInitiated;
+ public SnapshotManager getSnapshotManager() {
+ if(this.snapshotManager == null){
+ this.snapshotManager = new SnapshotManager(this, getLogger());
+ }
+ return this.snapshotManager;
}
public void setConfigParams(ConfigParams configParams) {
public static class MockPayload extends Payload implements Serializable {
private static final long serialVersionUID = 3121380393130864247L;
private String value = "";
+ private int size;
- public MockPayload(){
-
+ public MockPayload() {
}
public MockPayload(String s) {
this.value = s;
+ size = value.length();
+ }
+
+ public MockPayload(String s, int size) {
+ this(s);
+ this.size = size;
}
@Override public Map<GeneratedMessage.GeneratedExtension, String> encode() {
@Override
public int size() {
- return value.length();
+ return size;
}
@Override public String getClientPayloadClassName() {