Expand my Community achievements bar.

SOLVED

AEMContextImpl throws exception in teardown method - junit

Avatar

Level 1
try (ResourceResolver writeAccessResourceResolver = userMapperService.getJCRWriterService();
ResourceResolver readAccessResourceResolver = userMapperService.getJCRReadService()) {

...

 I am mocking userMapperService here , and returning aemContext.resourceResolver(), when  userMapperService.getJCRWriterService() or userMapperService.getJCRReadService() is called. 

 

My resourceresolver gets closed after the try block . But after the test case runs , it throws exception - " Resource Resolver is already closed " , nearAemContextImpl.tearDown method. 

 

java.lang.IllegalStateException: Resource resolver is already closed.

at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.checkClosed(ResourceResolverImpl.java:186)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.adaptTo(ResourceResolverImpl.java:804)
at org.apache.sling.testing.mock.sling.context.SlingContextImpl.tearDown(SlingContextImpl.java:216)
at io.wcm.testing.mock.aem.context.AemContextImpl.tearDown(AemContextImpl.java:99)
at io.wcm.testing.mock.aem.junit5.AemContext.tearDownContext(AemContext.java:106)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.lambda$afterEach$2(AemContextExtension.java:115)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.applyAemContext(AemContextExtension.java:123)
at io.wcm.testing.mock.aem.junit5.AemContextExtension.afterEach(AemContextExtension.java:110)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAfterEachCallbacks$11(TestMethodTestDescriptor.java:245)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$12(TestMethodTestDescriptor.java:256)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeAllAfterMethodsOrCallbacks$13(TestMethodTestDescriptor.java:256)

 

How to fix this issue? 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @padmaja_seshadri ,

 

This can be caused by multi-threaded use of the same ResourceResolver or by closing a ResourceResolver or javax.jcr.Session that you didn't open in your own code.

Hope this kb article helps: https://helpx.adobe.com/in/experience-manager/kb/Random-Resource-resolver-is-already-closed-in-the-l...

 

Regards,

Santosh

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @padmaja_seshadri ,

 

This can be caused by multi-threaded use of the same ResourceResolver or by closing a ResourceResolver or javax.jcr.Session that you didn't open in your own code.

Hope this kb article helps: https://helpx.adobe.com/in/experience-manager/kb/Random-Resource-resolver-is-already-closed-in-the-l...

 

Regards,

Santosh

 

Avatar

Level 8

Hi @padmaja_seshadri,

Can you please add screenshot with highlighting the line of code where this exception is getting thrown when JUnit test runs, it will be helpful to understand/reproduce the issue which you are getting. 

Avatar

Level 2

@padmaja_seshadri where u able to resolve this issue? Anychance did passing cloned resourceResolver help?