Document FindLeader message 04/34604/3
authorRobert Varga <rovarga@cisco.com>
Sat, 13 Feb 2016 20:48:08 +0000 (21:48 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 13 Feb 2016 21:33:53 +0000 (22:33 +0100)
Add Javadoc documentation and turn the message into a proper singleton,
as it does not currently hold any data.

Change-Id: Ib696b32234f048c4a9c7abb7a9972a00118219e5
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FindLeader.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java

index eebbde3393bfd75da5094a79eb77f3c1f1753d96..f99dc773c05f7be711a174413d9b9b1dd9286e9e 100644 (file)
@@ -8,9 +8,27 @@
 
 package org.opendaylight.controller.cluster.raft.client.messages;
 
 
 package org.opendaylight.controller.cluster.raft.client.messages;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.io.Serializable;
 
 import java.io.Serializable;
 
-public class FindLeader implements Serializable{
+/**
+ * Request to locate the leader raft actor. Each {@link org.opendaylight.controller.cluster.raft.RaftActor} must
+ * respond with a {@link FindLeaderReply} containing the address of the leader, as it is known to that particular
+ * actor.
+ *
+ * This message is intended for testing purposes only.
+ */
+@VisibleForTesting
+public final class FindLeader implements Serializable {
     private static final long serialVersionUID = 1L;
     private static final long serialVersionUID = 1L;
+    public static final FindLeader INSTANCE = new FindLeader();
+
+    private FindLeader() {
+        // Hidden to force reuse
+    }
 
 
+    @SuppressWarnings({ "static-method", "unused" })
+    private FindLeader readResolve() {
+        return INSTANCE;
+    }
 }
 }
index 815047423426e559b9099150f6c85d31aafe53ce..3d9214151f6302d26631d35d06f0f4d9266c77ef 100644 (file)
@@ -61,7 +61,7 @@ public class RaftActorTestKit extends JavaTestKit {
     public static void waitUntilLeader(ActorRef actorRef) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         for(int i = 0; i < 20 * 5; i++) {
     public static void waitUntilLeader(ActorRef actorRef) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         for(int i = 0; i < 20 * 5; i++) {
-            Future<Object> future = Patterns.ask(actorRef, new FindLeader(), new Timeout(duration));
+            Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
             try {
                 FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration);
                 if(resp.getLeaderActor() != null) {
             try {
                 FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration);
                 if(resp.getLeaderActor() != null) {
index c31acdad9361c2dd07053da257bbcf66eb11e3a5..d9d0b9bc8c7796b9a2c7c90ebced1e4136a15244 100644 (file)
@@ -230,7 +230,7 @@ public class ShardTest extends AbstractShardTest {
             assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
 
             // Sanity check - verify the shard is not the leader yet.
             assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
 
             // Sanity check - verify the shard is not the leader yet.
-            shard.tell(new FindLeader(), getRef());
+            shard.tell(FindLeader.INSTANCE, getRef());
             final FindLeaderReply findLeadeReply =
                     expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
             assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor());
             final FindLeaderReply findLeadeReply =
                     expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
             assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor());
@@ -329,7 +329,7 @@ public class ShardTest extends AbstractShardTest {
                 RegisterDataTreeChangeListenerReply.class);
             assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath());
 
                 RegisterDataTreeChangeListenerReply.class);
             assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath());
 
-            shard.tell(new FindLeader(), getRef());
+            shard.tell(FindLeader.INSTANCE, getRef());
             final FindLeaderReply findLeadeReply =
                     expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
             assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor());
             final FindLeaderReply findLeadeReply =
                     expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
             assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor());
index 8f3231b4179ce2c3b086fe083c61fcf55f084574..9df933b5bac75e84f13cbfbe3ec46e9bd9b0b3b8 100644 (file)
@@ -49,7 +49,7 @@ public class ShardTestKit extends JavaTestKit {
     public static String waitUntilLeader(ActorRef shard) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         for(int i = 0; i < 20 * 5; i++) {
     public static String waitUntilLeader(ActorRef shard) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         for(int i = 0; i < 20 * 5; i++) {
-            Future<Object> future = Patterns.ask(shard, new FindLeader(), new Timeout(duration));
+            Future<Object> future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration));
             try {
                 FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
                 if(resp.getLeaderActor() != null) {
             try {
                 FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
                 if(resp.getLeaderActor() != null) {
@@ -73,7 +73,7 @@ public class ShardTestKit extends JavaTestKit {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         Object lastResponse = null;
         for(int i = 0; i < 20 * 5; i++) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
         Object lastResponse = null;
         for(int i = 0; i < 20 * 5; i++) {
-            Future<Object> future = Patterns.ask(shard, new FindLeader(), new Timeout(duration));
+            Future<Object> future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration));
             try {
                 FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
                 if(resp.getLeaderActor() == null) {
             try {
                 FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
                 if(resp.getLeaderActor() == null) {