Migrate from YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / registry / mbeans / RemoteRpcRegistryMXBeanImplTest.java
index 8b23154232e59613301ff03eb76393816aa34bbe..4d719a2a662e20643ac5c070cfce5c740b15d917 100644 (file)
@@ -7,25 +7,30 @@
  */
 package org.opendaylight.controller.remote.rpc.registry.mbeans;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.actor.Props;
+import akka.dispatch.Dispatchers;
 import akka.testkit.TestActorRef;
 import akka.testkit.javadsl.TestKit;
+import akka.util.Timeout;
 import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
-import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig;
+import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig;
 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
+import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
+import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -42,121 +47,122 @@ public class RemoteRpcRegistryMXBeanImplTest {
     private RemoteRpcRegistryMXBeanImpl mxBean;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         system = ActorSystem.create("test");
 
         final DOMRpcIdentifier emptyRpcIdentifier = DOMRpcIdentifier.create(
-                EMPTY_SCHEMA_PATH, YangInstanceIdentifier.EMPTY);
+                EMPTY_SCHEMA_PATH, YangInstanceIdentifier.empty());
         final DOMRpcIdentifier localRpcIdentifier = DOMRpcIdentifier.create(
                 LOCAL_SCHEMA_PATH, YangInstanceIdentifier.of(LOCAL_QNAME));
 
         buckets = Lists.newArrayList(emptyRpcIdentifier, localRpcIdentifier);
 
-        final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
+        final RemoteOpsProviderConfig config = new RemoteOpsProviderConfig.Builder("system").build();
         final TestKit invoker = new TestKit(system);
         final TestKit registrar = new TestKit(system);
         final TestKit supervisor = new TestKit(system);
-        final Props props = RpcRegistry.props(config, invoker.getRef(), registrar.getRef());
+        final Props props = RpcRegistry.props(config, invoker.getRef(), registrar.getRef())
+                .withDispatcher(Dispatchers.DefaultDispatcherId());
         testActor = new TestActorRef<>(system, props, supervisor.getRef(), "testActor");
-        final RpcRegistry rpcRegistry = testActor.underlyingActor();
 
-        mxBean = new RemoteRpcRegistryMXBeanImpl(rpcRegistry);
-        Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
+        final Timeout timeout = Timeout.apply(10, TimeUnit.SECONDS);
+        mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(testActor, system.dispatcher(), timeout),
+                timeout);
     }
 
     @After
