use of org.osgi.service.device.Driver in project felix by apache.
the class DeviceManagerTest method DeviceAddedWithADriverLocator.
/**
* We add a device while there's one driverlocator that will successfully
* locate and load two driver bundles. We expect a <code>Driver.attach()</code> for
* the best matching driver. There's already a driver loaded that should not match.
*
* @throws Exception
*/
@Test
public void DeviceAddedWithADriverLocator() throws Exception {
final String driverId1 = "org.apache.felix.driver-1.0";
final String driverId2 = "org.apache.felix.driver-1.1";
final String notMatchingButLoadedDriverId = "dotorg.apache.felix.driver-1.0";
DriverLocator locator = Mockito.mock(DriverLocator.class);
Map<String, Driver> drivers = tstExpectDriverLocatorFor(locator, new String[] { driverId1, driverId2 }, new int[] { 30, 3 });
Driver noMatcher = tstCreateDriver(notMatchingButLoadedDriverId, 100);
Device device = tstCreateDevice(new String[] { "org.apache.felix" });
final CountDownLatch attachLatch = tstExpectAttach(drivers.get(driverId1), device);
final CountDownLatch unloadDriverLatch = tstExpectUnloadDriverBundle(drivers.get(driverId2));
m_manager.locatorAdded(locator);
m_manager.driverAdded(m_osgi.getReference(noMatcher), noMatcher);
m_manager.deviceAdded(m_osgi.getReference(device), device);
if (!attachLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an attach");
}
// of all other (dynamically loaded) driver bundles
if (!unloadDriverLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an unload");
}
}
use of org.osgi.service.device.Driver in project felix by apache.
the class DeviceManagerTest method DeviceAddedWithADriverLocatorUnloadFails.
@Test
public void DeviceAddedWithADriverLocatorUnloadFails() throws Exception {
final String driverId1 = "org.apache.felix.driver-1.0";
final String driverId2 = "org.apache.felix.driver-1.1";
final String notMatchingButLoadedDriverId = "dotorg.apache.felix.driver-1.0";
DriverLocator locator = Mockito.mock(DriverLocator.class);
Map<String, Driver> drivers = tstExpectDriverLocatorFor(locator, new String[] { driverId1, driverId2 }, new int[] { 30, 3 });
Driver noMatcher = tstCreateDriver(notMatchingButLoadedDriverId, 100);
Device device = tstCreateDevice(new String[] { "org.apache.felix" });
final CountDownLatch attachLatch = tstExpectAttach(drivers.get(driverId1), device);
final CountDownLatch unloadDriverLatch = new CountDownLatch(1);
ServiceReference driver2Ref = m_osgi.getReference(drivers.get(driverId2));
Bundle driver2Bundle = m_osgi.getBundle(driver2Ref);
Answer<Object> answer = new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
try {
throw new BundleException("test driverBundle uninstall failed");
} finally {
unloadDriverLatch.countDown();
}
}
};
Mockito.doAnswer(answer).when(driver2Bundle).uninstall();
m_manager.locatorAdded(locator);
m_manager.driverAdded(m_osgi.getReference(noMatcher), noMatcher);
m_manager.deviceAdded(m_osgi.getReference(device), device);
if (!attachLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an attach");
}
if (!unloadDriverLatch.await(5, TimeUnit.SECONDS)) {
Assert.fail("expected an unload");
}
// since driver1 is attached, we expect an uninstall()
// of all other (dynamically loaded) driver bundles
// Driver driver = drivers.get( driverId2 );
// tstVerifyBundleUninstall( driver );
}
use of org.osgi.service.device.Driver in project felix by apache.
the class DriverAnalyzerTest method VerifyCorrectDriverIsIgnored.
@Test
public void VerifyCorrectDriverIsIgnored() {
Properties p = new Properties();
p.put(Constants.DRIVER_ID, "a-driver-id");
ServiceReference ref = m_osgi.createReference(new String[] { Driver.class.getName() }, p);
m_analyzer.driverAdded(ref);
Mockito.verifyZeroInteractions(m_log);
}
use of org.osgi.service.device.Driver in project felix by apache.
the class DeviceManager method driverModified.
public void driverModified(ServiceReference ref, Object obj) {
final Driver driver = Driver.class.cast(obj);
debug("driver modified: " + Util.showDriver(ref));
m_drivers.remove(ref);
m_drivers.put(ref, new DriverAttributes(ref, driver));
// check if devices have become idle
// after some time
schedule(new CheckForIdleDevices());
}
use of org.osgi.service.device.Driver in project felix by apache.
the class DeviceManager method driverAdded.
public void driverAdded(ServiceReference ref, Object obj) {
final Driver driver = Driver.class.cast(obj);
m_drivers.put(ref, new DriverAttributes(ref, driver));
debug("driver appeared: " + Util.showDriver(ref));
// immediately check for idle devices
submit(new CheckForIdleDevices());
}
Aggregations