use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project netconf by opendaylight.
the class NetconfNodeActorTest method testYangTextSchemaSourceRequest.
@Test
public void testYangTextSchemaSourceRequest() throws Exception {
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
final ProxyYangTextSourceProvider proxyYangProvider = new ProxyYangTextSourceProvider(masterRef, system.dispatcher(), TIMEOUT);
final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sourceIdentifier, ByteSource.wrap("YANG".getBytes(UTF_8)));
// Test success.
final SchemaSourceRegistration<YangTextSchemaSource> schemaSourceReg = masterSchemaRepository.registerSchemaSource(id -> Futures.immediateFuture(yangTextSchemaSource), PotentialSchemaSource.create(sourceIdentifier, YangTextSchemaSource.class, 1));
final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
final YangTextSchemaSourceSerializationProxy success = Await.result(resolvedSchemaFuture, TIMEOUT.duration());
assertEquals(sourceIdentifier, success.getRepresentation().getIdentifier());
assertEquals("YANG", convertStreamToString(success.getRepresentation().openStream()));
// Test missing source failure.
schemaSourceReg.close();
final MissingSchemaSourceException ex = assertThrows(MissingSchemaSourceException.class, () -> {
final Future<YangTextSchemaSourceSerializationProxy> failedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
Await.result(failedSchemaFuture, TIMEOUT.duration());
});
assertThat(ex.getMessage(), startsWith("No providers registered for source"));
assertThat(ex.getMessage(), containsString(sourceIdentifier.toString()));
}
use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project netconf by opendaylight.
the class SchemaSourceCache method getSource.
@Override
public synchronized ListenableFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) {
final YangModuleInfo yangModuleInfo = cachedSchemas.get(sourceIdentifier);
if (yangModuleInfo != null) {
final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sourceIdentifier, yangModuleInfo.getYangTextByteSource());
return Futures.immediateFuture(representation.cast(yangTextSchemaSource));
}
LOG.debug("Source {} not found in cache", sourceIdentifier);
return Futures.immediateFailedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
}
Aggregations