+ final SchemaContextFactory mockSchemaContextFactorySuccess = mock(SchemaContextFactory.class);
+ doReturn(Futures.immediateFuture(mockSchemaContext))
+ .when(mockSchemaContextFactorySuccess).createSchemaContext(any());
+
+ doAnswer(unused -> {
+ SettableFuture<SchemaContext> future = SettableFuture.create();
+ new Thread(() -> {
+ doReturn(mockSchemaContextFactorySuccess).when(mockSchemaRepository)
+ .createSchemaContextFactory(any(SchemaSourceFilter.class));
+
+ slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2),
+ masterRef), testKit.getRef());
+
+ future.setException(new SchemaResolutionException("mock", new AskTimeoutException("timeout")));
+ }).start();
+ return future;
+ }).when(mockSchemaContextFactory).createSchemaContext(any());
+
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository)
+ .createSchemaContextFactory(any(SchemaSourceFilter.class));
+
+ slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2),
+ masterRef), testKit.getRef());
+
+ verify(mockMountPointBuilder, timeout(5000)).register();
+ verify(mockSchemaRepository, times(2)).createSchemaContextFactory(any(SchemaSourceFilter.class));
+ }
+
+ @Test(expected = MissingSchemaSourceException.class)
+ public void testMissingSchemaSourceOnMissingProvider() throws Exception {
+ SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
+ doReturn(DEFAULT_SCHEMA_REPOSITORY).when(schemaResourceDTO2).getSchemaRegistry();
+ doReturn(DEFAULT_SCHEMA_REPOSITORY).when(schemaResourceDTO2).getSchemaRepository();
+ final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
+ .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).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());
+ }
+
+ @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());