Search in sources :

Example 1 with EffectiveModelContextFactory

use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.

the class SharedSchemaRepositoryWithFeaturesTest method testSharedSchemaRepositoryWithAllFeaturesSupported.

@Test
public void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
    final SettableSchemaProvider<IRSchemaSource> foobar = getImmediateYangSourceProviderFromResource("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
    foobar.register(sharedSchemaRepository);
    foobar.setResult();
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> testSchemaContextFuture = fact.createEffectiveModelContext(foobar.getId());
    assertTrue(testSchemaContextFuture.isDone());
    assertSchemaContext(testSchemaContextFuture.get(), 1);
    final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
    assertNotNull(module);
    assertEquals(3, module.getChildNodes().size());
    final ContainerSchemaNode testContainerA = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-a"));
    final LeafSchemaNode testLeafA = (LeafSchemaNode) testContainerA.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-a"));
    final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-b"));
    final LeafSchemaNode testLeafB = (LeafSchemaNode) testContainerB.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-b"));
    final ContainerSchemaNode testContainerC = (ContainerSchemaNode) module.getDataChildByName(QName.create(module.getQNameModule(), "test-container-c"));
    final LeafSchemaNode testLeafC = (LeafSchemaNode) testContainerC.getDataChildByName(QName.create(module.getQNameModule(), "test-leaf-c"));
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 2 with EffectiveModelContextFactory

use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.

the class SharedSchemaRepositoryTest method testDifferentCosts.

@Test
public void testDifferentCosts() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final SettableSchemaProvider<IRSchemaSource> immediateInetTypesYang = spy(getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
    immediateInetTypesYang.register(sharedSchemaRepository);
    immediateInetTypesYang.setResult();
    final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = spy(getRemoteYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
    remoteInetTypesYang.register(sharedSchemaRepository);
    remoteInetTypesYang.setResult();
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
    assertSchemaContext(schemaContextFuture.get(), 1);
    final SourceIdentifier id = immediateInetTypesYang.getId();
    verify(remoteInetTypesYang, times(0)).getSource(id);
    verify(immediateInetTypesYang).getSource(id);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 3 with EffectiveModelContextFactory

use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.

the class SharedSchemaRepositoryTest method testFailedSchemaContext.

@Test
public void testFailedSchemaContext() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
    remoteInetTypesYang.register(sharedSchemaRepository);
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    // Make source appear
    final Throwable ex = new IllegalStateException("failed schema");
    remoteInetTypesYang.setException(ex);
    final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
    try {
        schemaContextFuture.get();
    } catch (final ExecutionException e) {
        assertNotNull(e.getCause());
        assertNotNull(e.getCause().getCause());
        assertSame(ex, e.getCause().getCause());
        return;
    }
    fail("Schema context creation should have failed");
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) ExecutionException(java.util.concurrent.ExecutionException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 4 with EffectiveModelContextFactory

use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.

the class SharedSchemaRepositoryTest method testSimpleSchemaContext.

@Test
public void testSimpleSchemaContext() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
    remoteInetTypesYang.register(sharedSchemaRepository);
    final ListenableFuture<IRSchemaSource> registeredSourceFuture = sharedSchemaRepository.getSchemaSource(remoteInetTypesYang.getId(), IRSchemaSource.class);
    assertFalse(registeredSourceFuture.isDone());
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
    assertFalse(schemaContextFuture.isDone());
    // Make source appear
    remoteInetTypesYang.setResult();
    assertEquals(remoteInetTypesYang.getSchemaSourceRepresentation(), registeredSourceFuture.get());
    // Verify schema created successfully
    assertTrue(schemaContextFuture.isDone());
    final SchemaContext firstSchemaContext = schemaContextFuture.get();
    assertSchemaContext(firstSchemaContext, 1);
    // Try same schema second time
    final ListenableFuture<EffectiveModelContext> secondSchemaFuture = sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(remoteInetTypesYang.getId());
    // Verify second schema created successfully immediately
    assertTrue(secondSchemaFuture.isDone());
    // Assert same context instance is returned from first and second attempt
    assertSame(firstSchemaContext, secondSchemaFuture.get());
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 5 with EffectiveModelContextFactory

use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project yangtools by opendaylight.

the class SharedSchemaRepositoryTest method testTwoSchemaContextsSharingSource.

@Test
public void testTwoSchemaContextsSharingSource() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
    remoteInetTypesYang.register(sharedSchemaRepository);
    remoteInetTypesYang.setResult();
    final SettableSchemaProvider<IRSchemaSource> remoteTopologyYang = getImmediateYangSourceProviderFromResource("/ietf/network-topology@2013-10-21.yang");
    remoteTopologyYang.register(sharedSchemaRepository);
    remoteTopologyYang.setResult();
    final SettableSchemaProvider<IRSchemaSource> remoteModuleNoRevYang = getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
    remoteModuleNoRevYang.register(sharedSchemaRepository);
    final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
    final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId(), remoteTopologyYang.getId());
    assertTrue(inetAndTopologySchemaContextFuture.isDone());
    assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 2);
    final ListenableFuture<EffectiveModelContext> inetAndNoRevSchemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId());
    assertFalse(inetAndNoRevSchemaContextFuture.isDone());
    remoteModuleNoRevYang.setResult();
    assertTrue(inetAndNoRevSchemaContextFuture.isDone());
    assertSchemaContext(inetAndNoRevSchemaContextFuture.get(), 2);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)21 Test (org.junit.Test)19 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)10 NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)10 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)10 Collection (java.util.Collection)9 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)9 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)8 SchemaResolutionException (org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException)8 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)7 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)7 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)7 HashMap (java.util.HashMap)6 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)6 HashMultimap (com.google.common.collect.HashMultimap)5 Iterables (com.google.common.collect.Iterables)5 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Futures (com.google.common.util.concurrent.Futures)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5