2 * Copyright (c) 2014 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
8 package org.opendaylight.mdsal.binding.dom.adapter.test;
10 import org.opendaylight.mdsal.common.api.AsyncDataChangeEvent;
11 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
12 import org.opendaylight.mdsal.common.api.AsyncDataBroker.DataChangeScope;
14 import org.opendaylight.mdsal.binding.api.DataChangeListener;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.TimeUnit;
17 import java.util.concurrent.TimeoutException;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import com.google.common.util.concurrent.SettableFuture;
22 public abstract class AbstractDataChangeListenerTest extends AbstractDataBrokerTest {
24 protected static final class TestListener implements DataChangeListener {
26 private final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event;
27 private boolean capture = false;
29 private TestListener() {
30 event = SettableFuture.create();
34 public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg) {
40 public AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event() {
42 return event.get(500, TimeUnit.MILLISECONDS);
43 } catch (InterruptedException | TimeoutException | ExecutionException e) {
44 throw new IllegalStateException(e);
48 public boolean hasEvent() {
49 return event.isDone();
52 public void startCapture() {
57 protected final TestListener createListener(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
58 final DataChangeScope scope) {
59 TestListener listener = new TestListener();
60 getDataBroker().registerDataChangeListener(store, path, listener, scope);
61 listener.startCapture();