report diagstatus from UdpHandler/TcpHandler on Netty thread terminate
[openflowplugin.git] / openflowjava / openflow-protocol-it / src / test / java / org / opendaylight / openflowjava / protocol / it / integration / IntegrationTest.java
index a747df745d3141a87a4d8860ba954979f9930133..92c9d64bc9df7089c15431e000ec6a0e6d5d556c 100644 (file)
@@ -14,8 +14,11 @@ import java.util.Deque;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import org.junit.After;
 import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;
 import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
@@ -40,6 +43,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
+ * End-to-end integration test.
+ *
  * @author michal.polkorab
  * @author timotej.kubas
  */
@@ -50,6 +55,7 @@ public class IntegrationTest {
 
     private static int port;
     private TlsConfiguration tlsConfiguration;
+    private static final int CHANNEL_OUTBOUND_QUEUE_SIZE = 1024;
     private static final int SWITCH_IDLE_TIMEOUT = 2000;
     private static final long CONNECTION_TIMEOUT = 2000;
     private InetAddress startupAddress;
@@ -57,13 +63,13 @@ public class IntegrationTest {
     private SwitchConnectionProviderImpl switchConnectionProvider;
     private ConnectionConfigurationImpl connConfig;
 
-    private Thread t;
+    private Thread thread;
+
+    private enum ClientType {
+        SIMPLE,
+        LISTENING
+    }
 
-    private enum ClientType {SIMPLE, LISTENING}
-    /**
-     * @param protocol communication protocol to be used during test
-     * @throws Exception
-     */
     public void setUp(final TransportProtocol protocol) throws Exception {
         LOGGER.debug("\n starting test -------------------------------");
 
@@ -77,11 +83,12 @@ public class IntegrationTest {
                     "/selfSignedController", PathType.CLASSPATH,
                     new ArrayList<String>());
         }
-        connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
+        connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration,
+                SWITCH_IDLE_TIMEOUT, true, false, CHANNEL_OUTBOUND_QUEUE_SIZE);
         connConfig.setTransferProtocol(protocol);
         mockPlugin = new MockPlugin();
 
-        switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig);
+        switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig, Mockito.mock(DiagStatusService.class));
         switchConnectionProvider.setSwitchConnectionHandler(mockPlugin);
         switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
         if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
@@ -93,9 +100,6 @@ public class IntegrationTest {
         }
     }
 
-    /**
-     * @throws Exception
-     */
     @After
     public void tearDown() throws Exception {
         switchConnectionProvider.close();
@@ -103,8 +107,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library integration and communication test with handshake
-     * @throws Exception
+     * Library integration and communication test with handshake.
      */
     @Test
     public void testHandshake() throws Exception {
@@ -112,7 +115,8 @@ public class IntegrationTest {
         final int amountOfCLients = 1;
         final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
         final ScenarioHandler handler = new ScenarioHandler(scenario);
-        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
+        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+                TransportProtocol.TCP, ClientType.SIMPLE);
         final OFClient firstClient = clients.get(0);
         firstClient.getScenarioDone().get();
         Thread.sleep(1000);
@@ -121,8 +125,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library integration and secured communication test with handshake
-     * @throws Exception
+     * Library integration and secured communication test with handshake.
      */
     @Test
     public void testTlsHandshake() throws Exception {
@@ -130,7 +133,8 @@ public class IntegrationTest {
         final int amountOfCLients = 1;
         final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
         final ScenarioHandler handler = new ScenarioHandler(scenario);
-        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
+        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+                TransportProtocol.TLS, ClientType.SIMPLE);
         final OFClient firstClient = clients.get(0);
         firstClient.getScenarioDone().get();
         Thread.sleep(1000);
@@ -139,8 +143,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library integration and communication test with handshake + echo exchange
-     * @throws Exception
+     * Library integration and communication test with handshake + echo exchange.
      */
     @Test
     public void testHandshakeAndEcho() throws Exception {
@@ -152,7 +155,8 @@ public class IntegrationTest {
         scenario.addFirst(new SleepEvent(1000));
         scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         final ScenarioHandler handler = new ScenarioHandler(scenario);
-        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
+        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+                TransportProtocol.TCP, ClientType.SIMPLE);
         final OFClient firstClient = clients.get(0);
         firstClient.getScenarioDone().get();
 
@@ -160,8 +164,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library integration and secured communication test with handshake + echo exchange
-     * @throws Exception
+     * Library integration and secured communication test with handshake + echo exchange.
      */
     @Test
     public void testTlsHandshakeAndEcho() throws Exception {
@@ -173,7 +176,8 @@ public class IntegrationTest {
         scenario.addFirst(new SleepEvent(1000));
         scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         final ScenarioHandler handler = new ScenarioHandler(scenario);
-        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
+        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+                TransportProtocol.TLS, ClientType.SIMPLE);
         final OFClient firstClient = clients.get(0);
         firstClient.getScenarioDone().get();
 
@@ -181,8 +185,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library udp integration and communication test with handshake + echo exchange
-     * @throws Exception
+     * Library udp integration and communication test with handshake + echo exchange.
      */
     @Test
     public void testUdpHandshakeAndEcho() throws Exception {
@@ -194,7 +197,8 @@ public class IntegrationTest {
         scenario.addFirst(new SleepEvent(1000));
         scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
         final ScenarioHandler handler = new ScenarioHandler(scenario);
-        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP, ClientType.SIMPLE);
+        final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+                TransportProtocol.UDP, ClientType.SIMPLE);
         final OFClient firstClient = clients.get(0);
         firstClient.getScenarioDone().get();
 
@@ -202,8 +206,7 @@ public class IntegrationTest {
     }
 
     /**
-     * Library integration and communication test (with virtual machine)
-     * @throws Exception
+     * Library integration and communication test (with virtual machine).
      */
     //@Test
     public void testCommunicationWithVM() throws Exception {
@@ -211,13 +214,16 @@ public class IntegrationTest {
     }
 
     /**
-     * @param amountOfCLients
+     * Creates and start a client.
+     *
+     * @param amountOfCLients number of clients
      * @param protocol true if encrypted connection should be used
      * @return new clients up and running
      * @throws ExecutionException if some client could not start
      */
     private List<OFClient> createAndStartClient(final int amountOfCLients, final ScenarioHandler scenarioHandler,
-            final TransportProtocol protocol, final ClientType clientType) throws ExecutionException {
+            final TransportProtocol protocol, final ClientType clientType)
+                    throws ExecutionException, InterruptedException, TimeoutException {
         final List<OFClient> clientsHorde = new ArrayList<>();
         for (int i = 0; i < amountOfCLients; i++) {
             LOGGER.debug("startup address in createclient: {}", startupAddress.getHostAddress());
@@ -244,23 +250,15 @@ public class IntegrationTest {
             sc.setScenarioHandler(scenarioHandler);
             clientsHorde.add(sc);
             //sc.run();
-            t = new Thread(sc);
-            t.start();
+            thread = new Thread(sc);
+            thread.start();
         }
         for (final OFClient sc : clientsHorde) {
-            try {
-                sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
-            } catch (final Exception e) {
-                LOGGER.error("createAndStartClient: Something borked ... ", e.getMessage(), e);
-                throw new ExecutionException(e);
-            }
+            sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
         }
         return clientsHorde;
     }
 
-    /**
-     * @throws Exception
-     */
     @Test
     public void testInitiateConnection() throws Exception {
         setUp(TransportProtocol.TCP);