Use ActorSystem.terminate() 68/42668/2
authorRobert Varga <rovarga@cisco.com>
Thu, 28 Jul 2016 01:53:44 +0000 (03:53 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 28 Jul 2016 17:03:03 +0000 (17:03 +0000)
ActorSystem.shutdown() has been deprecated, move on
to the replacement call.

Change-Id: I21cee3100c84003585afd9c95706c26f686d0eec
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java

index c027de0..9fe8a13 100644 (file)
@@ -17,8 +17,8 @@ import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantLock;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import scala.concurrent.duration.FiniteDuration;
 
@@ -28,8 +28,8 @@ public class MeteredBoundedMailboxTest {
     private static CommonConfig config;
     private final ReentrantLock lock = new ReentrantLock();
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeClass
+    public static void setUp() throws Exception {
         config = new CommonConfig.Builder<>("testsystem").withConfigReader(new AkkaConfigurationReader() {
             @Override
             public Config read() {
@@ -39,11 +39,12 @@ public class MeteredBoundedMailboxTest {
         actorSystem = ActorSystem.create("testsystem", config.get());
     }
 
-    @After
-    public void tearDown() throws Exception {
-       if (actorSystem != null) {
-        actorSystem.shutdown();
-    }
+    @AfterClass
+    public static void tearDown() throws Exception {
+        if (actorSystem != null) {
+            actorSystem.terminate();
+            actorSystem = null;
+        }
     }
 
     @Test
@@ -81,7 +82,7 @@ public class MeteredBoundedMailboxTest {
 
         ReentrantLock lock;
 
-        private PingPongActor(ReentrantLock lock){
+        private PingPongActor(final ReentrantLock lock){
             this.lock = lock;
         }
 
@@ -90,7 +91,7 @@ public class MeteredBoundedMailboxTest {
         }
 
         @Override
-        public void onReceive(Object message) throws Exception {
+        public void onReceive(final Object message) throws Exception {
             lock.lock();
             try {
                 if ("ping".equals(message)) {
index 5970ea4..1ab6738 100644 (file)
@@ -26,6 +26,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import scala.concurrent.Await;
 import scala.concurrent.duration.Duration;
 
 public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseable {
@@ -70,7 +71,7 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
 
     @Override
     public ListenerRegistration<ActorSystemProviderListener> registerActorSystemProviderListener(
-            ActorSystemProviderListener listener) {
+            final ActorSystemProviderListener listener) {
         return listeners.register(listener);
     }
 
@@ -78,9 +79,8 @@ public class ActorSystemProviderImpl implements ActorSystemProvider, AutoCloseab
     public void close() {
         LOG.info("Shutting down ActorSystem");
 
-        actorSystem.shutdown();
         try {
-            actorSystem.awaitTermination(Duration.create(10, TimeUnit.SECONDS));
+            Await.result(actorSystem.terminate(), Duration.create(10, TimeUnit.SECONDS));
         } catch (Exception e) {
             LOG.warn("Error awaiting actor termination", e);
         }
index 3582302..0698f01 100644 (file)
@@ -79,13 +79,13 @@ public class ActorContextTest extends AbstractActorTest{
         private final ActorRef actorRef;
         private final Map<String,Object> findPrimaryResponses = Maps.newHashMap();
 
-        private MockShardManager(boolean found, ActorRef actorRef){
+        private MockShardManager(final boolean found, final ActorRef actorRef){
 
             this.found = found;
             this.actorRef = actorRef;
         }
 
-        @Override public void onReceive(Object message) throws Exception {
+        @Override public void onReceive(final Object message) throws Exception {
             if(message instanceof FindPrimary) {
                 FindPrimary fp = (FindPrimary)message;
                 Object resp = findPrimaryResponses.get(fp.getShardName());
@@ -105,7 +105,7 @@ public class ActorContextTest extends AbstractActorTest{
             }
         }
 
-        void addFindPrimaryResp(String shardName, Object resp) {
+        void addFindPrimaryResp(final String shardName, final Object resp) {
             findPrimaryResponses.put(shardName, resp);
         }
 
@@ -127,7 +127,7 @@ public class ActorContextTest extends AbstractActorTest{
                 this.actorRef = null;
             }
 
-            MockShardManagerCreator(boolean found, ActorRef actorRef) {
+            MockShardManagerCreator(final boolean found, final ActorRef actorRef) {
                 this.found = found;
                 this.actorRef = actorRef;
             }
@@ -300,7 +300,6 @@ public class ActorContextTest extends AbstractActorTest{
                         mock(Configuration.class), DatastoreContext.newBuilder().build(), new PrimaryShardInfoFutureCache());
 
         assertEquals(getSystem().dispatchers().defaultGlobalDispatcher(), actorContext.getClientDispatcher());
-
     }
 
     @Test
@@ -313,8 +312,7 @@ public class ActorContextTest extends AbstractActorTest{
 
         assertNotEquals(actorSystem.dispatchers().defaultGlobalDispatcher(), actorContext.getClientDispatcher());
 
-        actorSystem.shutdown();
-
+        actorSystem.terminate();
     }
 
     @Test
@@ -362,7 +360,7 @@ public class ActorContextTest extends AbstractActorTest{
                     new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class),
                             mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {
                         @Override
-                        protected Future<Object> doAsk(ActorRef actorRef, Object message, Timeout timeout) {
+                        protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
                             return Futures.successful((Object) new RemotePrimaryShardFound(expPrimaryPath, expPrimaryVersion));
                         }
                     };
@@ -405,7 +403,7 @@ public class ActorContextTest extends AbstractActorTest{
                     new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class),
                             mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {
                         @Override
-                        protected Future<Object> doAsk(ActorRef actorRef, Object message, Timeout timeout) {
+                        protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
                             return Futures.successful((Object) new LocalPrimaryShardFound(expPrimaryPath, mockDataTree));
                         }
                     };
@@ -443,7 +441,7 @@ public class ActorContextTest extends AbstractActorTest{
         testFindPrimaryExceptions(new NotInitializedException("not initialized"));
     }
 
-    private void testFindPrimaryExceptions(final Object expectedException) throws Exception {
+    private static void testFindPrimaryExceptions(final Object expectedException) throws Exception {
         TestActorRef<MessageCollectorActor> shardManager =
             TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class));
 
@@ -455,7 +453,7 @@ public class ActorContextTest extends AbstractActorTest{
             new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class),
                 mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {
                 @Override
-                protected Future<Object> doAsk(ActorRef actorRef, Object message, Timeout timeout) {
+                protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
                     return Futures.successful(expectedException);
                 }
             };
@@ -500,7 +498,7 @@ public class ActorContextTest extends AbstractActorTest{
 
             actorContext.broadcast(new Function<Short, Object>() {
                 @Override
-                public Object apply(Short v) {
+                public Object apply(final Short v) {
                     return new TestMessage();
                 }
             }, TestMessage.class);