You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Henry Kuijpers (Jira)" <ji...@apache.org> on 2023/05/02 08:43:00 UTC

[jira] [Commented] (SLING-11849) Create osgiContext#unregisterService() for easy unregistering of services

    [ https://issues.apache.org/jira/browse/SLING-11849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17718486#comment-17718486 ] 

Henry Kuijpers commented on SLING-11849:
----------------------------------------

[~sseifert] We often have cases where we have bind- & unbind methods in our test classes. We usually want to thoroughly test all our logic, including those methods, to prevent issues in production.

I agree that in 80% of the cases it is very desired to just register the service and get the instance back, but it would be very nice if there was an option of either receiving back ServiceRegistration<T>, or be able to unregister a service without having the ServiceRegistration<T>.

There is quite some processing in OsgiContextImpl (the various register*-methods) and also a lot of processing etc in MockOsgi.register*-methods. 
In the end, MockOsgi.registerInjectActivateService(dsComponentClass,bundleContext, properties) registers the service, but it doesn't do anything with the ServiceRegistration<T> that is returned from bundleContext.registerService.

> Create osgiContext#unregisterService() for easy unregistering of services
> -------------------------------------------------------------------------
>
>                 Key: SLING-11849
>                 URL: https://issues.apache.org/jira/browse/SLING-11849
>             Project: Sling
>          Issue Type: Improvement
>          Components: Testing
>    Affects Versions: Testing OSGi Mock 3.3.6
>            Reporter: Henry Kuijpers
>            Priority: Major
>
> Since we can do:
> {code:java}
> this.underTest = context.registerInjectActivateService(Test.class);
> {code}
> it would be very useful if we can also do:
> {code:java}
> context.unregisterService(this.underTest);
> {code}
> for example.
> It would be very convenient to do this, since the OSGi Mock API is easy and simple to write and to be able to unregister services, it would be needed to have a ServiceRegistration<Test> and also a ServiceReference<Test> to be able to call .unregister() on it
> If we add this method, then all this logic can be put in this method.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)