Search in sources :

Example 6 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker in project smarthome by eclipse.

the class ReadyServiceImplTest method testDifferentReadyMarkerInstances.

@Test
public void testDifferentReadyMarkerInstances() {
    ReadyServiceImpl rs = new ReadyServiceImpl();
    assertFalse(rs.isReady(new ReadyMarker("test", "id")));
    rs.markReady(new ReadyMarker("test", "id"));
    assertTrue(rs.isReady(new ReadyMarker("test", "id")));
    rs.unmarkReady(new ReadyMarker("test", "id"));
    assertFalse(rs.isReady(new ReadyMarker("test", "id")));
}
Also used : ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) Test(org.junit.Test)

Example 7 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker in project smarthome by eclipse.

the class ReadyServiceImplTest method testTrackersAreInformedOnlyOnMatch.

@Test
public void testTrackersAreInformedOnlyOnMatch() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.registerTracker(tracker, new ReadyMarkerFilter().withType("test"));
    rs.markReady(new ReadyMarker("foo", "id"));
    verifyNoMoreInteractions(tracker);
    rs.markReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarkerFilter(org.eclipse.smarthome.core.service.ReadyMarkerFilter) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) ReadyTracker(org.eclipse.smarthome.core.service.ReadyService.ReadyTracker) Test(org.junit.Test)

Example 8 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker 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)

Example 9 with ReadyMarker

use of org.eclipse.smarthome.core.service.ReadyMarker in project smarthome by eclipse.

the class XmlDocumentBundleTracker method unregisterReadyMarker.

private void unregisterReadyMarker(Bundle bundle) {
    String bsn = bundle.getSymbolicName();
    ReadyMarker readyMarker = bundleReadyMarkerRegistrations.remove(bsn);
    if (readyMarker != null) {
        readyService.unmarkReady(readyMarker);
    }
}
Also used : ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker)

Aggregations

ReadyMarker (org.eclipse.smarthome.core.service.ReadyMarker)9 Test (org.junit.Test)5 ReadyTracker (org.eclipse.smarthome.core.service.ReadyService.ReadyTracker)4 ReadyMarkerFilter (org.eclipse.smarthome.core.service.ReadyMarkerFilter)3 ReadyService (org.eclipse.smarthome.core.service.ReadyService)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Consumer (java.util.function.Consumer)1 ServiceReference (org.osgi.framework.ServiceReference)1 Component (org.osgi.service.component.annotations.Component)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1