use of org.eclipse.smarthome.core.service.ReadyService in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method setUp.
@Before
public void setUp() throws Exception {
CONFIG_DESCRIPTION_THING = new URI("test:test");
CONFIG_DESCRIPTION_CHANNEL = new URI("test:channel");
THING = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
Collections.singletonList(//
ChannelBuilder.create(CHANNEL_UID, "Switch").withType(CHANNEL_TYPE_UID).build())).build();
registerVolatileStorageService();
configureAutoLinking(false);
managedThingProvider = getService(ManagedThingProvider.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(esh.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ChannelItemProvider.class, null), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
}
use of org.eclipse.smarthome.core.service.ReadyService in project smarthome by eclipse.
the class SyntheticBundleInstaller method waitForReadyMarker.
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);
}
Aggregations