X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeChangeListenerSupportTest.java;h=aee744e2484d861af6a52ce9b17a9863882605f0;hp=00f0f4bdf0502095aefad3858ffa18f63625e1a6;hb=HEAD;hpb=013a6679470bf692753f2e04ab4398c97fd9f5d0 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java index 00f0f4bdf0..88653642d2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java @@ -23,26 +23,28 @@ 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; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistration; -import org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeChangeListenerRegistrationReply; +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 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()); - entry.getValue().tell(CloseDataTreeChangeListenerRegistration.getInstance(), kit.getRef()); - kit.expectMsgClass(JavaTestKit.duration("5 seconds"), CloseDataTreeChangeListenerRegistrationReply.class); + TestKit kit = new TestKit(getSystem()); + entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef()); + 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() {