bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
527 stars 305 forks source link

Bnd 6.3.1 Junit 5 Gradle 7.4.2 - Integration test not work #5298

Closed jcommand closed 2 years ago

jcommand commented 2 years ago

When converting an old project from bnd 4.2 and osgi 5 to bnd 6.3.1 and osgi 7, I am unable to run the integration tests using Gradle. In Eclipse the execution of the integration tests works.

I use the Gradle BND Workspace plugin. In Eclipse I import the projects using the BND Workspace project. The tests are executed using bnd.bnd test, which in turn includes a jcommand.bndrun.

When running "./gradlew build" the OSGi instance is started (testOSGi). All bundles are started. Once all bundles are started and the gogo shell offers a console, all bundles are stopped again. Shortly before the end either an interrupt exception is thrown or a test is executed which fails because the service to be tested is no longer available.

When running the same bnd.bnd file in Eclipse with the BndTools 6.3.1 the tests are executed correctly and then the bundles are stopped.


settings.gradle

pluginManagement {
  plugins {
    id "biz.aQute.bnd.workspace" version bnd_version
  }
  repositories {
    maven {
      url = uri(bnd_snapshots)
    }
    mavenCentral()
    gradlePluginPortal()
  }
}
plugins {
  id "biz.aQute.bnd.workspace"
}

bnd.bnd

-include:  ./jcommand.bndrun, ${workspace}/cnf/includes/jdt.bnd
Bundle-Version: 1.0.0.${tstamp}
-buildpath: \
    ${osgi_base},\
    ${junit},\
    ${mockito},\
    ${osgitest},\
    ...
Test-Cases: \
    ${classes;NAMED;*Test}
Require-Bundle: \
    org.hamcrest.core,\
    org.hamcrest.library    
Provide-Capability: osgi.extender;  osgi.extender=org.jcommand.model; version:Version="1.0"
-runfw: org.apache.felix.framework;version='[7.0.5,7.0.5]'
-runee: JavaSE-17

jcommand.bndrun

-include: ${workspace}/cnf/ext/test.bnd
-runfw: org.apache.felix.framework;version='[7.0.5,7.0.5]'
-runsystemcapabilities: ${native_capability}
-resolve.effective: active
-runrepos: \
    TP,\
    Build,\
    Maven_Central
-runtrace: false 
-runrequires: \
    ...
    bnd.identity;id=junit-jupiter-engine,\
    bnd.identity;id=junit-vintage-engine,\
    bnd.identity;id='biz.aQute.tester.junit-platform',\
    bnd.identity;id='${basename;${.}}',\
-tester: biz.aQute.tester.junit-platform
-runproperties: \
    felix.cm.pm=jcommand
-runvm: -Xmx512m
-runee: JavaSE-17
-resolve: manual
-runbundles: \
...
    junit-jupiter-api;version='[5.8.2,5.8.3)',\
    junit-jupiter-engine;version='[5.8.2,5.8.3)',\
    junit-platform-commons;version='[1.8.2,1.8.3)',\
    junit-platform-engine;version='[1.8.2,1.8.3)',\
    org.hamcrest.core;version='[1.3.0,1.3.1)',\
    org.hamcrest.library;version='[1.3.0,1.3.1)',\
    junit-vintage-engine;version='[5.8.2,5.8.3)',\
    org.junit;version='[4.12.0,4.12.1)',\
    junit-platform-launcher;version='[1.8.2,1.8.3)',\
    biz.aQute.tester.junit-platform;version='[6.3.1,6.3.2)'

${workspace}/cnf/includes/jdt.bnd

osgi_base: osgi.annotation;version='0',\
    osgi.core;version='7.0.0',\
    osgi.cmpn;version='7.0.0'

${workspace}/cnf/ext/test.bnd

junit_jupiter_version: 5.8.2
junit_platform_version: 1.8.2
assertj_version: 3.23.1
mockito_version: 4.6.1
bytebuddy_version: 1.12.10
osgi_test_version: 1.1.0
junit: \
    junit-platform-commons;version=latest,\
    junit-platform-engine;version=latest,\
    assertj-core;version=latest,\
    org.opentest4j;version=latest,\
    org.apiguardian:apiguardian-api;version=latest,\
    junit-jupiter-api;version=latest,\
    junit-jupiter-engine;version=latest,\
    junit-jupiter-params;version=latest
mockito: org.mockito.mockito-core;version=latest,\
    net.bytebuddy.byte-buddy;version=latest,\
    org.objenesis;version=latest
-runsystempackages.objenesis: sun.misc,sun.reflect
osgitest: \
    org.osgi.test.common;version=latest,\
    org.osgi.test.junit5;version=latest,\
    org.osgi.test.assertj.framework;version=latest
bjhargrave commented 2 years ago

I don't see the description of a bug in Bnd anywhere in here. You seem to be asking for help to make your build work.

Usage questions should be asked in the Bnd Discourse Group. See https://github.com/bndtools/bnd#feedback.

A couple of things. The bnd.bnd file should not be including a bndrun file. The bnd.bnd file is the instructions to make the project's bundles while bndrun files are for executions. They are separate and both inherit from the workspace. So the bndrun file should not be including from cnf/ext since the workspace already includes those files.

jcommand commented 2 years ago

The bug is that one BND definition in two tools lead to different results (deterministic behavior?). The question is, is it the BND Eclipse plugin or the Gradle plugin that has a bug. My guess is the Gradle plugin.

I will move the other info to the user group.

Maybe I have misunderstood. But I thought the /cnf/build.bnd is the default build file. And if I want to include another one I have to include it.

The Gradle plugin always uses the bnd.bnd for the task build. So that the Run/Integration Test Config does not have to be stored in the bnd.bnd file, I have swapped it out into a bndrun file and then included it in the bnd.bnd file.

Thanks and greetings Frank

bjhargrave commented 2 years ago

But I thought the /cnf/build.bnd is the default build file.

cnf configures the Workspace from which all Projects and bndruns inherit. The Workspace is useful for defining the repositories and common properties and instructions for all projects.

If you have a specific bndrun file you want the testOSGi task to use, then you will need to configure that in the project's gradle script. For example, https://github.com/osgi/osgi-test/blob/main/examples/osgi-test-example-bndworkspace/org.osgi.test.example.player.test/build.gradle

See https://github.com/osgi/osgi-test/tree/main/examples/osgi-test-example-bndworkspace for a complete working example of a Bnd Workspace which uses a bndrun file to do OSGi testing.

bjhargrave commented 2 years ago

Closing as no issue evident. If you have other usage questions, they should be asked in the Bnd Discourse Group. See https://github.com/bndtools/bnd#feedback.