You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Carsten Ziegeler (JIRA)" <ji...@apache.org> on 2016/02/25 09:51:18 UTC
[jira] [Commented] (FELIX-5198) Service should not be available
while being unregistered
[ https://issues.apache.org/jira/browse/FELIX-5198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15166938#comment-15166938 ]
Carsten Ziegeler commented on FELIX-5198:
-----------------------------------------
Test case which currently fails:
Index: src/test/java/org/apache/felix/framework/ServiceRegistryTest.java
===================================================================
--- src/test/java/org/apache/felix/framework/ServiceRegistryTest.java (Revision 1732253)
+++ src/test/java/org/apache/felix/framework/ServiceRegistryTest.java (Arbeitskopie)
@@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Observable;
@@ -31,11 +32,11 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
-import junit.framework.TestCase;
-
import org.apache.felix.framework.ServiceRegistrationImpl.ServiceReferenceImpl;
import org.apache.felix.framework.ServiceRegistry.ServiceHolder;
+import org.apache.felix.framework.ServiceRegistry.ServiceRegistryCallbacks;
import org.apache.felix.framework.ServiceRegistry.UsageCount;
import org.easymock.MockControl;
import org.mockito.AdditionalAnswers;
@@ -54,6 +55,8 @@
import org.osgi.framework.hooks.service.FindHook;
import org.osgi.framework.hooks.service.ListenerHook;
+import junit.framework.TestCase;
+
public class ServiceRegistryTest extends TestCase
{
public void testRegisterEventHookService()
@@ -1228,6 +1231,34 @@
sb.append("Obtained service");
}
+ public void testGettingServiceWhileUnregistering() throws Exception
+ {
+ final Bundle regBundle = Mockito.mock(Bundle.class);
+
+ final AtomicReference<ServiceRegistry> registryRef = new AtomicReference<ServiceRegistry>();
+ final AtomicReference<ServiceReference> referenceRef = new AtomicReference<ServiceReference>();
+ final ServiceRegistryCallbacks callback = new ServiceRegistryCallbacks()
+ {
+
+ @Override
+ public void serviceChanged(ServiceEvent event, Dictionary<?, ?> oldProps)
+ {
+ if ( event.getType() == ServiceEvent.UNREGISTERING ) {
+ final Object obj = registryRef.get().getService(regBundle, referenceRef.get(), false);
+ assertNull(obj);
+ }
+ }
+
+ };
+ ServiceRegistry sr = new ServiceRegistry(null, callback);
+ registryRef.set(sr);
+
+ ServiceRegistration<?> reg1 = sr.registerService(
+ regBundle, new String [] {String.class.getName()}, "service is unregistering", null);
+ referenceRef.set(reg1.getReference());
+ sr.unregisterService(regBundle, reg1);
+ }
+
private Object getPrivateField(Object obj, String fieldName) throws NoSuchFieldException,
IllegalAccessException
{
> Service should not be available while being unregistered
> --------------------------------------------------------
>
> Key: FELIX-5198
> URL: https://issues.apache.org/jira/browse/FELIX-5198
> Project: Felix
> Issue Type: Bug
> Components: Framework
> Affects Versions: framework-5.4.0
> Reporter: Carsten Ziegeler
> Assignee: David Bosschaert
> Fix For: framework-5.6.0
>
>
> Currently it is possible to get a service while it is being unregistered - if the service is get during processing of the unregistering event. This is the order of events:
> a) a service (factory) is unregistered in the framework
> b) the UNREGISTERING event is sent before the service is actually unregistered (this is as defined in the spec)
> c) the above event is handled synchronously, reactivating dependent components
> d) during this reactivation, some component looks up the service that is unregistered in a). as this service is still registered and marked as valid, it gets it
> According to ServiceRegistration.unregister the service should not be available anymore while the events are sent
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)