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%2FDataChangeListenerRegistrationTest.java;h=d23cfea5f45b666bc91f9f9eeadcff035876bc8c;hp=a2bd569b3b88f65791f3371d672651e246327d47;hb=20f8f30f4bbf1e982672c1f883a6a18b0e4539de;hpb=4aafd13eccad285b5bb3ee277b0fb0b8721612bc diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java index a2bd569b3b..d23cfea5f4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; + import akka.actor.ActorRef; import akka.actor.Props; import akka.testkit.JavaTestKit; @@ -18,63 +19,58 @@ import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeLis import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; public class DataChangeListenerRegistrationTest extends AbstractActorTest { - private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService()); - - static { - store.onGlobalContextUpdated(TestModel.createTestContext()); - } - - - @Test - public void testOnReceiveCloseListenerRegistration() throws Exception { - new JavaTestKit(getSystem()) {{ - final Props props = DataChangeListenerRegistrationActor.props(store - .registerChangeListener(TestModel.TEST_PATH, noOpDataChangeListener(), - AsyncDataBroker.DataChangeScope.BASE)); - final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration"); - - new Within(duration("1 seconds")) { - @Override - protected void run() { - - subject.tell(CloseDataChangeListenerRegistration.INSTANCE, getRef()); - - final String out = new ExpectMsg(duration("1 seconds"), "match hint") { - // do not put code outside this method, will run afterwards - @Override - protected String match(final Object in) { - if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.class)) { - return "match"; - } else { - throw noMatch(); - } + private static final InMemoryDOMDataStore STORE = new InMemoryDOMDataStore("OPER", + MoreExecutors.newDirectExecutorService()); + + static { + STORE.onGlobalContextUpdated(TestModel.createTestContext()); + } + + @Test + public void testOnReceiveCloseListenerRegistration() throws Exception { + new JavaTestKit(getSystem()) { + { + final Props props = DataChangeListenerRegistrationActor.props(STORE.registerChangeListener( + TestModel.TEST_PATH, noOpDataChangeListener(), AsyncDataBroker.DataChangeScope.BASE)); + final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration"); + + new Within(duration("1 seconds")) { + @Override + protected void run() { + + subject.tell(CloseDataChangeListenerRegistration.INSTANCE, getRef()); + + final String out = new ExpectMsg(duration("1 seconds"), "match hint") { + // do not put code outside this method, will run + // afterwards + @Override + protected String match(final Object in) { + if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.class)) { + return "match"; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + assertEquals("match", out); + + expectNoMsg(); + } + + }; } - }.get(); // this extracts the received message - - assertEquals("match", out); - - expectNoMsg(); - } - - - }; - }}; - } - - private static AsyncDataChangeListener> noOpDataChangeListener(){ - return new AsyncDataChangeListener>() { - @Override - public void onDataChanged(final AsyncDataChangeEvent> change) { - - } - }; - } + }; + } + private static AsyncDataChangeListener> noOpDataChangeListener() { + return change -> { + }; + } }