1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import akka.testkit.JavaTestKit;
6 import com.google.common.util.concurrent.ListeningExecutorService;
7 import com.google.common.util.concurrent.MoreExecutors;
9 import org.opendaylight.controller.cluster.datastore.messages.CloseListenerRegistration;
10 import org.opendaylight.controller.cluster.datastore.messages.CloseListenerRegistrationReply;
11 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
15 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
16 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import static org.junit.Assert.assertEquals;
21 public class ListenerRegistrationTest extends AbstractActorTest {
22 private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
24 private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
27 store.onGlobalContextUpdated(TestModel.createTestContext());
32 public void testOnReceiveCloseListenerRegistration() throws Exception {
33 new JavaTestKit(getSystem()) {{
34 final Props props = ListenerRegistration.props(store.registerChangeListener(TestModel.TEST_PATH, noOpDataChangeListener(), AsyncDataBroker.DataChangeScope.BASE));
35 final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
37 new Within(duration("1 seconds")) {
38 protected void run() {
40 subject.tell(new CloseListenerRegistration(), getRef());
42 final String out = new ExpectMsg<String>("match hint") {
43 // do not put code outside this method, will run afterwards
44 protected String match(Object in) {
45 if (in instanceof CloseListenerRegistrationReply) {
51 }.get(); // this extracts the received message
53 assertEquals("match", out);
63 private AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
64 return new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
66 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {