BUG-837: it unstable (timeout to 60s)
[openflowplugin.git] / openflowplugin-it / src / test / java / org / opendaylight / openflowplugin / openflow / md / it / OFPluginToLibraryTest.java
index 1a94d5d6cbc53a257c1022917946dc2b587bc8c9..a565e7a4fc8e9622721d8c4edd65a5ef490b45a8 100644 (file)
@@ -10,13 +10,13 @@ package org.opendaylight.openflowplugin.openflow.md.it;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.util.Stack;
+import java.util.Deque;
+import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -25,6 +25,7 @@ import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
 import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
@@ -46,13 +47,16 @@ public class OFPluginToLibraryTest {
     private static final Logger LOG = LoggerFactory
             .getLogger(OFPluginToLibraryTest.class);
 
-    @Inject @Filter(timeout=5000)
+    private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
+
+    @Inject @Filter(timeout=60000)
     OpenflowPluginProvider openflowPluginProvider;
 
-    @Inject
+    @Inject @Filter(timeout=60000)
     BundleContext ctx;
 
     private SimpleClient switchSim;
+    private ThreadPoolLoggingExecutor scenarioPool;
 
     /**
      * test setup
@@ -61,8 +65,8 @@ public class OFPluginToLibraryTest {
     @Before
     public void setUp() throws InterruptedException {
         LOG.debug("openflowPluginProvider: "+openflowPluginProvider);
-        //FIXME: plugin should provide service exposing startup result via future
-        Thread.sleep(5000);
+        switchSim = createSimpleClient();
+        scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
     }
 
     /**
@@ -70,26 +74,8 @@ public class OFPluginToLibraryTest {
      */
     @After
     public void tearDown() {
-        try {
-            LOG.debug("tearing down simulator");
-            switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
-        } catch (Exception e) {
-            String msg = "waiting for scenario to finish failed: "+e.getMessage();
-            LOG.error(msg, e);
-            Assert.fail(msg);
-        }
-
-        //TODO: dump errors of plugin (by exploiting ErrorHandler)
-
-        try {
-            LOG.debug("checking if simulator succeeded to connect to controller");
-            boolean simulatorWasOnline = switchSim.getIsOnlineFuture().get(100, TimeUnit.MILLISECONDS);
-            Assert.assertTrue("simulator failed to connect to controller", simulatorWasOnline);
-        } catch (Exception e) {
-            String message = "simulator probably failed to connect to controller";
-            LOG.error(message, e);
-            Assert.fail(message);
-        }
+        SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
+        SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
     }
 
     /**
@@ -100,14 +86,13 @@ public class OFPluginToLibraryTest {
     public void handshakeOk1() throws Exception {
         LOG.debug("handshakeOk1 integration test");
 
-        switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
-                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenarioVBM(
+                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true);
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -120,12 +105,12 @@ public class OFPluginToLibraryTest {
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario(
                 (short) 0, ScenarioFactory.VERSION_BITMAP_10_13);
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -139,12 +124,12 @@ public class OFPluginToLibraryTest {
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 1,
                 ScenarioFactory.VERSION_BITMAP_10_13);
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -159,13 +144,12 @@ public class OFPluginToLibraryTest {
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory.createHandshakeScenario((short) 0,
                 ScenarioFactory.VERSION_BITMAP_10_13);
-        handshakeScenario.setElementAt(new SleepEvent(5000), 0);
-
+        handshakeScenario.addFirst(new SleepEvent(5000));
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -183,7 +167,7 @@ public class OFPluginToLibraryTest {
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory
                 .createHandshakeScenarioNoVBM_OF10_TwoHello();
         // handshakeScenario.setElementAt(new SleepEvent(5000),
         // handshakeScenario
@@ -191,7 +175,7 @@ public class OFPluginToLibraryTest {
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -209,12 +193,12 @@ public class OFPluginToLibraryTest {
 
         switchSim = createSimpleClient();
         switchSim.setSecuredClient(false);
-        Stack<ClientEvent> handshakeScenario = ScenarioFactory
+        Deque<ClientEvent> handshakeScenario = ScenarioFactory
                 .createHandshakeScenarioNOVBM_OF10_OneHello();
 
         ScenarioHandler scenario = new ScenarioHandler(handshakeScenario);
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
+        scenarioPool.execute(switchSim);
     }
 
     /**
@@ -250,7 +234,6 @@ public class OFPluginToLibraryTest {
                 TestHelper.mdSalCoreBundles(),
                 TestHelper.configMinumumBundles(),
                 TestHelper.baseModelBundles(),
-                TestHelper.flowCapableModelBundles(),
 
                 OFPaxOptionsAssistant.ofPluginBundles());
     }