use of org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory in project netconf by opendaylight.
the class NetconfNodeActorTest method testRegisterMountPointWithSchemaFailures.
@SuppressWarnings("unchecked")
@Test
public void testRegisterMountPointWithSchemaFailures() throws Exception {
SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setBaseSchemas(BASE_SCHEMAS).setActorSystem(system).build();
final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService));
// Test unrecoverable failure.
doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock"))).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
testKit.expectMsgClass(Success.class);
verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
verify(mockMountPointBuilder, after(1000).never()).register();
verify(mockSchemaSourceReg1, timeout(1000)).close();
verify(mockSchemaSourceReg2, timeout(1000)).close();
// Test recoverable AskTimeoutException - schema context resolution should be retried.
reset(mockSchemaSourceReg1, mockSchemaSourceReg2);
doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock", new AskTimeoutException("timeout")))).doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
testKit.expectMsgClass(Success.class);
verify(mockMountPointBuilder, timeout(5000)).register();
verifyNoMoreInteractions(mockSchemaSourceReg1, mockSchemaSourceReg2);
// Test AskTimeoutException with an interleaved successful registration. The first schema context resolution
// attempt should not be retried.
reset(mockSchemaSourceReg1, mockSchemaSourceReg2, mockSchemaRepository, mockSchemaContextFactory);
resetMountPointMocks();
final EffectiveModelContextFactory mockSchemaContextFactorySuccess = mock(EffectiveModelContextFactory.class);
doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactorySuccess).createEffectiveModelContext(anyCollection());
doAnswer(unused -> {
SettableFuture<SchemaContext> future = SettableFuture.create();
new Thread(() -> {
doReturn(mockSchemaContextFactorySuccess).when(mockSchemaRepository).createEffectiveModelContextFactory();
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).createEffectiveModelContext(anyCollection());
doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
verify(mockMountPointBuilder, timeout(5000)).register();
verify(mockSchemaRepository, times(2)).createEffectiveModelContextFactory();
}
Aggregations