Search in sources :

Example 1 with TextToIRTransformer

use of org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer in project yangtools by opendaylight.

the class SimpleModuleTest method init.

@Before
public void init() {
    schemaRegistry = new SharedSchemaRepository("test");
    final TextToIRTransformer astTransformer = TextToIRTransformer.create(schemaRegistry, schemaRegistry);
    schemaRegistry.registerSchemaSourceListener(astTransformer);
    schemaContextFactory = schemaRegistry.createEffectiveModelContextFactory();
    allTestSources = new HashSet<>();
    final SchemaListenerRegistration reg = schemaRegistry.registerSchemaSourceListener(new SchemaSourceListener() {

        @Override
        public void schemaSourceUnregistered(final PotentialSchemaSource<?> source) {
        // NOOP
        }

        @Override
        public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> sources) {
            for (final PotentialSchemaSource<?> source : sources) {
                allTestSources.add(source.getSourceIdentifier());
            }
        }

        @Override
        public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
        // NOOP
        }
    });
    reg.close();
}
Also used : SchemaSourceListener(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener) SchemaListenerRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaListenerRegistration) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository) TextToIRTransformer(org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) Before(org.junit.Before)

Example 2 with TextToIRTransformer

use of org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer in project yangtools by opendaylight.

the class SharedEffectiveModelContextFactoryTest method setUp.

@Before
public void setUp() {
    final YangTextSchemaSource source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
    final YangTextSchemaSource source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
    s1 = RevisionSourceIdentifier.create("ietf-inet-types", Revision.of("2010-09-24"));
    s2 = RevisionSourceIdentifier.create("iana-timezones", Revision.of("2012-07-09"));
    final TextToIRTransformer transformer = TextToIRTransformer.create(repository, repository);
    repository.registerSchemaSourceListener(transformer);
    repository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(source1), PotentialSchemaSource.create(s1, YangTextSchemaSource.class, 1));
    repository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(source2), PotentialSchemaSource.create(s2, YangTextSchemaSource.class, 1));
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) TextToIRTransformer(org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer) Before(org.junit.Before)

Example 3 with TextToIRTransformer

use of org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer in project yangtools by opendaylight.

the class FilesystemSchemaSourceCacheIntegrationTest method testWithCacheRunning.

@Test
public void testWithCacheRunning() throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
    final File storageDir = Files.createTempDir();
    final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
    sharedSchemaRepository.registerSchemaSourceListener(cache);
    final SourceIdentifier runningId = RevisionSourceIdentifier.create("running", Revision.of("2012-12-12"));
    sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(new YangTextSchemaSource(runningId) {

        @Override
        protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
            return toStringHelper;
        }

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("running".getBytes(StandardCharsets.UTF_8));
        }

        @Override
        public Optional<String> getSymbolicName() {
            return Optional.empty();
        }
    }), PotentialSchemaSource.create(runningId, YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
    final TextToIRTransformer transformer = TextToIRTransformer.create(sharedSchemaRepository, sharedSchemaRepository);
    sharedSchemaRepository.registerSchemaSourceListener(transformer);
    // Request schema to make repository notify the cache
    final ListenableFuture<EffectiveModelContext> schemaFuture = sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(runningId);
    Futures.addCallback(schemaFuture, new FutureCallback<SchemaContext>() {

        @Override
        public void onSuccess(final SchemaContext result) {
            fail("Creation of schema context should fail from non-regular sources");
        }

        @Override
        public void onFailure(final Throwable cause) {
            // Creation of schema context fails, since we do not provide regular sources, but we just want
            // to check cache
            final List<File> cachedSchemas = Arrays.asList(storageDir.listFiles());
            assertEquals(1, cachedSchemas.size());
            assertEquals(Files.getNameWithoutExtension(cachedSchemas.get(0).getName()), "running@2012-12-12");
        }
    }, MoreExecutors.directExecutor());
    try {
        schemaFuture.get();
    } catch (final ExecutionException e) {
        assertNotNull(e.getCause());
        assertEquals(MissingSchemaSourceException.class, e.getCause().getClass());
        return;
    }
    fail("Creation of schema context should fail from non-regular sources");
}
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) ToStringHelper(com.google.common.base.MoreObjects.ToStringHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) List(java.util.List) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository) TextToIRTransformer(org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

TextToIRTransformer (org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer)3 Before (org.junit.Before)2 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)2 SharedSchemaRepository (org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository)2 ToStringHelper (com.google.common.base.MoreObjects.ToStringHelper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 MissingSchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)1 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)1 SchemaSourceRepresentation (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 PotentialSchemaSource (org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource)1 SchemaListenerRegistration (org.opendaylight.yangtools.yang.model.repo.spi.SchemaListenerRegistration)1 SchemaSourceListener (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener)1