Search in sources :

Example 41 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class InMemoryDataStoreTest method testTransactionCommit.

@Test
public void testTransactionCommit() throws InterruptedException, ExecutionException {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    /*
         * Writes /test in writeTx
         */
    NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    writeTx.write(TestModel.TEST_PATH, testNode);
    /*
         * Reads /test from writeTx Read should return container.
         */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
    assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
    assertEquals("read: data", testNode, writeTxContainer.get().get());
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    assertThreePhaseCommit(cohort);
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", testNode, afterCommitRead.get());
}
Also used : Optional(com.google.common.base.Optional) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 42 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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());
}
Also used : DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) TransactionChainListener(org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataBroker(org.opendaylight.controller.md.sal.dom.api.DOMDataBroker) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) DOMDataBrokerExtension(org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TimeoutException(java.util.concurrent.TimeoutException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) Cont(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.top.top.level.list.list1.list1._1.Cont) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Test(org.junit.Test)

Example 43 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.

the class DOMRpcServiceTestBugfix560 method test.

@Test
public void test() throws ExecutionException, InterruptedException {
    // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
    domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {

        @Override
        public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
            final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
            return Futures.immediateCheckedFuture(result);
        }
    }).register();
    final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
    assertTrue(mountInstance.isPresent());
    final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
    assertTrue(rpcRegistry.isPresent());
    final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
    assertNotNull(rpcService);
    try {
        final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
        assertTrue(result.get().isSuccessful());
    } catch (final IllegalStateException ex) {
        fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) RockTheHouseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) DOMRpcAvailabilityListener(org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener) RpcConsumerRegistry(org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry) OpendaylightTestRpcServiceService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 44 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project bgpcep by opendaylight.

the class AbstractRIBSupportTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        AbstractRIBSupportTest.this.insertedRoutes.add(AbstractRIBSupportTest.this.mappingService.fromNormalizedNode((YangInstanceIdentifier) args[1], (NormalizedNode<?, ?>) args[2]));
        return args[1];
    }).when(this.tx).put(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        AbstractRIBSupportTest.this.deletedRoutes.add(AbstractRIBSupportTest.this.mappingService.fromYangInstanceIdentifier((YangInstanceIdentifier) args[1]));
        return args[1];
    }).when(this.tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
    this.deletedRoutes = new ArrayList<>();
    this.insertedRoutes = new ArrayList<>();
    this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
    this.moduleInfoBackedContext = ModuleInfoBackedContext.create();
}
Also used : BindingToNormalizedNodeCodec(org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec) BindingNormalizedNodeCodecRegistry(org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Before(org.junit.Before)

Example 45 with NormalizedNode

use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project bgpcep by opendaylight.

the class AbstractRIBSupportTest method createNlriAdvertiseRoute.

protected final ContainerNode createNlriAdvertiseRoute(final DestinationType destReach) {
    final MpReachNlri mpReach = new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(destReach).build()).build();
    final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> result = this.mappingService.toNormalizedNode(MP_REACH_IID, mpReach);
    return (ContainerNode) result.getValue();
}
Also used : MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri) Map(java.util.Map) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)94 Test (org.junit.Test)55 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)39 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Optional (com.google.common.base.Optional)15 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 ActorRef (akka.actor.ActorRef)8 InOrder (org.mockito.InOrder)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 ExecutionException (java.util.concurrent.ExecutionException)7 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 Map (java.util.Map)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6