I want to write a JUnitTest, which ensures that my Karaf Server is started fine and all (needed) Bundles are installed and active.
For this I have a Test, calling a helper method "assertBundleState" which ensures, that the given Bundle is in the given State. The test looks like following:
@Test (timeout=30000L)
public void testBundlesStarted() throws Exception {
assertBundleState("bundle.Name", BundleLifecycleState.Active);
... <other bundles in similar way>
}
This worked fine in the past. The timeout was never reached.
Unfortunately I now have to load a bundle, which need a bit longer for startup. So the Bundles are not yet started, when the test is executed. And so the test fails.
I have tried it with a sleep in a BeforeClass method, but I am not really happy with this solution. Because I can't ensure that the given sleep time is enough on every machine at every time. So I am looking for some event-based solution to interact with Karaf.
@BeforeClass
public static void init() throws Exception {
Thread.sleep(120000L);
}
Does anybody have an idea how I can solve it in a better way? Thanks