0f155ef5979c67dcd396b14dbd25c30bde130923
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ListenerRegistrationTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
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;
8 import org.junit.Test;
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;
18
19 import static org.junit.Assert.assertEquals;
20
21 public class ListenerRegistrationTest extends AbstractActorTest {
22   private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
23
24   private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
25
26   static {
27     store.onGlobalContextUpdated(TestModel.createTestContext());
28   }
29
30
31   @Test
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");
36
37       new Within(duration("1 seconds")) {
38         protected void run() {
39
40           subject.tell(new CloseListenerRegistration(), getRef());
41
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) {
46                 return "match";
47               } else {
48                 throw noMatch();
49               }
50             }
51           }.get(); // this extracts the received message
52
53           assertEquals("match", out);
54
55           expectNoMsg();
56         }
57
58
59       };
60     }};
61   }
62
63   private  AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
64     return new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
65       @Override
66       public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
67
68       }
69     };
70   }
71
72 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.