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.controller.md.sal.binding.test;
10 import java.util.concurrent.ExecutionException;
11 import java.util.concurrent.TimeUnit;
12 import java.util.concurrent.TimeoutException;
14 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import com.google.common.util.concurrent.SettableFuture;
23 public abstract class AbstractDataChangeListenerTest extends AbstractDataBrokerTest {
25 protected static final class TestListener implements DataChangeListener {
27 private final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event;
28 private boolean capture = false;
30 private TestListener() {
31 event = SettableFuture.create();
35 public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> arg) {
41 public AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event() {
43 return event.get(500, TimeUnit.MILLISECONDS);
44 } catch (InterruptedException | TimeoutException | ExecutionException e) {
45 throw new IllegalStateException(e);
49 public boolean hasEvent() {
50 return event.isDone();
53 public void startCapture() {
58 protected final TestListener createListener(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
59 final DataChangeScope scope) {
60 TestListener listener = new TestListener();
61 getDataBroker().registerDataChangeListener(store, path, listener, scope);
62 listener.startCapture();