Fix test failures in sal-binding-it 40/38040/1
authorTom Pantelis <tpanteli@brocade.com>
Fri, 22 Apr 2016 20:31:50 +0000 (16:31 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 22 Apr 2016 20:39:25 +0000 (16:39 -0400)
With the recent blueprint patch, the sal-binding-it integration tests
are failing in merge jobs (they don't run on veriy jobs) b/c they don't
install the blueprint bundle. I cobverted them from using the deprecated
TestHelper, which installs bundles, to using AbstractMdsalTestBase which
which installs features.

Also fixed a race condition in BindingToNormalizedNodeCodecFactory founf
when running the tests.

Change-Id: I06bbc33e7dbcb0bff557daccd8e1d87103bebc7d
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
features/mdsal/src/main/features/features.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodecFactory.java
opendaylight/md-sal/sal-binding-it/pom.xml
opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/AbstractIT.java
opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/DataServiceIT.java
opendaylight/md-sal/sal-binding-it/src/test/java/org/opendaylight/controller/test/sal/binding/it/RoutedServiceIT.java

index 897ec4ff18783f40e9f66ab626aae6523ca8e87b..ca5593d99368a9874e43b6a6eeef0b605f5a657b 100644 (file)
@@ -42,7 +42,7 @@
         <!-- FIXME: Bug 4202: Add MD-SAL provided odl-mdsal-dom-broker -->
         <bundle>mvn:org.opendaylight.controller/sal-core-api/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.controller/sal-core-spi/{{VERSION}}</bundle>
-        <bundle>mvn:org.opendaylight.controller/sal-broker-impl/{{VERSION}}</bundle>
+        <bundle start-level="70">mvn:org.opendaylight.controller/sal-broker-impl/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.controller/sal-binding-api/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.controller/sal-binding-broker-impl/{{VERSION}}</bundle>
         <bundle>mvn:org.opendaylight.controller/sal-binding-util/{{VERSION}}</bundle>
index a68ace70c63d21c7a00b3140206fab967f2e82cb..180f7b8f45a698bc5e847cd020074a8ae28263bb 100644 (file)
@@ -39,10 +39,15 @@ public class BindingToNormalizedNodeCodecFactory {
 
         BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
                 StreamWriterGenerator.create(SingletonHolder.JAVASSIST));
-        instance = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry, true);
+        BindingToNormalizedNodeCodec localInstance = new BindingToNormalizedNodeCodec(
+                classLoadingStrategy, codecRegistry, true);
 
-        schemaService.registerSchemaContextListener(instance);
+        schemaService.registerSchemaContextListener(localInstance);
 
+        // Publish the BindingToNormalizedNodeCodec instance after we've registered it as a
+        // SchemaContextListener to avoid a race condition by publishing it too early when it isn't
+        // fully initialized.
+        instance = localInstance;
         return instance;
     }
 
index f3561eb45151a865a0d9a95748f314300862b16f..b5d37c2e411655302a7f55a23de57b662daa27a4 100644 (file)
@@ -3,95 +3,22 @@
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.opendaylight.controller</groupId>
-    <artifactId>sal-parent</artifactId>
+    <artifactId>mdsal-it-parent</artifactId>
     <version>1.4.0-SNAPSHOT</version>
+    <relativePath/>
   </parent>
   <artifactId>sal-binding-it</artifactId>
 
   <dependencies>
-    <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-classic</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.tycho</groupId>
-      <artifactId>org.eclipse.osgi</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>javax.validation</groupId>
-      <artifactId>validation-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.persistence</groupId>
-      <artifactId>org.eclipse.persistence.core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.persistence</groupId>
-      <artifactId>org.eclipse.persistence.moxy</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>object-cache-guava</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-manager</artifactId>
+      <artifactId>features-mdsal</artifactId>
+      <classifier>features</classifier>
+      <type>xml</type>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-manager-facade-xml</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-persister-file-xml-adapter</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>config-persister-impl</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>logback-config</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-binding-broker-impl</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-binding-config</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-dom-broker-config</artifactId>
-    </dependency>
-    <dependency>
-      <!-- TODO Add this to odlparent -->
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr4-runtime</artifactId>
-      <version>4.5.1-1</version>
-    </dependency>
-
-    <!--Compile scopes for all testing dependencies are intentional-->
-    <!--This way, all testing dependencies can be transitively used by other integration test modules-->
-    <!--If the dependencies are test scoped, they are not visible to other maven modules depending on sal-binding-it-->
-
-    <!--TODO Create generic utilities(extract from this module) for integration tests on the controller-->
-    <dependency>
-      <groupId>openexi</groupId>
-      <artifactId>nagasena</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>openexi</groupId>
-      <artifactId>nagasena-rta</artifactId>
+      <artifactId>sal-test-model</artifactId>
     </dependency>
     <dependency>
       <groupId>org.ops4j.pax.exam</groupId>
                 tests. -->
       <scope>compile</scope>
     </dependency>
