use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverFactoryTest method testNestedThreadLocal.
@Test
public void testNestedThreadLocal() throws Exception {
assertNull(this.commonFactory.getThreadResourceResolver());
// create first resolver
final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
assertNotNull(rr1);
assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
// create second resolver
final ResourceResolver rr2 = this.commonFactory.getResourceResolver(null);
assertNotNull(rr2);
assertEquals(rr2, this.commonFactory.getThreadResourceResolver());
rr2.close();
assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
rr1.close();
assertNull(this.commonFactory.getThreadResourceResolver());
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverFactoryTest method testNestedUnorderedCloseThreadLocal.
@Test
public void testNestedUnorderedCloseThreadLocal() throws Exception {
assertNull(this.commonFactory.getThreadResourceResolver());
// create three resolver
final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
final ResourceResolver rr2 = this.commonFactory.getResourceResolver(null);
final ResourceResolver rr3 = this.commonFactory.getResourceResolver(null);
assertEquals(rr3, this.commonFactory.getThreadResourceResolver());
rr2.close();
assertEquals(rr3, this.commonFactory.getThreadResourceResolver());
rr3.close();
assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
rr1.close();
assertNull(this.commonFactory.getThreadResourceResolver());
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverFactoryTest method testSingleThreadLocal.
@Test
public void testSingleThreadLocal() throws Exception {
assertNull(this.commonFactory.getThreadResourceResolver());
// create first resolver
final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
assertNotNull(rr1);
assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
rr1.close();
assertNull(this.commonFactory.getThreadResourceResolver());
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverFactoryTest method testThreadLocalWithAdmin.
@Test
public void testThreadLocalWithAdmin() throws Exception {
assertNull(this.commonFactory.getThreadResourceResolver());
final ResourceResolver rr1 = this.commonFactory.getResourceResolver(null);
final ResourceResolver admin = this.commonFactory.getAdministrativeResourceResolver(null);
assertEquals(rr1, this.commonFactory.getThreadResourceResolver());
rr1.close();
assertNull(this.commonFactory.getThreadResourceResolver());
admin.close();
assertNull(this.commonFactory.getThreadResourceResolver());
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ScriptingResourceResolverProviderImpl method getRequestScopedResourceResolver.
@Override
public ResourceResolver getRequestScopedResourceResolver() {
ScriptingResourceResolver threadResolver = perThreadResourceResolver.get();
if (threadResolver == null) {
try {
ResourceResolver delegate = rrf.getServiceResourceResolver(null);
threadResolver = new ScriptingResourceResolver(logStackTraceOnResolverClose, delegate);
perThreadResourceResolver.set(threadResolver);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Set per thread resource resolver for thread {}.", Thread.currentThread().getId());
}
} catch (LoginException e) {
throw new IllegalStateException("Cannot create per thread resource resolver.", e);
}
}
return threadResolver;
}
Aggregations