Fix warnings in sal-akka-raft test classes
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / MockRaftActor.java
index 88865d55bdf39a16891a3c59734aa4e1edf79ef2..b4b558b6f357a908c8ac537dd80e86c3abdd5eca 100644 (file)
@@ -10,10 +10,12 @@ package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
+
 import akka.actor.ActorRef;
 import akka.actor.Props;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
+import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -56,7 +58,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         this.snapshotCohortDelegate = builder.snapshotCohort != null ? builder.snapshotCohort :
             mock(RaftActorSnapshotCohort.class);
 
-        if(builder.dataPersistenceProvider == null){
+        if (builder.dataPersistenceProvider == null) {
             setPersistence(builder.persistent.isPresent() ? builder.persistent.get() : true);
         } else {
             setPersistence(builder.dataPersistenceProvider);
@@ -91,7 +93,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         try {
             assertEquals("Recovery complete", true, recoveryComplete.await(5,  TimeUnit.SECONDS));
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            Throwables.propagate(e);
         }
     }
 
@@ -99,14 +101,14 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         try {
             assertEquals("Behavior initialized", true, initializeBehaviorComplete.await(5,  TimeUnit.SECONDS));
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            Throwables.propagate(e);
         }
     }
 
 
-    public void waitUntilLeader(){
-        for(int i = 0;i < 10; i++){
-            if(isLeader()){
+    public void waitUntilLeader() {
+        for (int i = 0; i < 10; i++) {
+            if (isLeader()) {
                 break;
             }
             Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
@@ -168,14 +170,18 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
     }
 
     private void applySnapshotBytes(byte[] bytes) {
+        if (bytes.length == 0) {
+            return;
+        }
+
         try {
             Object data = toObject(bytes);
             if (data instanceof List) {
                 state.clear();
                 state.addAll((List<?>) data);
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (ClassNotFoundException | IOException e) {
+            Throwables.propagate(e);
         }
     }
 
@@ -212,12 +218,12 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
 
     @Override
     protected void handleCommand(final Object message) {
-        if(message instanceof RaftActorBehavior) {
+        if (message instanceof RaftActorBehavior) {
             super.changeCurrentBehavior((RaftActorBehavior)message);
         } else {
             super.handleCommand(message);
 
-            if(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT.equals(message)) {
+            if (RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT.equals(message)) {
                 snapshotCommitted.countDown();
             }
         }
@@ -225,7 +231,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
 
     @Override
     protected void pauseLeader(Runnable operation) {
-        if(pauseLeaderFunction != null) {
+        if (pauseLeaderFunction != null) {
             pauseLeaderFunction.apply(operation);
         } else {
             super.pauseLeader(operation);
@@ -251,7 +257,7 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         return obj;
     }
 
-    public ReplicatedLog getReplicatedLog(){
+    public ReplicatedLog getReplicatedLog() {
         return this.getRaftActorContext().getReplicatedLog();
     }
 
@@ -260,15 +266,14 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         return restoreFromSnapshot;
     }
 
-    public static Props props(final String id, final Map<String, String> peerAddresses,
-            ConfigParams config){
+    public static Props props(final String id, final Map<String, String> peerAddresses, ConfigParams config) {
         return builder().id(id).peerAddresses(peerAddresses).config(config).props();
     }
 
     public static Props props(final String id, final Map<String, String> peerAddresses,
-                              ConfigParams config, DataPersistenceProvider dataPersistenceProvider){
-        return builder().id(id).peerAddresses(peerAddresses).config(config).
-                dataPersistenceProvider(dataPersistenceProvider).props();
+                              ConfigParams config, DataPersistenceProvider dataPersistenceProvider) {
+        return builder().id(id).peerAddresses(peerAddresses).config(config)
+                .dataPersistenceProvider(dataPersistenceProvider).props();
     }
 
     public static Builder builder() {
@@ -297,53 +302,53 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
             return (T) this;
         }
 
-        public T id(String id) {
-            this.id = id;
+        public T id(String newId) {
+            this.id = newId;
             return self();
         }
 
-        public T peerAddresses(Map<String, String> peerAddresses) {
-            this.peerAddresses = peerAddresses;
+        public T peerAddresses(Map<String, String> newPeerAddresses) {
+            this.peerAddresses = newPeerAddresses;
             return self();
         }
 
-        public T config(ConfigParams config) {
-            this.config = config;
+        public T config(ConfigParams newConfig) {
+            this.config = newConfig;
             return self();
         }
 
-        public T dataPersistenceProvider(DataPersistenceProvider dataPersistenceProvider) {
-            this.dataPersistenceProvider = dataPersistenceProvider;
+        public T dataPersistenceProvider(DataPersistenceProvider newDataPersistenceProvider) {
+            this.dataPersistenceProvider = newDataPersistenceProvider;
             return self();
         }
 
-        public T roleChangeNotifier(ActorRef roleChangeNotifier) {
-            this.roleChangeNotifier = roleChangeNotifier;
+        public T roleChangeNotifier(ActorRef newRoleChangeNotifier) {
+            this.roleChangeNotifier = newRoleChangeNotifier;
             return self();
         }
 
-        public T snapshotMessageSupport(RaftActorSnapshotMessageSupport snapshotMessageSupport) {
-            this.snapshotMessageSupport = snapshotMessageSupport;
+        public T snapshotMessageSupport(RaftActorSnapshotMessageSupport newSnapshotMessageSupport) {
+            this.snapshotMessageSupport = newSnapshotMessageSupport;
             return self();
         }
 
-        public T restoreFromSnapshot(byte[] restoreFromSnapshot) {
-            this.restoreFromSnapshot = restoreFromSnapshot;
+        public T restoreFromSnapshot(byte[] newRestoreFromSnapshot) {
+            this.restoreFromSnapshot = newRestoreFromSnapshot;
             return self();
         }
 
-        public T persistent(Optional<Boolean> persistent) {
-            this.persistent = persistent;
+        public T persistent(Optional<Boolean> newPersistent) {
+            this.persistent = newPersistent;
             return self();
         }
 
-        public T pauseLeaderFunction(Function<Runnable, Void> pauseLeaderFunction) {
-            this.pauseLeaderFunction = pauseLeaderFunction;
+        public T pauseLeaderFunction(Function<Runnable, Void> newPauseLeaderFunction) {
+            this.pauseLeaderFunction = newPauseLeaderFunction;
             return self();
         }
 
-        public T snapshotCohort(RaftActorSnapshotCohort snapshotCohort) {
-            this.snapshotCohort = snapshotCohort;
+        public T snapshotCohort(RaftActorSnapshotCohort newSnapshotCohort) {
+            this.snapshotCohort = newSnapshotCohort;
             return self();
         }