Search in sources :

Example 1 with ReadyService

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);
        }
    });
}
Also used : ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ReadyService(org.eclipse.smarthome.core.service.ReadyService) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) URI(java.net.URI) Before(org.junit.Before)

Example 2 with ReadyService

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);
}
Also used : ReadyService(org.eclipse.smarthome.core.service.ReadyService) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ReadyMarker (org.eclipse.smarthome.core.service.ReadyMarker)2 ReadyService (org.eclipse.smarthome.core.service.ReadyService)2 URI (java.net.URI)1 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)1 ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)1 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)1 Before (org.junit.Before)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1