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;
13 import akka.actor.ActorRef;
14 import akka.actor.Props;
15 import akka.testkit.JavaTestKit;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
19 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply;
20 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
21 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
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",
29 MoreExecutors.newDirectExecutorService());
32 STORE.onGlobalContextUpdated(TestModel.createTestContext());
36 public void testOnReceiveCloseListenerRegistration() throws Exception {
37 new JavaTestKit(getSystem()) {
39 final Props props = DataChangeListenerRegistrationActor.props(STORE.registerChangeListener(
40 TestModel.TEST_PATH, noOpDataChangeListener(), AsyncDataBroker.DataChangeScope.BASE));
41 final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
43 new Within(duration("1 seconds")) {
45 protected void run() {
47 subject.tell(CloseDataChangeListenerRegistration.INSTANCE, getRef());
49 final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
50 // do not put code outside this method, will run
53 protected String match(final Object in) {
54 if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.class)) {
60 }.get(); // this extracts the received message
62 assertEquals("match", out);
72 private static AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener() {