X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Flistener%2FNetconfDeviceCommunicatorTest.java;h=0ff5e2d3d50014dcaf5ddc6184e9fda4a1ecb295;hp=a24034d2f009700bd6d8bd3dd152783e19f0bfcd;hb=2e7af5f8377352ecdae3bace51417ee286dc6796;hpb=26f481389b07a10c111a62b3ad8f2a0a4a5713aa diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java index a24034d2f0..0ff5e2d3d5 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicatorTest.java @@ -56,10 +56,10 @@ import org.opendaylight.controller.netconf.api.NetconfTerminationReason; import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.NetconfClientSession; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; import org.opendaylight.controller.sal.connect.api.RemoteDevice; -import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator; import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; import org.opendaylight.protocol.framework.ReconnectStrategy; @@ -77,7 +77,7 @@ public class NetconfDeviceCommunicatorTest { NetconfClientSession mockSession; @Mock - RemoteDevice mockDevice; + RemoteDevice mockDevice; NetconfDeviceCommunicator communicator; @@ -85,16 +85,15 @@ public class NetconfDeviceCommunicatorTest { public void setUp() throws Exception { MockitoAnnotations.initMocks( this ); - communicator = new NetconfDeviceCommunicator( new RemoteDeviceId( "test" ), mockDevice ); + communicator = new NetconfDeviceCommunicator( new RemoteDeviceId( "test" ), mockDevice); } @SuppressWarnings("unchecked") - void setupSession() - { - doReturn( Collections.emptySet() ).when( mockSession ).getServerCapabilities(); - doNothing().when( mockDevice ).onRemoteSessionUp( any( NetconfSessionCapabilities.class ), - any( RemoteDeviceCommunicator.class ) ); - communicator.onSessionUp( mockSession ); + void setupSession() { + doReturn(Collections.emptySet()).when(mockSession).getServerCapabilities(); + doNothing().when(mockDevice).onRemoteSessionUp(any(NetconfSessionPreferences.class), + any(NetconfDeviceCommunicator.class)); + communicator.onSessionUp(mockSession); } private ListenableFuture> sendRequest() throws Exception { @@ -130,16 +129,16 @@ public class NetconfDeviceCommunicatorTest { testCapability ); doReturn( serverCapabilities ).when( mockSession ).getServerCapabilities(); - ArgumentCaptor netconfSessionCapabilities = - ArgumentCaptor.forClass( NetconfSessionCapabilities.class ); - doNothing().when( mockDevice ).onRemoteSessionUp( netconfSessionCapabilities.capture(), eq( communicator ) ); + ArgumentCaptor NetconfSessionPreferences = + ArgumentCaptor.forClass( NetconfSessionPreferences.class ); + doNothing().when( mockDevice ).onRemoteSessionUp( NetconfSessionPreferences.capture(), eq( communicator ) ); communicator.onSessionUp( mockSession ); verify( mockSession ).getServerCapabilities(); - verify( mockDevice ).onRemoteSessionUp( netconfSessionCapabilities.capture(), eq( communicator ) ); + verify( mockDevice ).onRemoteSessionUp( NetconfSessionPreferences.capture(), eq( communicator ) ); - NetconfSessionCapabilities actualCapabilites = netconfSessionCapabilities.getValue(); + NetconfSessionPreferences actualCapabilites = NetconfSessionPreferences.getValue(); assertEquals( "containsModuleCapability", true, actualCapabilites.containsNonModuleCapability( NetconfMessageTransformUtil.NETCONF_ROLLBACK_ON_ERROR_URI.toString()) ); assertEquals( "containsModuleCapability", false, actualCapabilites.containsNonModuleCapability(testCapability) ); @@ -297,6 +296,27 @@ public class NetconfDeviceCommunicatorTest { return new NetconfMessage( doc ); } + //Test scenario verifying whether missing message is handled + @Test + public void testOnMissingResponseMessage() throws Exception { + + setupSession(); + + String messageID1 = UUID.randomUUID().toString(); + ListenableFuture> resultFuture1 = sendRequest( messageID1 ); + + String messageID2 = UUID.randomUUID().toString(); + ListenableFuture> resultFuture2 = sendRequest( messageID2 ); + + String messageID3 = UUID.randomUUID().toString(); + ListenableFuture> resultFuture3 = sendRequest( messageID3 ); + + //response messages 1,2 are omitted + communicator.onMessage( mockSession, createSuccessResponseMessage( messageID3 ) ); + + verifyResponseMessage( resultFuture3.get(), messageID3 ); + } + @Test public void testOnSuccessfulResponseMessage() throws Exception { setupSession(); @@ -340,7 +360,7 @@ public class NetconfDeviceCommunicatorTest { */ @Test public void testNetconfDeviceReconnectInCommunicator() throws Exception { - final RemoteDevice device = mock(RemoteDevice.class); + final RemoteDevice device = mock(RemoteDevice.class); final TimedReconnectStrategy timedReconnectStrategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, 10000, 0, 1.0, null, 100L, null); final ReconnectStrategy reconnectStrategy = spy(new ReconnectStrategy() { @@ -360,11 +380,11 @@ public class NetconfDeviceCommunicatorTest { } }); - final NetconfDeviceCommunicator listener = new NetconfDeviceCommunicator(new RemoteDeviceId("test"), device); final EventLoopGroup group = new NioEventLoopGroup(); final Timer time = new HashedWheelTimer(); try { - final NetconfClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create() + final NetconfDeviceCommunicator listener = new NetconfDeviceCommunicator(new RemoteDeviceId("test"), device); + final NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create() .withAddress(new InetSocketAddress("localhost", 65000)) .withReconnectStrategy(reconnectStrategy) .withConnectStrategyFactory(new ReconnectStrategyFactory() { @@ -379,7 +399,6 @@ public class NetconfDeviceCommunicatorTest { .withSessionListener(listener) .build(); - listener.initializeRemoteConnection(new NetconfClientDispatcherImpl(group, group, time), cfg); verify(reconnectStrategy, timeout((int) TimeUnit.MINUTES.toMillis(3)).times(101)).scheduleReconnect(any(Throwable.class));