use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy 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.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.
the class NetconfNodeActorTest method testMissingSchemaSourceOnMissingProvider.
@Test(expected = MissingSchemaSourceException.class)
public void testMissingSchemaSourceOnMissingProvider() throws Exception {
final SharedSchemaRepository repository = new SharedSchemaRepository("test");
SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system).setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setBaseSchemas(BASE_SCHEMAS).build();
final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
final ProxyYangTextSourceProvider proxyYangProvider = new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
Await.result(resolvedSchemaFuture, TIMEOUT.duration());
}
use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.
the class ProxyYangTextSourceProvider method getYangTextSchemaSource.
@Override
public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier sourceIdentifier) {
final Future<Object> scalaFuture = Patterns.ask(masterRef, new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime);
final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
scalaFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) {
if (failure != null) {
promise.failure(failure);
return;
}
promise.success((YangTextSchemaSourceSerializationProxy) success);
}
}, executionContext);
return promise.future();
}
use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.
the class NetconfNodeActor method sendYangTextSchemaSourceProxy.
private void sendYangTextSchemaSourceProxy(final SourceIdentifier sourceIdentifier, final ActorRef sender) {
final ListenableFuture<YangTextSchemaSource> schemaSourceFuture = schemaRepository.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class);
Futures.addCallback(schemaSourceFuture, new FutureCallback<YangTextSchemaSource>() {
@Override
public void onSuccess(final YangTextSchemaSource yangTextSchemaSource) {
try {
LOG.debug("{}: getSchemaSource for {} succeeded", id, sourceIdentifier);
sender.tell(new YangTextSchemaSourceSerializationProxy(yangTextSchemaSource), getSelf());
} catch (IOException e) {
sender.tell(new Failure(e), getSelf());
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.debug("{}: getSchemaSource for {} failed", id, sourceIdentifier, throwable);
sender.tell(new Failure(throwable), getSelf());
}
}, MoreExecutors.directExecutor());
}
Aggregations