From ad98c16f6f690874866b6c218c178489e7f4b373 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 28 Jul 2016 03:53:44 +0200 Subject: [PATCH] Use ActorSystem.terminate() ActorSystem.shutdown() has been deprecated, move on to the replacement call. Change-Id: I21cee3100c84003585afd9c95706c26f686d0eec Signed-off-by: Robert Varga --- .../actor/MeteredBoundedMailboxTest.java | 23 ++++++++++--------- .../impl/ActorSystemProviderImpl.java | 6 ++--- .../datastore/utils/ActorContextTest.java | 22 ++++++++---------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java index c027de0acf..9fe8a13222 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java @@ -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)) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java index 5970ea47e5..1ab67384f1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/actor_system_provider/impl/ActorSystemProviderImpl.java @@ -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 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); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 3582302072..0698f011c6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -79,13 +79,13 @@ public class ActorContextTest extends AbstractActorTest{ private final ActorRef actorRef; private final Map 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 doAsk(ActorRef actorRef, Object message, Timeout timeout) { + protected Future 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 doAsk(ActorRef actorRef, Object message, Timeout timeout) { + protected Future 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 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 doAsk(ActorRef actorRef, Object message, Timeout timeout) { + protected Future 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() { @Override - public Object apply(Short v) { + public Object apply(final Short v) { return new TestMessage(); } }, TestMessage.class); -- 2.36.6