Search in sources :

Example 1 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method writeContainerEmptyTreeTest.

@Test
public void writeContainerEmptyTreeTest() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(1, listener.getReceivedChanges().size());
    final Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 2 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method rootModificationChildListenerTest.

@Test
public void rootModificationChildListenerTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
    writeTx.submit().checkedGet();
    latch.await(1, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 3 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method getDOMDataTreeChangeService.

private DOMDataTreeChangeService getDOMDataTreeChangeService() {
    final DOMDataBrokerExtension extension = domBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
    if (extension == null) {
        return null;
    }
    DOMDataTreeChangeService dataTreeChangeService = null;
    if (extension instanceof DOMDataTreeChangeService) {
        dataTreeChangeService = (DOMDataTreeChangeService) extension;
    }
    return dataTreeChangeService;
}
Also used : DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)

Example 4 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project bgpcep by opendaylight.

the class RibImplTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Mockito.doReturn(mock(GeneratedClassLoadingStrategy.class)).when(this.extension).getClassLoadingStrategy();
    Mockito.doReturn(this.ribSupport).when(this.extension).getRIBSupport(any(TablesKey.class));
    final NodeIdentifier nii = new NodeIdentifier(QName.create("", "test").intern());
    Mockito.doReturn(nii).when(this.ribSupport).routeAttributesIdentifier();
    Mockito.doReturn(ImmutableSet.of()).when(this.ribSupport).cacheableAttributeObjects();
    final ChoiceNode choiceNode = mock(ChoiceNode.class);
    Mockito.doReturn(choiceNode).when(this.ribSupport).emptyRoutes();
    Mockito.doReturn(nii).when(choiceNode).getIdentifier();
    Mockito.doReturn(QName.create("", "test").intern()).when(choiceNode).getNodeType();
    Mockito.doReturn(this.domTx).when(this.domDataBroker).createTransactionChain(any());
    final DOMDataTreeChangeService dOMDataTreeChangeService = mock(DOMDataTreeChangeService.class);
    Mockito.doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dOMDataTreeChangeService)).when(this.domDataBroker).getSupportedExtensions();
    Mockito.doReturn(this.dataTreeRegistration).when(this.domSchemaService).registerSchemaContextListener(any());
    Mockito.doNothing().when(this.dataTreeRegistration).close();
    Mockito.doReturn(mock(ListenerRegistration.class)).when(dOMDataTreeChangeService).registerDataTreeChangeListener(any(), any());
    Mockito.doNothing().when(this.serviceRegistration).unregister();
}
Also used : GeneratedClassLoadingStrategy(org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) Before(org.junit.Before)

Example 5 with DOMDataTreeChangeService

use of org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService in project controller by opendaylight.

the class DOMDataTreeListenerTest method deleteContainerContainerInTreeTest.

@Test
public void deleteContainerContainerInTreeTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(TEST_CONTAINER, null, ModificationType.DELETE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Aggregations

DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)11 Test (org.junit.Test)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)6 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)6 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 Before (org.junit.Before)2 ClusteredDOMDataTreeChangeListener (org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener)2 DOMDataBrokerExtension (org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension)2 DOMDataTreeIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier)2 Optional (com.google.common.base.Optional)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 GlobalEventExecutor (io.netty.util.concurrent.GlobalEventExecutor)1 InetSocketAddress (java.net.InetSocketAddress)1 Executor (java.util.concurrent.Executor)1 TimeUnit (java.util.concurrent.TimeUnit)1