use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class DataTreeChangeListenerTest method testWildcardNotificationOfPreexistingData.
@SuppressWarnings("unchecked")
@Test
public void testWildcardNotificationOfPreexistingData() throws Exception {
InstanceIdentifier<Top> id = InstanceIdentifier.builder(Top.class).build();
ArrayList<TopLevelList> list = new ArrayList<>();
list.add(new TopLevelListBuilder().setName("name").build());
TopBuilder builder = new TopBuilder().setTopLevelList(list);
DataBroker dataBroker = getDataBroker();
WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
writeTransaction.put(LogicalDatastoreType.OPERATIONAL, id, builder.build());
assertCommit(writeTransaction.submit());
DataTreeChangeListener<TopLevelList> listener = mock(DataTreeChangeListener.class);
InstanceIdentifier<TopLevelList> wildcard = InstanceIdentifier.builder(Top.class).child(TopLevelList.class).build();
dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, wildcard), listener);
verify(listener, timeout(1000)).onDataTreeChanged(Matchers.anyObject());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class OpenDaylightToasterTest method testToasterInitOnStartUp.
@Test
public void testToasterInitOnStartUp() throws Exception {
DataBroker broker = getDataBroker();
ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
assertNotNull(optional);
assertTrue("Operational toaster not present", optional.isPresent());
Toaster toasterData = optional.get();
assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus());
assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class BrokerIntegrationTest method simpleModifyOperation.
@Test
public void simpleModifyOperation() throws Exception {
DataBroker dataBroker = testContext.getDataBroker();
Optional<TopLevelList> tllFoo = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
assertFalse(tllFoo.isPresent());
TopLevelList tllFooData = createTll(TLL_FOO_KEY);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, FOO_PATH, tllFooData);
transaction.submit().get(5, TimeUnit.SECONDS);
Optional<TopLevelList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
assertTrue(readedData.isPresent());
assertEquals(tllFooData.getKey(), readedData.get().getKey());
TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
final WriteTransaction insertMoreTr = dataBroker.newWriteOnlyTransaction();
insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAR_PATH, nodeBarData);
insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAZ_PATH, nodeBazData);
insertMoreTr.submit().get(5, TimeUnit.SECONDS);
Optional<Top> top = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, TOP_PATH).checkedGet(5, TimeUnit.SECONDS);
assertTrue(top.isPresent());
assertEquals(3, top.get().getTopLevelList().size());
// We create transaction no 2
final WriteTransaction removalTransaction = dataBroker.newWriteOnlyTransaction();
// We remove node 1
removalTransaction.delete(LogicalDatastoreType.CONFIGURATION, BAR_PATH);
// We commit transaction
removalTransaction.submit().get(5, TimeUnit.SECONDS);
Optional<TopLevelList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, BAR_PATH).checkedGet(5, TimeUnit.SECONDS);
assertFalse(readedData2.isPresent());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class CrossBrokerMountPointTest method testMountPoint.
@Test
public void testMountPoint() throws ReadFailedException, TimeoutException {
final Integer attrIntValue = 500;
domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI).addService(DOMDataBroker.class, new DOMDataBroker() {
@Override
public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
throw new UnsupportedOperationException();
}
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
throw new UnsupportedOperationException();
}
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
return new DOMDataReadWriteTransaction() {
@Override
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
if (store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
final ContainerNode data = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(AUG_CONT)).withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue)).build();
return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(data));
}
return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
}
@Override
public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
throw new UnsupportedOperationException();
}
@Override
public Object getIdentifier() {
return this;
}
@Override
public boolean cancel() {
return false;
}
@Override
public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
throw new UnsupportedOperationException();
}
@Override
public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
throw new UnsupportedOperationException();
}
@Override
public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
throw new UnsupportedOperationException();
}
@Override
public CheckedFuture<Void, TransactionCommitFailedException> submit() {
throw new UnsupportedOperationException();
}
};
}
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
throw new UnsupportedOperationException();
}
@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
throw new UnsupportedOperationException();
}
@Override
public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
return Collections.emptyMap();
}
}).register();
final Optional<MountPoint> bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
assertTrue(bindingMountPoint.isPresent());
final Optional<DataBroker> dataBroker = bindingMountPoint.get().getService(DataBroker.class);
assertTrue(dataBroker.isPresent());
final Optional<Cont> data = dataBroker.get().newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, AUG_CONT_ID_BA).checkedGet(5, TimeUnit.SECONDS);
assertTrue(data.isPresent());
assertEquals(attrIntValue, data.get().getAttrInt());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testWriteByReplace.
@Test
public void testWriteByReplace() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction cwuTx = dataBroker.newWriteOnlyTransaction();
cwuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
cwuTx.submit().get(5, TimeUnit.SECONDS);
assertFalse(eventFuture.isDone());
final WriteTransaction lvuTx = dataBroker.newWriteOnlyTransaction();
TreeComplexUsesAugment tcua = new TreeComplexUsesAugmentBuilder().setListViaUses(Collections.singletonList(LVU)).build();
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_TCU_PATH, tcua, true);
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
lvuTx.submit().get(5, TimeUnit.SECONDS);
validateEvent(eventFuture.get(1000, TimeUnit.MILLISECONDS));
}
Aggregations