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

Konrad Windszus edited comment on SLING-10930 at 11/19/21, 8:00 AM:
--------------------------------------------------------------------

The following options come to my mind to resolve that:
# Don't throw ISE in MockBundleContext.unregisterService() in case the shutdown 
method is being executed
# Don't call deactivate() automatically during MockBundleContext.shutdown()

I would rather tend to solution 2. as MockBundleContext should not know 
anything about DS components and therefore not call their deactivate method. 
Currently I don't see a strong need to also introduce a registry for DS 
components (which would be able to call deactivate() for each component once).
[~sseifert] WDYT?


was (Author: kwin):
The following options come to my mind to resolve that:
# Don't throw ISE in MockBundleContext.unregisterService() in case the shutdown 
method is being executed
# Don't call deactivate() automatically during shutdown

I would rather tend to solution 2. as MockBundleContext should not know 
anything about DS components and therefore not call their deactivate method. 
Currently I don't see a strong need to also introduce a registry for DS 
components (which would be able to call deactivate() for each component once).
[~sseifert] WDYT?

> OSGi Mock:  "java.lang.IllegalStateException: Service was already 
> unregistered" in MockBundleContext.shutdown()
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: SLING-10930
>                 URL: https://issues.apache.org/jira/browse/SLING-10930
>             Project: Sling
>          Issue Type: Bug
>          Components: Testing
>    Affects Versions: Testing OSGi Mock 3.1.4
>            Reporter: Konrad Windszus
>            Assignee: Konrad Windszus
>            Priority: Major
>
> When executing a test I see the following error in the log
> {code}
> [ERROR] 
> testLegacyRegistration(com.adobe.acs.commons.httpcache.invalidator.event.JCRNodeChangeEventHandlerTest)
>   Time elapsed: 0.124 s  <<< ERROR!
> java.lang.RuntimeException: Unable to invoke method 'deactivate' for class 
> com.adobe.acs.commons.httpcache.invalidator.event.JCRNodeChangeEventHandler
>       at 
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:347)
>       at 
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeLifecycleMethod(OsgiServiceUtil.java:234)
>       at 
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateDeactivate(OsgiServiceUtil.java:98)
>       at 
> org.apache.sling.testing.mock.osgi.MockOsgi.deactivate(MockOsgi.java:272)
>       at 
> org.apache.sling.testing.mock.osgi.MockBundleContext.shutdown(MockBundleContext.java:461)
>       at 
> org.apache.sling.testing.mock.osgi.MockOsgi.shutdown(MockOsgi.java:371)
>       at 
> org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.tearDown(OsgiContextImpl.java:58)
>       at 
> org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:256)
>       at 
> io.wcm.testing.mock.aem.context.AemContextImpl.tearDown(AemContextImpl.java:109)
>       at 
> io.wcm.testing.mock.aem.junit.AemContext.access$200(AemContext.java:48)
>       at io.wcm.testing.mock.aem.junit.AemContext$1.after(AemContext.java:188)
>       at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50)
>       at org.junit.rules.RunRules.evaluate(RunRules.java:20)
>       at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>       at 
> org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:77)
>       at 
> org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:83)
>       at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
>       at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
>       at org.junit.runners.Suite.runChild(Suite.java:128)
>       at org.junit.runners.Suite.runChild(Suite.java:27)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>       at org.junit.runners.Suite.runChild(Suite.java:128)
>       at org.junit.runners.Suite.runChild(Suite.java:27)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>       at 
> org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:410)
>       at 
> org.apache.maven.surefire.junitcore.pc.InvokerStrategy.schedule(InvokerStrategy.java:54)
>       at 
> org.apache.maven.surefire.junitcore.pc.Scheduler.schedule(Scheduler.java:367)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>       at 
> org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder$PC$1.run(ParallelComputerBuilder.java:590)
>       at org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55)
>       at 
> org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
>       at 
> org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeLazy(JUnitCoreWrapper.java:119)
>       at 
> org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:87)
>       at 
> org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
>       at 
> org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:158)
>       at 
> org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
>       at 
> org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
>       at 
> org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
>       at 
> org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
> Caused by: java.lang.IllegalStateException: Service was already unregistered
>       at 
> org.apache.sling.testing.mock.osgi.MockBundleContext.unregisterService(MockBundleContext.java:203)
>       at 
> org.apache.sling.testing.mock.osgi.MockServiceRegistration.unregister(MockServiceRegistration.java:101)
>       at 
> com.adobe.acs.commons.httpcache.invalidator.event.JCRNodeChangeEventHandler.deactivate(JCRNodeChangeEventHandler.java:116)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>       at 
> org.apache.sling.testing.mock.osgi.OsgiServiceUtil.invokeMethod(OsgiServiceUtil.java:338)
>       ... 54 more
> {code}
> This happens because the {{deactivate(...)}} method is called twice and 
> internally calls {{BundleContext.unregisterService(..)}}. This only works the 
> first time and the 2nd time leads to this exception.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to