BUG-837: it unstable (added missing bundles)
[openflowplugin.git] / openflowplugin-it / src / test / java / org / opendaylight / openflowplugin / openflow / md / it / SalIntegrationTest.java
index 541319d76ba3b1cc36264917ee28ef522092188f..f7483aa3b2c834885b61dd3848da729c3b81e572 100644 (file)
@@ -1,32 +1,37 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.openflowplugin.openflow.md.it;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import javax.inject.Inject;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
+import org.opendaylight.controller.test.sal.binding.it.TestHelper;
 import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;
 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
-import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
@@ -35,47 +40,65 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Openday
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * @author mirehak
+ * Exercise inventory listener ({@link OpendaylightInventoryListener#onNodeUpdated(NodeUpdated)})
  */
-//@RunWith(PaxExam.class)
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
 public class SalIntegrationTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
-
-    /** base controller package */
-    public static final String ODL = "org.opendaylight.controller";
-    /** controller.model package */
-    public static final String ODL_MODEL = "org.opendaylight.controller.model";
-    /** yangtools package */
-    public static final String YANG = "org.opendaylight.yangtools";
-    /** yangtools.model package */
-    public static final String YANG_MODEL = "org.opendaylight.yangtools.model";
-    /** OFPlugin package */
-    public static final String OFPLUGIN = "org.opendaylight.openflowplugin";
-    /** OFLibrary package */
-    public static final String OFLIBRARY = "org.opendaylight.openflowjava";
-    /** netty.io package */
-    public static final String NETTY = "io.netty";
-
-    @Inject
-    SwitchConnectionProvider switchConnectionProvider;
-
-    @Inject
+    static final Logger LOG = LoggerFactory.getLogger(SalIntegrationTest.class);
+
+    private final ArrayBlockingQueue<Runnable> SCENARIO_POOL_QUEUE = new ArrayBlockingQueue<>(1);
+    private ThreadPoolLoggingExecutor scenarioPool;
+    private SimpleClient switchSim;
+    private Runnable finalCheck;
+
+    @Inject @Filter(timeout=60*000)
     BundleContext ctx;
 
-    @Inject
+    @Inject @Filter(timeout=60*1000)
     BindingAwareBroker broker;
 
+    @Inject @Filter(timeout=60*1000)
+    OpenflowPluginProvider openflowPluginProvider;
+
     /**
      * @return timeout for case of failure
      */
-    private static long getFailSafeTimeout() {
-        return 20000;
+    static long getFailSafeTimeout() {
+        return 30000;
+    }
+
+    /**
+     * test setup
+     * @throws InterruptedException
+     */
+    @Before
+    public void setUp() throws InterruptedException {
+        switchSim = new SimpleClient("localhost", 6653);
+        scenarioPool = new ThreadPoolLoggingExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, SCENARIO_POOL_QUEUE, "scenario");
+    }
+
+    /**
+     * test tear down
+     */
+    @After
+    public void tearDown() {
+        SimulatorAssistant.waitForSwitchSimulatorOn(switchSim);
+        SimulatorAssistant.tearDownSwitchSimulatorAfterScenario(switchSim, scenarioPool, getFailSafeTimeout());
+
+        if (finalCheck != null) {
+            LOG.info("starting final check");
+            finalCheck.run();
+        }
     }
 
     /**
@@ -83,7 +106,7 @@ public class SalIntegrationTest {
      *
      * @throws Exception
      */
-    //@Test
+    @Test
     public void handshakeAndNodeUpdate() throws Exception {
 
         final TestInventoryListener listener = new TestInventoryListener();
@@ -98,20 +121,21 @@ public class SalIntegrationTest {
         assertNotNull(consumerReg);
 
         LOG.debug("handshake integration test");
-        LOG.debug("switchConnectionProvider: " + switchConnectionProvider);
+        LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
 
-        SimpleClient switchSim = new SimpleClient("localhost", 6653);
         switchSim.setSecuredClient(false);
         ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(
-                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13));
+                ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
         switchSim.setScenarioHandler(scenario);
-        switchSim.start();
-
-        switchSim.getScenarioDone().get(getFailSafeTimeout(), TimeUnit.MILLISECONDS);
-        Thread.sleep(2000);
-        assertEquals(1, listener.nodeUpdated.size());
-        assertNotNull(listener.nodeUpdated.get(0));
+        scenarioPool.execute(switchSim);
 
+        finalCheck = new Runnable() {
+            @Override
+            public void run() {
+                assertEquals(1, listener.nodeUpdated.size());
+                assertNotNull(listener.nodeUpdated.get(0));
+            }
+        };
     }
 
     /**
@@ -119,34 +143,14 @@ public class SalIntegrationTest {
      */
     @Configuration
     public Option[] config() {
-        return options(systemProperty("osgi.console").value("2401"),
-                mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
-                mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(),
-                mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(),
-                mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(),
-
-                mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
-
-                mavenBundle(OFLIBRARY, "openflow-protocol-impl").versionAsInProject(),
-                mavenBundle(OFLIBRARY, "openflow-protocol-api").versionAsInProject(),
-                mavenBundle(OFLIBRARY, "openflow-protocol-spi").versionAsInProject(),
-
-                mavenBundle(ODL, "sal").versionAsInProject(),
-                mavenBundle(ODL, "sal.connection").versionAsInProject(),
-                mdSalCoreBundles(), baseModelBundles(), flowCapableModelBundles(),
-                configMinumumBundles(),
-
-                bindingAwareSalBundles(),
-
-                mavenBundle(NETTY, "netty-handler").versionAsInProject(),
-                mavenBundle(NETTY, "netty-buffer").versionAsInProject(),
-                mavenBundle(NETTY, "netty-common").versionAsInProject(),
-                mavenBundle(NETTY, "netty-transport").versionAsInProject(),
-                mavenBundle(NETTY, "netty-codec").versionAsInProject(),
-
-                mavenBundle(OFLIBRARY, "simple-client").versionAsInProject().start(),
-                mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(), junitBundles()
-                );
+        return options(
+                systemProperty("osgi.console").value("2401"),
+                systemProperty("osgi.bundles.defaultStartLevel").value("4"),
+                systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
+
+                OFPaxOptionsAssistant.osgiConsoleBundles(),
+                OFPaxOptionsAssistant.loggingBudles(),
+                OFPaxOptionsAssistant.ofPluginBundles());
     }
 
     private static class TestInventoryListener implements OpendaylightInventoryListener {