Merge "Add timeout to netconf IT test"
authorTony Tkacik <ttkacik@cisco.com>
Wed, 7 Jan 2015 09:42:01 +0000 (09:42 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 7 Jan 2015 09:42:02 +0000 (09:42 +0000)
1  2 
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java

index bd8e2ed4df623f4c96051429f70cadc11ed9b17f,31986b8afe522be41e1844714cd895d819b259ed..7d568b64628f82ec6499d1d9288ef6eb54b0c572
@@@ -41,6 -41,8 +41,6 @@@ import org.apache.sshd.server.session.S
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
 -import org.mockito.Mock;
 -import org.mockito.MockitoAnnotations;
  import org.opendaylight.controller.netconf.api.NetconfMessage;
  import org.opendaylight.controller.netconf.auth.AuthProvider;
  import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
@@@ -106,15 -108,15 +106,15 @@@ public class NetconfITSecureTest extend
      @After
      public void tearDown() throws Exception {
          sshProxyServer.close();
-         clientGroup.shutdownGracefully().await();
+         clientGroup.shutdownGracefully();
          minaTimerEx.shutdownNow();
          nioExec.shutdownNow();
      }
  
-     @Test
+     @Test(timeout = 2*60*1000)
      public void testSecure() throws Exception {
          final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
 -        try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener()))) {
 +        try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener(), TLS_ADDRESS))) {
              NetconfMessage response = netconfClient.sendMessage(getGetConfig());
              assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()),
                      NetconfMessageUtil.isErrorMessage(response));
  
          final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
          final NetconfDeviceCommunicator sessionListener = getSessionListener();
 -        try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener))) {
 +        try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener, TLS_ADDRESS))) {
  
              final AtomicInteger responseCounter = new AtomicInteger(0);
              final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = Lists.newArrayList();
          }
      }
  
 -    private NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException {
 +    public static NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException {
          String s = XmlUtil.toString(getConfig.getDocument(), false);
          s = s.replace("101", Integer.toString(i));
          return new NetconfMessage(XmlUtil.readXmlToDocument(s));
      }
  
 -    public NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener) throws IOException {
 +    static NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener,final InetSocketAddress tlsAddress) throws IOException {
          final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
 -        b.withAddress(TLS_ADDRESS);
 +        b.withAddress(tlsAddress);
          // Using session listener from sal-netconf-connector since stress test cannot be performed with simple listener
          b.withSessionListener(sessionListener);
          b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
          return b.build();
      }
  
 -    @Mock
 -    private RemoteDevice<NetconfSessionCapabilities, NetconfMessage> mockedRemoteDevice;
 -
 -    private NetconfDeviceCommunicator getSessionListener() {
 -        MockitoAnnotations.initMocks(this);
 +    static NetconfDeviceCommunicator getSessionListener() {
 +        RemoteDevice<NetconfSessionCapabilities, NetconfMessage> mockedRemoteDevice = mock(RemoteDevice.class);
          doNothing().when(mockedRemoteDevice).onRemoteSessionUp(any(NetconfSessionCapabilities.class), any(RemoteDeviceCommunicator.class));
          doNothing().when(mockedRemoteDevice).onRemoteSessionDown();
          return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test"), mockedRemoteDevice);
          return mockAuth;
      }
  
 -    public AuthenticationHandler getAuthHandler() throws IOException {
 +    public static AuthenticationHandler getAuthHandler() throws IOException {
          return new LoginPassword(USERNAME, PASSWORD);
      }