use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.
@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
// We wrote initial state NODE_0_FLOW
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
// We registered DataChangeListener
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
assertFalse(eventFuture.isDone());
final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
secondTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(event);
// Data change should contains NODE_1 Flow - which was added
assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
// Data change must not containe NODE_0 Flow which was replaced with same value.
assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project openflowplugin by opendaylight.
the class SimplifiedOperationalListenerTest method setUp.
@Before
public void setUp() throws Exception {
final DataBroker db = Mockito.mock(DataBroker.class);
final FlowCapableNodeSnapshotDao configSnapshot = new FlowCapableNodeSnapshotDao();
final FlowCapableNodeSnapshotDao operationalSnapshot = new FlowCapableNodeSnapshotDao();
final FlowCapableNodeDao configDao = new FlowCapableNodeCachedDao(configSnapshot, new FlowCapableNodeOdlDao(db, LogicalDatastoreType.CONFIGURATION));
nodeListenerOperational = new SimplifiedOperationalListener(reactor, operationalSnapshot, configDao, reconciliationRegistry, deviceMastershipManager);
InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
fcNodePath = nodePath.augmentation(FlowCapableNode.class);
final DataTreeIdentifier<Node> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, nodePath);
Mockito.when(db.newReadOnlyTransaction()).thenReturn(roTx);
Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
Mockito.when(dataTreeModification.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(dataTreeModification.getRootNode()).thenReturn(operationalModification);
Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.
the class ListenerTest method toStringTest.
/**
* Tests {@link NetworkListener#toString}, {@link PortListener#toString}, {@link SubnetListener#toString} method.
*/
@Test
public void toStringTest() {
final DataProcessor<Network> networkDataProcessor = Mockito.mock(DataProcessor.class);
final DataBroker dataBroker = Mockito.mock(DataBroker.class);
final NetworkListener networkListener = new NetworkListener(networkDataProcessor, dataBroker);
final DataProcessor<Port> portDataProcessor = Mockito.mock(DataProcessor.class);
final PortListener portListener = new PortListener(portDataProcessor, dataBroker);
final DataProcessor<Subnet> subnetDataProcessor = Mockito.mock(DataProcessor.class);
final SubnetListener subnetListener = new SubnetListener(subnetDataProcessor, dataBroker);
assertEquals("NetworkListener", networkListener.toString());
assertEquals("PortListener", portListener.toString());
assertEquals("SubnetListener", subnetListener.toString());
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.
the class VppNodeReader method readFirstAvailableIpOfVppNode.
private ListenableFuture<Optional<Ipv4Address>> readFirstAvailableIpOfVppNode(final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifierToVppNode) {
final SettableFuture<Optional<Ipv4Address>> resultFuture = SettableFuture.create();
final DataBroker vppDataBroker = LispNeutronUtil.resolveDataBrokerForMountPoint(instanceIdentifierToVppNode, mountService);
if (vppDataBroker != null) {
final Optional<InterfacesState> interfacesOnVppNodeOptional = VppNetconfTrasaction.read(vppDataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class));
if (interfacesOnVppNodeOptional.isPresent()) {
for (Interface intf : interfacesOnVppNodeOptional.get().getInterface()) {
if (intf.getType().equals(Loopback.class)) {
continue;
}
final Optional<Ipv4Address> ipv4AddressOptional = readIpAddressFromInterface(intf, instanceIdentifierToVppNode);
if (ipv4AddressOptional.isPresent()) {
resultFuture.set(ipv4AddressOptional);
break;
}
}
}
resultFuture.set(Optional.absent());
} else {
LOG.debug("Data broker for vpp {} is missing.", instanceIdentifierToVppNode);
}
return resultFuture;
}
use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.
the class AuthenticationKeyDataListenerTest method init.
@Before
@SuppressWarnings("unchecked")
public void init() {
DataBroker dataBrokerMock = Mockito.mock(DataBroker.class);
iMappingSystemMock = Mockito.mock(IMappingSystem.class);
authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBrokerMock, iMappingSystemMock);
final InstanceIdentifier<AuthenticationKey> instanceIdentifierMock = Mockito.mock(InstanceIdentifier.class);
final DataTreeIdentifier<AuthenticationKey> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceIdentifierMock);
change_del = Mockito.mock(DataTreeModification.class);
change_subtreeModified = Mockito.mock(DataTreeModification.class);
change_write = Mockito.mock(DataTreeModification.class);
mod_del = Mockito.mock(DataObjectModification.class);
mod_subtreeModified = Mockito.mock(DataObjectModification.class);
mod_write = Mockito.mock(DataObjectModification.class);
Mockito.when(change_del.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_del.getRootNode()).thenReturn(mod_del);
Mockito.when(change_subtreeModified.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_subtreeModified.getRootNode()).thenReturn(mod_subtreeModified);
Mockito.when(change_write.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_write.getRootNode()).thenReturn(mod_write);
Mockito.when(mod_del.getModificationType()).thenReturn(ModificationType.DELETE);
Mockito.when(mod_subtreeModified.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED);
Mockito.when(mod_write.getModificationType()).thenReturn(ModificationType.WRITE);
}
Aggregations