import org.opendaylight.controller.cluster.raft.behaviors.Leader;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
import org.opendaylight.yangtools.concepts.Identifier;
-import org.opendaylight.yangtools.util.StringIdentifier;
+import org.opendaylight.yangtools.util.AbstractStringIdentifier;
/**
* A sample actor showing how the RaftActor is to be extended
*/
public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort, RaftActorSnapshotCohort {
+ private static final class PayloadIdentifier extends AbstractStringIdentifier<PayloadIdentifier> {
+ private static final long serialVersionUID = 1L;
+
+ PayloadIdentifier(final long identifier) {
+ super(String.valueOf(identifier));
+ }
+ }
private final Map<String, String> state = new HashMap<>();
protected void handleNonRaftCommand(Object message) {
if(message instanceof KeyValue){
if(isLeader()) {
- persistData(getSender(), new StringIdentifier(String.valueOf(persistIdentifier++)), (Payload) message);
+ persistData(getSender(), new PayloadIdentifier(persistIdentifier++), (Payload) message);
} else {
if(getLeader() != null) {
getLeader().forward(message, getContext());
import org.opendaylight.controller.cluster.raft.messages.UnInitializedFollowerSnapshotReply;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
import org.opendaylight.yangtools.concepts.Identifier;
-import org.opendaylight.yangtools.util.UUIDIdentifier;
+import org.opendaylight.yangtools.util.AbstractUUIDIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.duration.FiniteDuration;
}
}
+ private static final class ServerOperationContextIdentifier extends AbstractUUIDIdentifier<ServerOperationContextIdentifier> {
+ private static final long serialVersionUID = 1L;
+
+ ServerOperationContextIdentifier() {
+ super(UUID.randomUUID());
+ }
+ }
+
/**
* Stores context information for a server operation.
*
ServerOperationContext(T operation, ActorRef clientRequestor){
this.operation = operation;
this.clientRequestor = clientRequestor;
- contextId = new UUIDIdentifier(UUID.randomUUID());
+ contextId = new ServerOperationContextIdentifier();
}
Identifier getContextId() {
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-
+import org.opendaylight.yangtools.util.AbstractStringIdentifier;
import java.io.File;
import java.io.IOException;
public abstract class AbstractActorTest {
+ protected static final class MockIdentifier extends AbstractStringIdentifier<MockIdentifier> {
+ private static final long serialVersionUID = 1L;
+
+ public MockIdentifier(final String string) {
+ super(string);
+ }
+ }
+
private static ActorSystem system;
@BeforeClass
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
import org.opendaylight.yangtools.concepts.Identifier;
-import org.opendaylight.yangtools.util.StringIdentifier;
+import org.opendaylight.yangtools.util.AbstractStringIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.duration.FiniteDuration;
*/
public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest {
+ private static final class MockIdentifier extends AbstractStringIdentifier<MockIdentifier> {
+ private static final long serialVersionUID = 1L;
+
+ protected MockIdentifier(String string) {
+ super(string);
+ }
+ }
+
public static class SetPeerAddress {
private final String peerId;
private final String peerAddress;
public void handleCommand(Object message) {
if(message instanceof MockPayload) {
MockPayload payload = (MockPayload)message;
- super.persistData(collectorActor, new StringIdentifier(payload.toString()), payload);
+ super.persistData(collectorActor, new MockIdentifier(payload.toString()), payload);
return;
}
String expId, long expTerm, long expIndex, MockPayload payload) {
assertEquals("ApplyState getClientActor", expClientActor, applyState.getClientActor());
- final Identifier id = expId == null ? null : new StringIdentifier(expId);
+ final Identifier id = expId == null ? null : new MockIdentifier(expId);
assertEquals("ApplyState getIdentifier", id, applyState.getIdentifier());
ReplicatedLogEntry replicatedLogEntry = applyState.getReplicatedLogEntry();
verifyReplicatedLogEntry(replicatedLogEntry, expTerm, expIndex, payload);
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
import org.opendaylight.yangtools.concepts.Identifier;
-import org.opendaylight.yangtools.util.StringIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.duration.Duration;
ReplicatedLogEntry entry = new MockRaftActorContext.MockReplicatedLogEntry(1, 5,
new MockRaftActorContext.MockPayload("F"));
- final Identifier id = new StringIdentifier("apply-state");
+ final Identifier id = new MockIdentifier("apply-state");
mockRaftActor.onReceiveCommand(new ApplyState(mockActorRef, id, entry));
verify(mockRaftActor.actorDelegate).applyState(eq(mockActorRef), eq(id), anyObject());
assertEquals(RaftState.Leader, leaderActor.getCurrentBehavior().state());
// Persist another entry (this will cause a CaptureSnapshot to be triggered
- leaderActor.persistData(mockActorRef, new StringIdentifier("x"),
+ leaderActor.persistData(mockActorRef, new MockIdentifier("x"),
new MockRaftActorContext.MockPayload("duh"));
// Now send a CaptureSnapshotReply
import org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
import org.opendaylight.yangtools.concepts.Identifier;
-import org.opendaylight.yangtools.util.StringIdentifier;
import scala.concurrent.duration.FiniteDuration;
public class LeaderTest extends AbstractLeaderTest<Leader> {
actorContext.getReplicatedLog().append(newEntry);
- final Identifier id = new StringIdentifier("state-id");
+ final Identifier id = new MockIdentifier("state-id");
RaftActorBehavior raftBehavior = leader.handleMessage(leaderActor, new Replicate(leaderActor, id, newEntry));
// State should not change
// this should invoke a sendinstallsnapshot as followersLastIndex < snapshotIndex
RaftActorBehavior raftBehavior = leader.handleMessage(
- leaderActor, new Replicate(null, new StringIdentifier("state-id"), entry));
+ leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry));
assertTrue(raftBehavior instanceof Leader);
//update follower timestamp
leader.markFollowerActive(FOLLOWER_ID);
- leader.handleMessage(leaderActor, new Replicate(null, new StringIdentifier("state-id"), entry));
+ leader.handleMessage(leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry));
assertEquals("isCapturing", true, actorContext.getSnapshotManager().isCapturing());
assertEquals(2, cs.getLastTerm());
// if an initiate is started again when first is in progress, it shouldnt initiate Capture
- leader.handleMessage(leaderActor, new Replicate(null, new StringIdentifier("state-id"), entry));
+ leader.handleMessage(leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry));
assertSame("CaptureSnapshot instance", cs, actorContext.getSnapshotManager().getCaptureSnapshot());
}
assertEquals(2, cs.getLastTerm());
// if an initiate is started again when first is in progress, it should not initiate Capture
- leader.handleMessage(leaderActor, new Replicate(null, new StringIdentifier("state-id"), entry));
+ leader.handleMessage(leaderActor, new Replicate(null, new MockIdentifier("state-id"), entry));
assertSame("CaptureSnapshot instance", cs, actorContext.getSnapshotManager().getCaptureSnapshot());
}