sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1409697 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
Date Thu, 15 Nov 2012 08:53:45 GMT
Author: cziegeler
Date: Thu Nov 15 08:53:44 2012
New Revision: 1409697

URL: http://svn.apache.org/viewvc?rev=1409697&view=rev
Log:
SLING-2638 :  Unclosed Session Detected causing later tests to fail 

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java?rev=1409697&r1=1409696&r2=1409697&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
Thu Nov 15 08:53:44 2012
@@ -144,6 +144,7 @@ public class JcrResourceListener impleme
             } catch (RepositoryException e) {
                 logger.warn("Unable to remove session listener: " + this, e);
             }
+            this.session.logout();
         }
         if ( this.resourceResolver != null ) {
             this.resourceResolver.close();

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java?rev=1409697&r1=1409696&r2=1409697&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceListenerTest.java
Thu Nov 15 08:53:44 2012
@@ -119,193 +119,201 @@ public class JcrResourceListenerTest ext
     private List<Event> generateEvents(String workspaceName) throws Exception {
         final Session session = getRepository().loginAdministrative(workspaceName);
 
-        final List<Event> events = new ArrayList<Event>();
+        try {
+            final List<Event> events = new ArrayList<Event>();
 
-        addNodeToModify(session);
-        addNodeToDelete(session);
+            addNodeToModify(session);
+            addNodeToDelete(session);
 
-        final ResourceResolver resolver = new ResourceResolver() {
+            final ResourceResolver resolver = new ResourceResolver() {
 
-            public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
{
-                return (AdapterType)session;
-            }
-
-            public Resource resolve(HttpServletRequest request, String absPath) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            public Resource resolve(String absPath) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            public Resource resolve(HttpServletRequest request) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            public String map(String resourcePath) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            public String map(HttpServletRequest request, String resourcePath) {
-                // TODO Auto-generated method stub
-                return null;
-            }
-
-            public Resource getResource(String path) {
-                // TODO Auto-generated method stub
-                try {
-                    return new JcrNodeResource(this, session.getNode(path), null);
-                } catch (PathNotFoundException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                } catch (RepositoryException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
+                public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
{
+                    return (AdapterType)session;
                 }
-                return null;
-            }
 
-            public Resource getResource(Resource base, String path) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Resource resolve(HttpServletRequest request, String absPath) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public String[] getSearchPath() {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Resource resolve(String absPath) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Iterator<Resource> listChildren(Resource parent) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Resource resolve(HttpServletRequest request) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Iterable<Resource> getChildren(Resource parent) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public String map(String resourcePath) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Iterator<Resource> findResources(String query, String language)
{
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public String map(HttpServletRequest request, String resourcePath) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Iterator<Map<String, Object>> queryResources(String query,
String language) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Resource getResource(String path) {
+                    // TODO Auto-generated method stub
+                    try {
+                        return new JcrNodeResource(this, session.getNode(path), null);
+                    } catch (PathNotFoundException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    } catch (RepositoryException e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                    return null;
+                }
 
-            public ResourceResolver clone(Map<String, Object> authenticationInfo) throws
LoginException {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Resource getResource(Resource base, String path) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public boolean isLive() {
-                // TODO Auto-generated method stub
-                return false;
-            }
+                public String[] getSearchPath() {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public void close() {
-                // TODO Auto-generated method stub
+                public Iterator<Resource> listChildren(Resource parent) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            }
+                public Iterable<Resource> getChildren(Resource parent) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public String getUserID() {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Iterator<Resource> findResources(String query, String language)
{
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Iterator<String> getAttributeNames() {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public Iterator<Map<String, Object>> queryResources(String query,
String language) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public Object getAttribute(String name) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public ResourceResolver clone(Map<String, Object> authenticationInfo)
throws LoginException {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public void delete(Resource resource) {
-                // TODO Auto-generated method stub
-            }
+                public boolean isLive() {
+                    // TODO Auto-generated method stub
+                    return false;
+                }
 
-            public Resource create(Resource parent, String name, Map<String, Object>
properties) {
-                // TODO Auto-generated method stub
-                return null;
-            }
+                public void close() {
+                    // TODO Auto-generated method stub
 
-            public void revert() {
-                // TODO Auto-generated method stub
+                }
 
-            }
+                public String getUserID() {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public void commit() {
-                // TODO Auto-generated method stub
+                public Iterator<String> getAttributeNames() {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            }
+                public Object getAttribute(String name) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public boolean hasChanges() {
-                // TODO Auto-generated method stub
-                return false;
-            }
-        };
-        final ResourceResolverFactory factory = new ResourceResolverFactory() {
+                public void delete(Resource resource) {
+                    // TODO Auto-generated method stub
+                }
 
-            public ResourceResolver getResourceResolver(Map<String, Object> authenticationInfo)
throws LoginException {
-                return null;
-            }
+                public Resource create(Resource parent, String name, Map<String, Object>
properties) {
+                    // TODO Auto-generated method stub
+                    return null;
+                }
 
-            public ResourceResolver getAdministrativeResourceResolver(Map<String, Object>
authenticationInfo) throws LoginException {
-                return resolver;
-            }
-        };
+                public void revert() {
+                    // TODO Auto-generated method stub
 
-        final EventAdmin mockEA = new EventAdmin() {
+                }
 
-            public void postEvent(Event event) {
-                events.add(event);
-            }
+                public void commit() {
+                    // TODO Auto-generated method stub
 
-            public void sendEvent(Event event) {
-                events.add(event);
-            }
-        };
+                }
 
-        final ServiceTracker tracker = mock(ServiceTracker.class);
-        when(tracker.getService()).thenReturn(mockEA);
+                public boolean hasChanges() {
+                    // TODO Auto-generated method stub
+                    return false;
+                }
+            };
+            final ResourceResolverFactory factory = new ResourceResolverFactory() {
 
-        final BundleContext bundleContext = mock(BundleContext.class);
-        when(bundleContext.createFilter(any(String.class))).thenReturn(null);
-        when(bundleContext.getServiceReference(any(String.class))).thenReturn(null);
-        when(bundleContext.getService(null)).thenReturn(mockEA);
+                public ResourceResolver getResourceResolver(Map<String, Object> authenticationInfo)
throws LoginException {
+                    return null;
+                }
 
-        SynchronousJcrResourceListener listener = new SynchronousJcrResourceListener(factory,
getRepository(),
-                        bundleContext, resolver, tracker);
+                public ResourceResolver getAdministrativeResourceResolver(Map<String,
Object> authenticationInfo) throws LoginException {
+                    return resolver;
+                }
+            };
 
-        createdPath = createTestPath();
-        createNode(session, createdPath);
+            final EventAdmin mockEA = new EventAdmin() {
 
-        Node modified = session.getNode(pathToModify);
-        modified.setProperty("foo", "bar");
-        session.save();
+                public void postEvent(Event event) {
+                    events.add(event);
+                }
 
-        Node deleted = session.getNode(pathToDelete);
-        deleted.remove();
-        session.save();
+                public void sendEvent(Event event) {
+                    events.add(event);
+                }
+            };
 
-        Session newSession = getRepository().loginAdministrative(workspaceName);
-        EventHelper helper = new EventHelper(newSession);
-        helper.waitForEvents(5000);
-        helper.dispose();
-        listener.dispose();
+            final ServiceTracker tracker = mock(ServiceTracker.class);
+            when(tracker.getService()).thenReturn(mockEA);
 
-        newSession.logout();
-        session.logout();
+            final BundleContext bundleContext = mock(BundleContext.class);
+            when(bundleContext.createFilter(any(String.class))).thenReturn(null);
+            when(bundleContext.getServiceReference(any(String.class))).thenReturn(null);
+            when(bundleContext.getService(null)).thenReturn(mockEA);
+
+            final SynchronousJcrResourceListener listener = new SynchronousJcrResourceListener(factory,
getRepository(),
+                            bundleContext, resolver, tracker);
+            Session newSession = null;
+            try {
+                createdPath = createTestPath();
+                createNode(session, createdPath);
+
+                Node modified = session.getNode(pathToModify);
+                modified.setProperty("foo", "bar");
+                session.save();
+
+                Node deleted = session.getNode(pathToDelete);
+                deleted.remove();
+                session.save();
+
+                newSession = getRepository().loginAdministrative(workspaceName);
+
+                EventHelper helper = new EventHelper(newSession);
+                helper.waitForEvents(5000);
+                helper.dispose();
+            } finally {
+                listener.dispose();
+                if ( newSession != null ) {
+                    newSession.logout();
+                }
+            }
+            return events;
+        } finally {
+            session.logout();
+        }
 
-        return events;
     }
 }



Mime
View raw message