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"));
}
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);
}
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");
}
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());
}
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);
}
Aggregations