2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore;
11 import static org.junit.Assert.assertEquals;
12 import akka.actor.ActorRef;
13 import akka.actor.Props;
14 import akka.testkit.JavaTestKit;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
18 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply;
19 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
20 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
21 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
22 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
23 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 public class DataChangeListenerRegistrationTest extends AbstractActorTest {
28 private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
31 store.onGlobalContextUpdated(TestModel.createTestContext());
36 public void testOnReceiveCloseListenerRegistration() throws Exception {
37 new JavaTestKit(getSystem()) {{
38 final Props props = DataChangeListenerRegistrationActor.props(store
39 .registerChangeListener(TestModel.TEST_PATH, noOpDataChangeListener(),
40 AsyncDataBroker.DataChangeScope.BASE));
41 final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
43 new Within(duration("1 seconds")) {
45 protected void run() {
47 subject.tell(new CloseDataChangeListenerRegistration().toSerializable(), getRef());
49 final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
50 // do not put code outside this method, will run afterwards
52 protected String match(final Object in) {
53 if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.SERIALIZABLE_CLASS)) {
59 }.get(); // this extracts the received message
61 assertEquals("match", out);
71 private static AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
72 return new AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>() {
74 public void onDataChanged(final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change) {