RemoteYangTextSourceProviderImpl implements RemoteYangTextSourceProvider { @Override public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier) { LOG.trace("Sending yang schema source for {}", identifier); final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise(); ListenableFuture<YangTextSchemaSource> future = repository.getSchemaSource(identifier, YangTextSchemaSource.class); Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() { @Override public void onSuccess(final YangTextSchemaSource result) { try { promise.success(new YangTextSchemaSourceSerializationProxy(result)); } catch (IOException e) { LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e); promise.failure(e); } } @Override public void onFailure(final Throwable failure) { LOG.warn("Unable to retrieve schema source from provider", failure); promise.failure(failure); } }, MoreExecutors.directExecutor()); return promise.future(); } RemoteYangTextSourceProviderImpl(final SchemaRepository repository,
            final Set<SourceIdentifier> providedSources); @Override Future<Set<SourceIdentifier>> getProvidedSources(); @Override Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier);  }
@Test public void testGetExistingYangTextSchemaSource() throws Exception { String source = "Test source."; YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource( ID, ByteSource.wrap(source.getBytes())); Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn( Futures.immediateFuture(schemaSource)); Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture = remoteRepository.getYangTextSchemaSource(ID); assertTrue(retrievedSourceFuture.isCompleted()); YangTextSchemaSource resultSchemaSource = Await.result(retrievedSourceFuture, FiniteDuration.Zero()).getRepresentation(); assertEquals(resultSchemaSource.getIdentifier(), schemaSource.getIdentifier()); assertArrayEquals(resultSchemaSource.read(), schemaSource.read()); }
@Test(expected = SchemaSourceException.class) public void testGetNonExistentYangTextSchemaSource() throws Exception { Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn( Futures.immediateFailedFuture(new SchemaSourceException("Source is not provided"))); Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture = remoteRepository.getYangTextSchemaSource(ID); assertTrue(retrievedSourceFuture.isCompleted()); Await.result(retrievedSourceFuture, FiniteDuration.Zero()); }