private static void waitForReadyMarker(BundleContext context, String marker, Bundle bundle) { if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) { return; } long startTime = System.nanoTime(); ServiceReference<?> readyServiceRef = context.getServiceReference(ReadyService.class.getName()); ReadyService readyService = (ReadyService) context.getService(readyServiceRef); ReadyMarker expected = new ReadyMarker(marker, bundle.getSymbolicName()); while (!readyService.isReady(expected)) { if (System.nanoTime() - startTime > TimeUnit.SECONDS.toNanos(WAIT_TIMOUT)) { Assert.fail(MessageFormat.format("Timout waiting for marker {0} at bundle {1}", marker, bundle.getSymbolicName())); } try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } context.ungetService(readyServiceRef); }