Search in sources :

Example 21 with EffectiveModelContextFactory

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();
}
Also used : SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) AskTimeoutException(akka.pattern.AskTimeoutException) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) Test(org.junit.Test)

Aggregations

EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)21 Test (org.junit.Test)19 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)10 NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)10 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)10 Collection (java.util.Collection)9 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)9 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)8 SchemaResolutionException (org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException)8 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)7 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)7 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)7 HashMap (java.util.HashMap)6 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)6 HashMultimap (com.google.common.collect.HashMultimap)5 Iterables (com.google.common.collect.Iterables)5 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 Futures (com.google.common.util.concurrent.Futures)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5