-    <dependency>
-      <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-container-native</artifactId>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-junit4</artifactId>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-link-mvn</artifactId>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>log4j-over-slf4j</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-test-model</artifactId>
-      <version>${mdsal.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.mdsal.model</groupId>
-      <artifactId>ietf-yang-types</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.mdsal.model</groupId>
-      <artifactId>ietf-inet-types</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.mdsal.model</groupId>
-      <artifactId>opendaylight-l2-types</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>javax.inject</groupId>
-      <artifactId>javax.inject</artifactId>
-      <version>1</version>
-    </dependency>
   </dependencies>
 
   <build>
-    <pluginManagement>
-      <plugins>
-        <!--This plugin's configuration is used to store Eclipse
-                    m2e settings only. It has no influence on the Maven build itself. -->
-        <plugin>
-          <groupId>org.eclipse.m2e</groupId>
-          <artifactId>lifecycle-mapping</artifactId>
-          <version>${lifecycle.mapping.version}</version>
-          <configuration>
-            <lifecycleMappingMetadata>
-              <pluginExecutions>
-                <pluginExecution>
-                  <pluginExecutionFilter>
-                    <groupId>org.ops4j.pax.exam</groupId>
-                    <artifactId>maven-paxexam-plugin</artifactId>
-                    <versionRange>[1.2.4,)</versionRange>
-                    <goals>
-                      <goal>generate-depends-file</goal>
-                    </goals>
-                  </pluginExecutionFilter>
-                  <action>
-                    <ignore></ignore>
-                  </action>
-                </pluginExecution>
-              </pluginExecutions>
-            </lifecycleMappingMetadata>
-          </configuration>
-        </plugin>
-      </plugins>
-    </pluginManagement>
     <plugins>
-      <plugin>
-        <groupId>org.ops4j.pax.exam</groupId>
-        <artifactId>maven-paxexam-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>generate-config</id>
-            <goals>
-              <goal>generate-depends-file</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-failsafe-plugin</artifactId>
+        <artifactId>maven-dependency-plugin</artifactId>
         <executions>
           <execution>
-              <goals>
-                  <goal>integration-test</goal>
-                  <goal>verify</goal>
-              </goals>
+           <id>unpack-karaf-resources</id>
+           <goals>
+            <goal>unpack-dependencies</goal>
+           </goals>
+           <phase>process-test-resources</phase>
+           <configuration>
+            <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+            <groupId>org.opendaylight.controller</groupId>
+            <includeArtifactIds>mockito-all,config-it-base,mdsal-it-base</includeArtifactIds>
+            <excludes>META-INF\/**</excludes>
+            <ignorePermissions>false</ignorePermissions>
+           </configuration>
           </execution>
-        </executions>
-        <!-- PAX EXAM tests sometimes takes longer to run if
-             not enough system resources are provided and
-             default timeout of two minutes may be not enough
-             on some jenkins jobs. In order to not loose
-             results of these tests, but to prevent this
-             tests of failing verifies sporadically
-             this test suites are optional and should not
-             fail build.
-         -->
-        <configuration>
-            <testFailureIgnore>true</testFailureIgnore>
-        </configuration>
+         </executions>
       </plugin>
     </plugins>
   </build>
index 10b40e3bedaebe757e9fd01131d35fad834b47bd..29a336e98ee168eb5496e91d0e46481a376459fb 100644 (file)
@@ -7,82 +7,47 @@
  */
 package org.opendaylight.controller.test.sal.binding.it;
 
-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.junitAndMockitoBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.salTestModelBundles;
+import static org.ops4j.pax.exam.CoreOptions.maven;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemPackages;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-
 import javax.inject.Inject;
 import org.junit.runner.RunWith;
+import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.util.Filter;
-import org.osgi.framework.BundleContext;
 
 @RunWith(PaxExam.class)
-public abstract class AbstractIT {
-
-    public static final String CONTROLLER = "org.opendaylight.controller";
-    public static final String YANGTOOLS = "org.opendaylight.yangtools";
-
-    public static final String CONTROLLER_MODELS = "org.opendaylight.controller.model";
-    public static final String YANGTOOLS_MODELS = "org.opendaylight.yangtools.model";
+public abstract class AbstractIT extends AbstractMdsalTestBase {
 
     @Inject
     @Filter(timeout=120*1000)
     BindingAwareBroker broker;
 
-    @Inject
-    BundleContext bundleContext;
-
-    public BindingAwareBroker getBroker() {
-        return broker;
+    @Override
+    public String getModuleName() {
+        return "binding-broker-impl";
     }
 
-    public void setBroker(final BindingAwareBroker broker) {
-        this.broker = broker;
+    @Override
+    public String getInstanceName() {
+        return "binding-broker-impl";
     }
 
-    public BundleContext getBundleContext() {
-        return bundleContext;
+    @Override
+    public MavenUrlReference getFeatureRepo() {
+        return maven().groupId("org.opendaylight.controller").artifactId("features-mdsal").classifier("features")
+                .type("xml").versionAsInProject();
     }
 
-    public void setBundleContext(final BundleContext bundleContext) {
-        this.bundleContext = bundleContext;
+    @Override
+    public String getFeatureName() {
+        return "odl-mdsal-broker";
     }
 
-    @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("openexi", "nagasena").versionAsInProject(),
-                mavenBundle("openexi", "nagasena-rta").versionAsInProject(),
-                 //
-                systemProperty("osgi.bundles.defaultStartLevel").value("4"),
-                systemPackages("sun.nio.ch"),
-
-                mdSalCoreBundles(),
-                configMinumumBundles(),
-                bindingAwareSalBundles(),
-
-                // BASE Models
-                baseModelBundles(),
-                salTestModelBundles(),
-
-                // Set fail if unresolved bundle present
-                systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
-                junitAndMockitoBundles());
+    @Override
+    protected Option[] getAdditionalOptions() {
+        return new Option[]{mavenBundle("org.opendaylight.controller", "sal-test-model").versionAsInProject()};
     }
-
 }
index dd95e03131e76f5b1fe1497bca4ea95dfc8cd688..717aa638114c5fb3779af6b00bed1d7b12817e9a 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.controller.test.sal.binding.it;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-
-import javax.inject.Inject;
 import java.util.concurrent.Future;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
@@ -19,7 +17,6 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerCo
 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
@@ -33,12 +30,8 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
  * covers creating, reading and deleting of an item in dataStore
  */
 public class DataServiceIT extends AbstractIT {
-
     protected DataBrokerService consumerDataService;
 
-    @Inject
-    Broker broker2;
-
     /**
      *
      * Ignored this, because classes here are constructed from
@@ -49,14 +42,15 @@ public class DataServiceIT extends AbstractIT {
      */
     @Test
     public void test() throws Exception {
-        BindingAwareConsumer consumer1 = new BindingAwareConsumer() {
+        BindingAwareConsumer consumer = new BindingAwareConsumer() {
 
             @Override
             public void onSessionInitialized(final ConsumerContext session) {
                 consumerDataService = session.getSALService(DataBrokerService.class);
             }
         };
-        broker.registerConsumer(consumer1);
+
+        broker.registerConsumer(consumer);
 
         assertNotNull(consumerDataService);
 
index c5833a8587461098a94ff040a2b433bab9f430cc..0b365cac49e7444b1ad280322b094f09e0b1613b 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertSame;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-
 import com.google.common.util.concurrent.Futures;
 import org.junit.Before;
 import org.junit.Test;
@@ -68,7 +67,7 @@ public class RoutedServiceIT extends AbstractIT {
     @Test
     public void testServiceRegistration() {
 
-        assertNotNull(getBroker());
+        assertNotNull(broker);
 
         final BindingAwareProvider provider1 = new AbstractTestProvider() {
             @Override