Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DataTreeChangeListenerSupportTest.java
index 1426e4a243f4a35cdc4de136581ee1f1a26a7d45..88653642d26d423188fd41309714c36fdbe498e1 100644 (file)
@@ -23,10 +23,10 @@ import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.t
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.pattern.Patterns;
-import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
+import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
-import com.google.common.base.Throwables;
+import java.time.Duration;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
@@ -36,13 +36,15 @@ import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration;
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistrationReply;
 import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener;
-import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply;
+import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply;
 import org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
 import scala.concurrent.Await;
-import scala.concurrent.duration.Duration;
+import scala.concurrent.duration.FiniteDuration;
 
 /**
  * Unit tests for DataTreeChangeListenerSupport.
@@ -55,7 +57,7 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
 
     @Override
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         super.setUp();
         createShard();
     }
@@ -68,15 +70,17 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
     }
 
     @Test
-    public void testChangeListenerWithNoInitialData() throws Exception {
+    public void testChangeListenerWithNoInitialData() {
         MockDataTreeChangeListener listener = registerChangeListener(TEST_PATH, 0).getKey();
 
         listener.expectNoMoreChanges("Unexpected initial change event");
     }
 
     @Test
-    public void testInitialChangeListenerEventWithContainerPath() throws Exception {
-        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
+    public void testInitialChangeListenerEventWithContainerPath() throws DataValidationFailedException {
+        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
+            .build());
 
         Entry<MockDataTreeChangeListener, ActorSelection> entry = registerChangeListener(TEST_PATH, 1);
         MockDataTreeChangeListener listener = entry.getKey();
@@ -86,21 +90,25 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
 
         listener.reset(1);
 
-        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
+        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
+            .build());
         listener.waitForChangeEvents();
         listener.verifyNotifiedData(TEST_PATH);
 
         listener.reset(1);
-        JavaTestKit kit = new JavaTestKit(getSystem());
+        TestKit kit = new TestKit(getSystem());
         entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef());
-        kit.expectMsgClass(JavaTestKit.duration("5 seconds"), CloseDataTreeNotificationListenerRegistrationReply.class);
+        kit.expectMsgClass(Duration.ofSeconds(5), CloseDataTreeNotificationListenerRegistrationReply.class);
 
-        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
+        writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.newContainerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(TEST_QNAME))
+            .build());
         listener.verifyNoNotifiedData(TEST_PATH);
     }
 
     @Test
-    public void testInitialChangeListenerEventWithListPath() throws Exception {
+    public void testInitialChangeListenerEventWithListPath() throws DataValidationFailedException {
         mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(1, 2));
 
         MockDataTreeChangeListener listener = registerChangeListener(OUTER_LIST_PATH, 1).getKey();
@@ -110,7 +118,7 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
     }
 
     @Test
-    public void testInitialChangeListenerEventWithWildcardedListPath() throws Exception {
+    public void testInitialChangeListenerEventWithWildcardedListPath() throws DataValidationFailedException {
         mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(1, 2));
 
         MockDataTreeChangeListener listener =
@@ -121,7 +129,7 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
     }
 
     @Test
-    public void testInitialChangeListenerEventWithNestedWildcardedListsPath() throws Exception {
+    public void testInitialChangeListenerEventWithNestedWildcardedListsPath() throws DataValidationFailedException {
         mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(outerNode(
                 outerNodeEntry(1, innerNode("one", "two")), outerNodeEntry(2, innerNode("three", "four")))));
 
@@ -160,16 +168,17 @@ public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
         MockDataTreeChangeListener listener = new MockDataTreeChangeListener(expectedEvents);
         ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH));
 
+        RegisterDataTreeNotificationListenerReply reply;
         try {
-            RegisterDataTreeChangeListenerReply reply = (RegisterDataTreeChangeListenerReply)
-                Await.result(Patterns.ask(shardActor, new RegisterDataTreeChangeListener(path, dclActor, false),
-                    new Timeout(5, TimeUnit.SECONDS)), Duration.create(5, TimeUnit.SECONDS));
-            return new SimpleEntry<>(listener, getSystem().actorSelection(reply.getListenerRegistrationPath()));
-
+            reply = (RegisterDataTreeNotificationListenerReply)
+                    Await.result(Patterns.ask(shardActor, new RegisterDataTreeChangeListener(path, dclActor, false),
+                        new Timeout(5, TimeUnit.SECONDS)), FiniteDuration.create(5, TimeUnit.SECONDS));
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception e) {
-            Throwables.propagate(e);
-            return null;
+            throw new RuntimeException(e);
         }
+        return new SimpleEntry<>(listener, getSystem().actorSelection(reply.getListenerRegistrationPath()));
     }
 
     private void createShard() {