-    public void tearDown() throws Exception {
+    public void tearDown() {
         TestKit.shutdownActorSystem(system, Boolean.TRUE);
     }
 
     @Test
-    public void testGetGlobalRpcEmptyBuckets() throws Exception {
+    public void testGetGlobalRpcEmptyBuckets() {
         final Set<String> globalRpc = mxBean.getGlobalRpc();
 
-        Assert.assertNotNull(globalRpc);
-        Assert.assertTrue(globalRpc.isEmpty());
+        assertNotNull(globalRpc);
+        assertTrue(globalRpc.isEmpty());
     }
 
     @Test
-    public void testGetGlobalRpc() throws Exception {
+    public void testGetGlobalRpc() {
         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
         final Set<String> globalRpc = mxBean.getGlobalRpc();
 
-        Assert.assertNotNull(globalRpc);
-        Assert.assertEquals(1, globalRpc.size());
+        assertNotNull(globalRpc);
+        assertEquals(1, globalRpc.size());
 
         final String rpc = globalRpc.iterator().next();
-        Assert.assertEquals(EMPTY_SCHEMA_PATH.toString(), rpc);
+        assertEquals(EMPTY_SCHEMA_PATH.toString(), rpc);
     }
 
     @Test
-    public void testGetLocalRegisteredRoutedRpcEmptyBuckets() throws Exception {
+    public void testGetLocalRegisteredRoutedRpcEmptyBuckets() {
         final Set<String> localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc();
 
-        Assert.assertNotNull(localRegisteredRoutedRpc);
-        Assert.assertTrue(localRegisteredRoutedRpc.isEmpty());
+        assertNotNull(localRegisteredRoutedRpc);
+        assertTrue(localRegisteredRoutedRpc.isEmpty());
     }
 
     @Test
-    public void testGetLocalRegisteredRoutedRpc() throws Exception {
+    public void testGetLocalRegisteredRoutedRpc() {
         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
         final Set<String> localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc();
 
-        Assert.assertNotNull(localRegisteredRoutedRpc);
-        Assert.assertEquals(1, localRegisteredRoutedRpc.size());
+        assertNotNull(localRegisteredRoutedRpc);
+        assertEquals(1, localRegisteredRoutedRpc.size());
 
         final String localRpc = localRegisteredRoutedRpc.iterator().next();
-        Assert.assertTrue(localRpc.contains(LOCAL_QNAME.toString()));
-        Assert.assertTrue(localRpc.contains(LOCAL_SCHEMA_PATH.toString()));
+        assertTrue(localRpc.contains(LOCAL_QNAME.toString()));
+        assertTrue(localRpc.contains(LOCAL_SCHEMA_PATH.toString()));
     }
 
     @Test
-    public void testFindRpcByNameEmptyBuckets() throws Exception {
+    public void testFindRpcByNameEmptyBuckets() {
         final Map<String, String> rpcByName = mxBean.findRpcByName("");
 
-        Assert.assertNotNull(rpcByName);
-        Assert.assertTrue(rpcByName.isEmpty());
+        assertNotNull(rpcByName);
+        assertTrue(rpcByName.isEmpty());
     }
 
     @Test
-    public void testFindRpcByName() throws Exception {
+    public void testFindRpcByName() {
         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
         final Map<String, String> rpcByName = mxBean.findRpcByName("");
 
-        Assert.assertNotNull(rpcByName);
-        Assert.assertEquals(1, rpcByName.size());
-        Assert.assertTrue(rpcByName.containsValue(LOCAL_QNAME.getLocalName()));
+        assertNotNull(rpcByName);
+        assertEquals(1, rpcByName.size());
+        assertTrue(rpcByName.containsValue(LOCAL_QNAME.getLocalName()));
     }
 
     @Test
-    public void testFindRpcByRouteEmptyBuckets() throws Exception {
+    public void testFindRpcByRouteEmptyBuckets() {
         final Map<String, String> rpcByRoute = mxBean.findRpcByRoute("");
 
-        Assert.assertNotNull(rpcByRoute);
-        Assert.assertTrue(rpcByRoute.isEmpty());
+        assertNotNull(rpcByRoute);
+        assertTrue(rpcByRoute.isEmpty());
     }
 
     @Test
-    public void testFindRpcByRoute() throws Exception {
+    public void testFindRpcByRoute() {
         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
         final Map<String, String> rpcByRoute = mxBean.findRpcByRoute("");
 
-        Assert.assertNotNull(rpcByRoute);
-        Assert.assertEquals(1, rpcByRoute.size());
-        Assert.assertTrue(rpcByRoute.containsValue(LOCAL_QNAME.getLocalName()));
+        assertNotNull(rpcByRoute);
+        assertEquals(1, rpcByRoute.size());
+        assertTrue(rpcByRoute.containsValue(LOCAL_QNAME.getLocalName()));
     }
 
     @Test
-    public void testGetBucketVersionsEmptyBuckets() throws Exception {
+    public void testGetBucketVersionsEmptyBuckets() {
         final String bucketVersions = mxBean.getBucketVersions();
-        Assert.assertEquals(Collections.EMPTY_MAP.toString(), bucketVersions);
+        assertEquals(Collections.emptyMap().toString(), bucketVersions);
     }
 
     @Test
-    public void testGetBucketVersions() throws Exception {
+    public void testGetBucketVersions() {
         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
         final String bucketVersions = mxBean.getBucketVersions();
 
-        Assert.assertTrue(bucketVersions.contains(testActor.provider().getDefaultAddress().toString()));
+        assertTrue(bucketVersions.contains(testActor.provider().getDefaultAddress().toString()));
     }
 }