X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FActorContextTest.java;h=89a50b84e446fe4e8bc99191f8c83ff7799e5765;hb=a6af137c30470b86d4bc624d4c48cb686495a182;hp=3c60fb7dee3819270e38466fc1e46ae0c12b9928;hpb=917283d6f5633ad981bebb6dfc6d6e0245876ab5;p=controller.git 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 3c60fb7dee..89a50b84e4 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 @@ -26,8 +26,8 @@ import akka.actor.Props; import akka.actor.UntypedActor; import akka.dispatch.Futures; import akka.japi.Creator; -import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import akka.util.Timeout; import com.google.common.base.Optional; import com.google.common.collect.Maps; @@ -57,7 +57,7 @@ import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound; import org.opendaylight.controller.cluster.raft.utils.EchoActor; import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +73,7 @@ public class ActorContextTest extends AbstractActorTest { private static class TestMessage { } - private static class MockShardManager extends UntypedActor { + private static final class MockShardManager extends UntypedActor { private final boolean found; private final ActorRef actorRef; @@ -85,7 +85,7 @@ public class ActorContextTest extends AbstractActorTest { this.actorRef = actorRef; } - @Override public void onReceive(final Object message) throws Exception { + @Override public void onReceive(final Object message) { if (message instanceof FindPrimary) { FindPrimary fp = (FindPrimary)message; Object resp = findPrimaryResponses.get(fp.getShardName()); @@ -133,7 +133,7 @@ public class ActorContextTest extends AbstractActorTest { } @Override - public MockShardManager create() throws Exception { + public MockShardManager create() { return new MockShardManager(found, actorRef); } } @@ -141,27 +141,24 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindLocalShardWithShardFound() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { - new Within(duration("1 seconds")) { - @Override - protected void run() { + within(duration("1 seconds"), () -> { + ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class)); - ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class)); + ActorRef shardManagerActorRef = getSystem() + .actorOf(MockShardManager.props(true, shardActorRef)); - ActorRef shardManagerActorRef = getSystem() - .actorOf(MockShardManager.props(true, shardActorRef)); - - ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, - mock(ClusterWrapper.class), mock(Configuration.class)); + ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, + mock(ClusterWrapper.class), mock(Configuration.class)); - Optional out = actorContext.findLocalShard("default"); + Optional out = actorContext.findLocalShard("default"); - assertEquals(shardActorRef, out.get()); + assertEquals(shardActorRef, out.get()); - expectNoMsg(); - } - }; + expectNoMsg(); + return null; + }); } }; @@ -169,7 +166,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindLocalShardWithShardNotFound() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(false, null)); @@ -185,7 +182,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testExecuteRemoteOperation() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class)); @@ -206,7 +203,7 @@ public class ActorContextTest extends AbstractActorTest { @Test @SuppressWarnings("checkstyle:IllegalCatch") public void testExecuteRemoteOperationAsync() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class)); @@ -316,7 +313,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testSetDatastoreContext() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class), DatastoreContext.newBuilder() @@ -349,8 +346,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindPrimaryShardAsyncRemotePrimaryFound() throws Exception { - TestActorRef shardManager = TestActorRef.create(getSystem(), - Props.create(MessageCollectorActor.class)); + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -391,8 +387,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindPrimaryShardAsyncLocalPrimaryFound() throws Exception { - TestActorRef shardManager = TestActorRef.create(getSystem(), - Props.create(MessageCollectorActor.class)); + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -432,19 +427,18 @@ public class ActorContextTest extends AbstractActorTest { } @Test - public void testFindPrimaryShardAsyncPrimaryNotFound() throws Exception { + public void testFindPrimaryShardAsyncPrimaryNotFound() { testFindPrimaryExceptions(new PrimaryNotFoundException("not found")); } @Test - public void testFindPrimaryShardAsyncActorNotInitialized() throws Exception { + public void testFindPrimaryShardAsyncActorNotInitialized() { testFindPrimaryExceptions(new NotInitializedException("not initialized")); } @SuppressWarnings("checkstyle:IllegalCatch") - private static void testFindPrimaryExceptions(final Object expectedException) throws Exception { - TestActorRef shardManager = - TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); + private static void testFindPrimaryExceptions(final Object expectedException) { + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -477,10 +471,10 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testBroadcast() { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { - ActorRef shardActorRef1 = getSystem().actorOf(Props.create(MessageCollectorActor.class)); - ActorRef shardActorRef2 = getSystem().actorOf(Props.create(MessageCollectorActor.class)); + ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props()); + ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props()); TestActorRef shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props());