ops4j / org.ops4j.pax.exam2

Pax Exam is a testing framework for OSGi
https://ops4j1.jira.com/wiki/spaces/PAXEXAM4/
Apache License 2.0
84 stars 100 forks source link

Error "Problem starting container" when using customized Karaf distribution [PAXEXAM-615] #725

Open ops4j-issues opened 10 years ago

ops4j-issues commented 10 years ago

Lukas Roedl created PAXEXAM-615

Following the manual at http://karaf.apache.org/manual/latest-2.3.x/developers-guide/writing-tests.html#KarafDistributionConfigurationOption I tried to write integration tests based on a custom Karaf distribution.
I used the following to configure the container:

...
karafDistributionConfiguration()
    .frameworkUrl(
            maven()
            .groupId("at.ac.ait.hbs.homer")
            .artifactId("at.ac.ait.hbs.homer.core.distribution.assemblies.stable")
            .type("zip")
            .version("1.2.7-SNAPSHOT")
    )
    .karafVersion(KARAF_VERSION)
    .name("Apache Karaf")
    .unpackDirectory(new File(UNPACK_DIRECTORY)),
...

When running the tests I get an "java.lang.RuntimeException: Problem starting container" error. When looking into the "target\exam\<random>\" folder (= UNPACK_DIRECTORY) there is really a mess:

DISCLAIMER.txt
LICENSE.txt
README.txt
...
bin\
...
config.properties
custom.properties
endorsed\
ext\
...
karaf.bat
karaf.jar
keys.properties
org\
...
system.properties
tmp\
users.properties

What I expected was the default Karaf distribution layout:

bin\
data\
demo\
deploy\
etc\
lib\
system\
README
karaf-manual-2.3.5.html
karaf-manual-2.3.5.pdf
...

Digging into the problem I found out that the eg. the apache-karaf-2.3.5.zip looks like:

apache-karaf-2.3.5\bin\
apache-karaf-2.3.5\data\
apache-karaf-2.3.5\demo\
apache-karaf-2.3.5\deploy\
apache-karaf-2.3.5\etc\
apache-karaf-2.3.5\lib\
apache-karaf-2.3.5\system\
apache-karaf-2.3.5\README
apache-karaf-2.3.5\karaf-manual-2.3.5.html
apache-karaf-2.3.5\karaf-manual-2.3.5.pdf
...

Whereas the custom distribution I'm using looks like:

bin\
data\
demo\
deploy\
etc\
lib\
system\
README
karaf-manual-2.3.5.html
karaf-manual-2.3.5.pdf
...

Note the different "base" directory in the two packages - "apache-karaf-2.3.5" in case of the Karaf 2.3.5 assembly.
It seems that the container assumes that every zip/tar.gz file given has this "base" directory structure and extracts only the contents of subfolders to the unpack directory.

I already saw the "searchKarafBase" function in the "KarafTestContainer" but that doesn't seem to work as the extraction of the underlying archive doesn't work as expected.

But I was able to fix it on my own modifying the "ArchiveExtractor".


Affects: 3.4.0, 3.5.0 Fixed in: unscheduled Attachments:

Votes: 1, Watches: 2

ops4j-issues commented 10 years ago

Lukas Roedl commented

Patched the ArchiveExtractor unpacking also the "base" directory.
The right Karaf directory is then found via the "searchKarafBase" method in the "KarafTestContainer".

ops4j-issues commented 10 years ago

Lukas Roedl commented

Any chance to get this issue resolved with the provided patch?

ops4j-issues commented 10 years ago

Harald Wellmann commented

I can't see anything unusual about Karaf's packaging layout, this is what most projects use. Pax Exam is supposed to work with official Karaf distributions out of the box, and we can't support all sorts of alternative formats.

ops4j-issues commented 10 years ago

Lukas Roedl commented

There is nothing unusual about Karaf's packaging format, but I have the following problem:
I create a custom Karaf distribution on top of a standard Karaf distro. So I unpack it, edit and add some files and repack it. When running iTests with resulting zip or tar file I get the before mentioned error.

I tried to look into your implementation and found out, that there is a method 'searchKarafBase' which should find the correct directory. But in the current configuration this method doesn't work and is some kind of useless because there is a problem when unpacking - which doesn't show up with the default Karaf distro.

So I really appreciate that this is fixed...

ops4j-issues commented 10 years ago

Harald Wellmann commented

Did you try changing your custom distro to this format?

apache-karaf-2.3.5-custom/bin
apache-karaf-2.3.5-custom/data
ops4j-issues commented 10 years ago

Lukas Roedl commented

Yes, I tried this and it worked.
But in my case (as I then unpack it once more and repack it to other formats) it would really help if this also would work as I wouldn't have to reconfigure a bunch of modules in my Maven project.
And in my understanding this is intended to work when I look at the current implementation. But correct me if I'm wrong...

ops4j-issues commented 10 years ago

Harald Wellmann commented

You've submitted a pull request without even running the regression tests, or else you would have noticed a broken test.

Rather than adapting your custom build to the standard layout, you seem to expect everyone to adapt to your layout or to assume that both layouts will work in all use cases.

You've preempted the project lead's decision to include a fix for this issue in a given release.

You should get a vote from the Karaf community on this and make all tests pass before going on with this.

ops4j-issues commented 10 years ago

Lukas Roedl commented

You are right that I forgot to enable the test while running the build - I’ll look into the itests and fix them as soon as possible. Furthermore I’ve to say that I didn’t want to preempt anyone’s decision: When raising a Jira, it asks for a version and so I filled it out. But as I've now read in the JIRA guide this is not the intended use of this property. You've my apologies.

Regarding the standard layout you can maybe point me in the right direction and tell me were the standard layout is described.

Anyway I’ll discuss this topic with the Karaf development team and come back to you.