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