Fix warnings in sal-akka-raft test classes
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / TestActorFactory.java
index 0b709aa038d5e12ad4a897c95a7aa5b448feb451..92b401581c3721bd8d978d1b0faf33f712c7d70d 100644 (file)
@@ -41,7 +41,8 @@ import scala.concurrent.Future;
 
 /**
  * TestActorFactory provides methods to create both normal and test actors and to kill them when the factory is closed
- * The ideal usage for TestActorFactory is with try with resources, <br/>
+ * The ideal usage for TestActorFactory is with try with resources.
+ * <p/>
  * For example <br/>
  * <pre>
  *     try (TestActorFactory factory = new TestActorFactory(getSystem())){
@@ -52,56 +53,73 @@ import scala.concurrent.Future;
  * </pre>
  */
 public class TestActorFactory implements AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(TestActorFactory.class);
+
     private final ActorSystem system;
     List<ActorRef> createdActors = new LinkedList<>();
-    Logger LOG = LoggerFactory.getLogger(getClass());
     private static int actorCount = 1;
 
-    public TestActorFactory(ActorSystem system){
+    public TestActorFactory(ActorSystem system) {
         this.system = system;
     }
 
     /**
-     * Create a normal actor with an auto-generated name
+     * Create a normal actor with an auto-generated name.
      *
-     * @param props
-     * @return
+     * @param props the actor Props
+     * @return the ActorRef
      */
-    public ActorRef createActor(Props props){
+    public ActorRef createActor(Props props) {
         ActorRef actorRef = system.actorOf(props);
         return addActor(actorRef);
     }
 
     /**
-     * Create a normal actor with the passed in name
-     * @param props
+     * Create a normal actor with the passed in name.
+     *
+     * @param props the actor Props
      * @param actorId name of actor
-     * @return
+     * @return the ActorRef
      */
-    public ActorRef createActor(Props props, String actorId){
+    public ActorRef createActor(Props props, String actorId) {
         ActorRef actorRef = system.actorOf(props, actorId);
         return addActor(actorRef);
     }
 
     /**
-     * Create a test actor with the passed in name
-     * @param props
-     * @param actorId
-     * @param <T>
-     * @return
+     * Create a test actor with the passed in name.
+     *
+     * @param props the actor Props
+     * @param actorId name of actor
+     * @param <T> the actor type
+     * @return the ActorRef
      */
     @SuppressWarnings("unchecked")
-    public <T extends Actor> TestActorRef<T> createTestActor(Props props, String actorId){
+    public <T extends Actor> TestActorRef<T> createTestActor(Props props, String actorId) {
         TestActorRef<T> actorRef = TestActorRef.create(system, props, actorId);
         return (TestActorRef<T>) addActor(actorRef);
     }
 
+    /**
+     * Create a test actor with an auto-generated name.
+     *
+     * @param props the actor Props
+     * @param <T> the actor type
+     * @return the TestActorRef
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends Actor> TestActorRef<T> createTestActor(Props props) {
+        TestActorRef<T> actorRef = TestActorRef.create(system, props);
+        return (TestActorRef<T>) addActor(actorRef);
+    }
+
     private <T extends ActorRef> ActorRef addActor(T actorRef) {
         createdActors.add(actorRef);
         verifyActorReady(actorRef);
         return actorRef;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void verifyActorReady(ActorRef actorRef) {
         // Sometimes we see messages go to dead letters soon after creation - it seems the actor isn't quite
         // in a state yet to receive messages or isn't actually created yet. This seems to happen with
@@ -111,7 +129,7 @@ public class TestActorFactory implements AutoCloseable {
         Timeout timeout = new Timeout(100, TimeUnit.MILLISECONDS);
         Throwable lastError = null;
         Stopwatch sw = Stopwatch.createStarted();
-        while(sw.elapsed(TimeUnit.SECONDS) <= 10) {
+        while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
             try {
                 ActorSelection actorSelection = system.actorSelection(actorRef.path().toString());
                 Future<Object> future = Patterns.ask(actorSelection, new Identify(""), timeout);
@@ -128,23 +146,12 @@ public class TestActorFactory implements AutoCloseable {
     }
 
     /**
-     * Create a test actor with an auto-generated name
-     * @param props
-     * @param <T>
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    public <T extends Actor> TestActorRef<T> createTestActor(Props props){
-        TestActorRef<T> actorRef = TestActorRef.create(system, props);
-        return (TestActorRef<T>) addActor(actorRef);
-    }
-
-    /**
-     * Generate a friendly but unique actor id/name
-     * @param prefix
-     * @return
+     * Generate a friendly but unique actor id/name.
+     *
+     * @param prefix the name prefix
+     * @return the actor name
      */
-    public String generateActorId(String prefix){
+    public String generateActorId(String prefix) {
         return prefix + actorCount++;
     }
 
@@ -152,26 +159,26 @@ public class TestActorFactory implements AutoCloseable {
         killActor(actor, kit, true);
     }
 
-    public String createTestActorPath(String actorId){
-        return "akka://test/user/" + actorId;
-    }
-
     private void killActor(ActorRef actor, JavaTestKit kit, boolean remove) {
         LOG.info("Killing actor {}", actor);
         kit.watch(actor);
         actor.tell(PoisonPill.getInstance(), ActorRef.noSender());
         kit.expectTerminated(JavaTestKit.duration("5 seconds"), actor);
 
-        if(remove) {
+        if (remove) {
             createdActors.remove(actor);
         }
     }
 
+    public String createTestActorPath(String actorId) {
+        return "akka://test/user/" + actorId;
+    }
+
     @Override
     public void close() {
         JavaTestKit kit = new JavaTestKit(system);
-        for(ActorRef actor : createdActors) {
+        for (ActorRef actor : createdActors) {
             killActor(actor, kit, false);
         }
     }
-}
\ No newline at end of file
+}