Search in sources :

Example 6 with MissingSchemaSourceException

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()));
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Test(org.junit.Test)

Example 7 with MissingSchemaSourceException

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));
}
Also used : YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)

Aggregations

MissingSchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)7 SchemaSourceRepresentation (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)3 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)3 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Futures (com.google.common.util.concurrent.Futures)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1