osgipax-exam

How to start and shut down a second OSGi container in pax exam


I am testing remote services using pax exam.

To do this I need to start two containers. One local one that runs my test which calls the consumer and a second one that runs the service, Aries RSA and zookeeper.

I managed to start the external container by calling this in the @Configuration method. It does not seem that this belongs there but it was the only place I found where code is executed outside OSGi.

See https://github.com/apache/aries-rsa/blob/master/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java#L47-L51

Now I need a second hook that gets called when the test shuts down where I then can shut down the container. @After or @AfterClass does not seem to work as both run in OSGi.

I would also be happy about a cleaner way to start the external container as adding it in @Configuration does not feel right to me.


Solution

  • I found a solution now but I still hope there is something that works out of the box.

    I created a new Pax runner TwoContainerPaxExam. It looks for a second config annotated with @ServerConfiguration, starts it before the test and shuts it down after.

    So my test looks like this TestRoundTrip now. If there is nothing out of the box I will try to put this solution into pax exam.