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 eebbde3..f99dc77 100644 (file)
@@ -8,9 +8,27 @@
 
 package org.opendaylight.controller.cluster.raft.client.messages;
 
+import com.google.common.annotations.VisibleForTesting;
 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;
+    public static final FindLeader INSTANCE = new FindLeader();
+
+    private FindLeader() {
+        // Hidden to force reuse
+    }
 
+    @SuppressWarnings({ "static-method", "unused" })
+    private FindLeader readResolve() {
+        return INSTANCE;
+    }
 }
index 8150474..3d92141 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++) {
-            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) {
index c31acda..d9d0b9b 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.
-            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());
@@ -329,7 +329,7 @@ public class ShardTest extends AbstractShardTest {
                 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());
index 8f3231b..9df933b 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++) {
-            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) {
@@ -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++) {
-            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) {