Search in sources :

Example 6 with AsyncDataChangeEvent

use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.

the class WildcardedDataChangeListenerTest method testSeparateWrites.

@Test
public void testSeparateWrites() 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 transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
    transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
    transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
    transaction.submit().get(5, TimeUnit.SECONDS);
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
    validateEvent(event);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 7 with AsyncDataChangeEvent

use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.

the class DeleteNestedAugmentationListenParentTest method deleteChildListenParent.

@Test
public void deleteChildListenParent() throws InterruptedException, ExecutionException, TimeoutException {
    DataBroker dataBroker = testContext.getDataBroker();
    final WriteTransaction initTx = dataBroker.newWriteOnlyTransaction();
    initTx.put(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, createList11(), true);
    initTx.submit().get(5, TimeUnit.SECONDS);
    final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
    dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, change -> event.set(change), DataChangeScope.SUBTREE);
    final WriteTransaction deleteTx = dataBroker.newWriteOnlyTransaction();
    deleteTx.delete(LogicalDatastoreType.OPERATIONAL, LIST11_PATH.augmentation(List11SimpleAugment.class));
    deleteTx.submit().get(5, TimeUnit.SECONDS);
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
    assertFalse(receivedEvent.getRemovedPaths().contains(TLL_COMPLEX_AUGMENT_PATH));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) List11SimpleAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 8 with AsyncDataChangeEvent

use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.

the class WriteParentListenAugmentTest method writeNodeListenAugment.

@Test
public void writeNodeListenAugment() throws Exception {
    final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
    DataBroker dataBroker = testContext.getDataBroker();
    ListenerRegistration<org.opendaylight.controller.md.sal.binding.api.DataChangeListener> dclRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, AUGMENT_WILDCARDED_PATH, change -> event.set(change), DataChangeScope.SUBTREE);
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    TopLevelList tll = new TopLevelListBuilder().setKey(TLL_KEY).addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
    transaction.put(LogicalDatastoreType.OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
    transaction.submit().get(5, TimeUnit.SECONDS);
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
    assertTrue(receivedEvent.getCreatedData().containsKey(AUGMENT_TLL_PATH));
    dclRegistration.close();
    final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
    transaction2.put(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
    transaction2.submit().get(5, TimeUnit.SECONDS);
    TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get();
    assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) TopLevelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 9 with AsyncDataChangeEvent

use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.

the class Bug4513Test method testDataChangeListener.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangeListener() throws Exception {
    DataChangeListener listener = mock(DataChangeListener.class);
    InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class).child(ListItem.class).build();
    ListenerRegistration<DataChangeListener> reg = getDataBroker().registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, wildCard, listener, AsyncDataBroker.DataChangeScope.SUBTREE);
    final ListItem item = writeListItem();
    ArgumentCaptor<AsyncDataChangeEvent> captor = ArgumentCaptor.forClass(AsyncDataChangeEvent.class);
    verify(listener, timeout(100)).onDataChanged(captor.capture());
    AsyncDataChangeEvent event = captor.getValue();
    assertEquals("createdData", 1, event.getCreatedData().size());
    assertEquals("ListItem", item, event.getCreatedData().values().iterator().next());
}
Also used : DataChangeListener(org.opendaylight.controller.md.sal.binding.api.DataChangeListener) ListItem(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest) Test(org.junit.Test) ListenerTest(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTest)

Example 10 with AsyncDataChangeEvent

use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.

the class DOMBrokerTest method testDataChangeListenerDoingBlockingWriteTxSubmit.

/**
 * Tests a DataChangeListener that does a blocking submit of a write Tx in its onDataChanged method.
 * This should throw an exception and not deadlock.
 */
@Test(expected = TransactionCommitDeadlockException.class)
@SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:IllegalCatch" })
public void testDataChangeListenerDoingBlockingWriteTxSubmit() throws Throwable {
    final AtomicReference<Throwable> caughtCommitEx = new AtomicReference<>();
    TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener() {

        @Override
        public void onDataChanged(final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change) {
            DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
            writeTx.put(OPERATIONAL, TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME));
            try {
                writeTx.submit().get();
            } catch (ExecutionException e) {
                caughtCommitEx.set(e.getCause());
            } catch (Exception e) {
                caughtCommitEx.set(e);
            } finally {
                super.onDataChanged(change);
            }
        }
    };
    domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE);
    final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    assertNotNull(writeTx);
    writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    AtomicReference<Throwable> caughtEx = submitTxAsync(writeTx);
    dcListener.waitForChange();
    if (caughtEx.get() != null) {
        throw caughtEx.get();
    }
    if (caughtCommitEx.get() != null) {
        throw caughtCommitEx.get();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) TransactionCommitDeadlockException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 AsyncDataChangeEvent (org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent)12 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)5 AbstractDataServiceTest (org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest)5 ActorRef (akka.actor.ActorRef)4 Props (akka.actor.Props)4 TestKit (akka.testkit.javadsl.TestKit)4 DataChanged (org.opendaylight.controller.cluster.datastore.messages.DataChanged)4 AsyncDataChangeListener (org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener)4 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)4 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 EnableNotification (org.opendaylight.controller.cluster.datastore.messages.EnableNotification)2 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)2 TreeComplexUsesAugment (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment)2 DeadLetter (akka.actor.DeadLetter)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1