* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowjava.protocol.it.integration;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.junit.After;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
+import org.opendaylight.infrautils.diagstatus.ServiceRegistration;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;
import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
import org.slf4j.LoggerFactory;
/**
+ * End-to-end integration test.
+ *
* @author michal.polkorab
* @author timotej.kubas
*/
+@RunWith(MockitoJUnitRunner.class)
public class IntegrationTest {
private static final Logger LOGGER = LoggerFactory
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;
private MockPlugin mockPlugin;
private SwitchConnectionProviderImpl switchConnectionProvider;
private ConnectionConfigurationImpl connConfig;
+ @Mock
+ private ExecutorService executorService;
- 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 -------------------------------");
+ doAnswer(invocation -> {
+ invocation.getArgument(0, Runnable.class).run();
+ return null;
+ }).when(executorService).execute(ArgumentMatchers.any());
final String currentDir = System.getProperty("user.dir");
LOGGER.debug("Current dir using System: {}", currentDir);
tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,
"/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,
"/selfSignedController", PathType.CLASSPATH,
- new ArrayList<String>());
+ List.of());
}
- connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
+ connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration,
+ SWITCH_IDLE_TIMEOUT, true, false, CHANNEL_OUTBOUND_QUEUE_SIZE);
connConfig.setTransferProtocol(protocol);
- mockPlugin = new MockPlugin();
+ mockPlugin = new MockPlugin(executorService);
- switchConnectionProvider = new SwitchConnectionProviderImpl();
+ final var diagStatusService = mock(DiagStatusService.class);
+ doReturn(mock(ServiceRegistration.class)).when(diagStatusService).register(any());
+
+ switchConnectionProvider = new SwitchConnectionProviderImpl(diagStatusService, connConfig);
switchConnectionProvider.setSwitchConnectionHandler(mockPlugin);
- switchConnectionProvider.setConfiguration(connConfig);
switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
final TcpHandler tcpHandler = (TcpHandler) switchConnectionProvider.getServerFacade();
}
}
- /**
- * @throws Exception
- */
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
switchConnectionProvider.close();
LOGGER.debug("\n ending test -------------------------------");
}
/**
- * Library integration and communication test with handshake
- * @throws Exception
+ * Library integration and communication test with handshake.
*/
@Test
public void testHandshake() throws Exception {
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);
}
/**
- * Library integration and secured communication test with handshake
- * @throws Exception
+ * Library integration and secured communication test with handshake.
*/
@Test
public void testTlsHandshake() throws Exception {
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);
}
/**
- * 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 {
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();
}
/**
- * 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 {
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();
}
/**
- * 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 {
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();
}
/**
- * Library integration and communication test (with virtual machine)
- * @throws Exception
+ * Library integration and communication test (with virtual machine).
*/
//@Test
public void testCommunicationWithVM() throws Exception {
}
/**
- * @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());
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);