Search in sources :

Example 6 with SchemaResolutionException

use of org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException 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

SchemaResolutionException (org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException)6 EffectiveModelContextFactory (org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory)5 Test (org.junit.Test)4 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)4 IOException (java.io.IOException)3 HashMultimap (com.google.common.collect.HashMultimap)2 Iterables (com.google.common.collect.Iterables)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 Futures (com.google.common.util.concurrent.Futures)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2