use of org.apache.felix.framework.ServiceRegistrationImpl.ServiceReferenceImpl in project felix by apache.
the class ServiceRegistryTest method testUngetServiceThreadMarking.
public void testUngetServiceThreadMarking() {
ServiceRegistry sr = new ServiceRegistry(null, null);
Bundle b = Mockito.mock(Bundle.class);
ServiceRegistrationImpl reg = Mockito.mock(ServiceRegistrationImpl.class);
ServiceReferenceImpl ref = Mockito.mock(ServiceReferenceImpl.class);
Mockito.when(ref.getRegistration()).thenReturn(reg);
assertFalse("There is no usage count, so this method should return false", sr.ungetService(b, ref, null));
InOrder inOrder = Mockito.inOrder(reg);
inOrder.verify(reg, Mockito.times(1)).currentThreadMarked();
inOrder.verify(reg, Mockito.times(1)).markCurrentThread();
inOrder.verify(reg, Mockito.times(1)).unmarkCurrentThread();
}
use of org.apache.felix.framework.ServiceRegistrationImpl.ServiceReferenceImpl in project felix by apache.
the class ServiceRegistryTest method testUngetService.
@SuppressWarnings("unchecked")
public void testUngetService() throws Exception {
ServiceRegistry sr = new ServiceRegistry(null, null);
Bundle b = Mockito.mock(Bundle.class);
ServiceRegistrationImpl reg = Mockito.mock(ServiceRegistrationImpl.class);
ServiceReferenceImpl ref = Mockito.mock(ServiceReferenceImpl.class);
Mockito.when(ref.getRegistration()).thenReturn(reg);
final ConcurrentMap<Bundle, UsageCount[]> inUseMap = (ConcurrentMap<Bundle, UsageCount[]>) getPrivateField(sr, "m_inUseMap");
UsageCount uc = new UsageCount(ref, false);
uc.m_svcHolderRef.set(new ServiceHolder());
inUseMap.put(b, new UsageCount[] { uc });
assertFalse(sr.ungetService(b, ref, null));
assertNull(uc.m_svcHolderRef.get());
}
use of org.apache.felix.framework.ServiceRegistrationImpl.ServiceReferenceImpl in project felix by apache.
the class ServiceRegistryTest method testGetServiceHolderAwait.
@SuppressWarnings("unchecked")
public void testGetServiceHolderAwait() throws Exception {
ServiceRegistry sr = new ServiceRegistry(null, null);
final String svc = "test";
Bundle b = Mockito.mock(Bundle.class);
ServiceRegistrationImpl reg = Mockito.mock(ServiceRegistrationImpl.class);
Mockito.when(reg.isValid()).thenReturn(true);
ServiceReferenceImpl ref = Mockito.mock(ServiceReferenceImpl.class);
Mockito.when(ref.getRegistration()).thenReturn(reg);
UsageCount uc = sr.obtainUsageCount(b, ref, null, false);
// Set an empty Service Holder so we can test that it waits.
final ServiceHolder sh = new ServiceHolder();
uc.m_svcHolderRef.set(sh);
final StringBuffer sb = new StringBuffer();
final AtomicBoolean threadException = new AtomicBoolean(false);
Thread t = new Thread() {
@Override
public void run() {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
}
sh.m_service = svc;
if (sb.length() > 0) {
// Should not have put anything in SB until countDown() was called...
threadException.set(true);
}
sh.m_latch.countDown();
}
};
assertFalse(t.isInterrupted());
t.start();
Object actualSvc = sr.getService(b, ref, false);
sb.append(actualSvc);
t.join();
assertFalse("This thread did not wait until the latch was count down", threadException.get());
assertSame(svc, actualSvc);
}
Aggregations