incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r693802 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
Date Wed, 10 Sep 2008 11:53:09 GMT
Author: bdelacretaz
Date: Wed Sep 10 04:53:08 2008
New Revision: 693802

URL: http://svn.apache.org/viewvc?rev=693802&view=rev
Log:
SLING-646 - check for deleted resources at startup

Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=693802&r1=693801&r2=693802&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Wed Sep 10 04:53:08 2008
@@ -95,6 +95,15 @@
             folders.addAll(findWatchedFolders(root));
         }
         
+        // Check if any deletions happened while this
+        // service was inactive
+        for(WatchedFolder wf : folders) {
+            try {
+                wf.checkDeletions();
+            } catch(Exception e) {
+                log.warn("Exception in activate() / checkDeletions", e);
+            }
+        }
     }
     
     protected void deactivate(ComponentContext oldContext) {

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java?rev=693802&r1=693801&r2=693802&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
Wed Sep 10 04:53:08 2008
@@ -125,6 +125,8 @@
     protected void scan() throws Exception {
         log.debug("Scanning {}", path);
         
+        checkDeletions();
+        
         Node folder = null;
         if(session.itemExists(path)) {
         	Item i = session.getItem(path);
@@ -137,9 +139,6 @@
         	log.info("Folder {} does not exist (or not anymore), cannot scan", path);
         	return;
         }
-        	
-        
-        // TODO: check deletions
         
         // Check adds and updates, for all child nodes that are files
         final NodeIterator it = folder.getNodes();
@@ -153,6 +152,19 @@
         }
     }
     
+    /** Check for deleted resources and uninstall them */
+    void checkDeletions() throws Exception {
+        // Check deletions
+        for(String uri : controller.getInstalledUris()) {
+            if(uri.startsWith(path)) {
+                if(!session.itemExists(uri)) {
+                    log.debug("Resource {} has been deleted, uninstalling");
+                    controller.uninstall(uri);
+                }
+            }
+        }
+    }
+    
     /** Install or update the given resource, as needed */ 
     protected void installOrUpdate(String path, InputStream data, Long lastModified) throws
IOException, JcrInstallException {
     	final long currentLastModified = controller.getLastModified(path);

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java?rev=693802&r1=693801&r2=693802&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
Wed Sep 10 04:53:08 2008
@@ -18,12 +18,16 @@
  */
 package org.apache.sling.jcr.jcrinstall.jcr.impl;
 
+import java.util.HashSet;
 import java.util.Set;
 
 import javax.jcr.Session;
 
 import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
 
 /** Test the "find watched folders" feature of the RepositoryObserver */
 public class FindWatchedFoldersTest extends RepositoryTestBase {
@@ -32,6 +36,8 @@
     Session session;
     private EventHelper eventHelper; 
     private ContentHelper contentHelper;
+    private Mockery mockery;
+    private OsgiController osgiController;
     
     @Override
     protected void tearDown() throws Exception {
@@ -50,12 +56,18 @@
         eventHelper = new EventHelper(session);
         contentHelper = new ContentHelper(session);
         contentHelper.cleanupContent();
+        mockery = new Mockery();
+        osgiController = mockery.mock(OsgiController.class);
+        final Set<String> installedUri = new HashSet<String>();
+        mockery.checking(new Expectations() {{
+            allowing(osgiController).getInstalledUris(); will(returnValue(installedUri));
+        }});
     }
     
     public void testInitialFind() throws Exception {
     	
     	contentHelper.setupContent();
-        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, null);
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, osgiController);
         ro.activate(null);
         
         final Set<WatchedFolder> wfSet = MiscHelper.getWatchedFolders(ro);
@@ -69,7 +81,7 @@
     
     public void testNewWatchedFolderDetection() throws Exception {
     	contentHelper.setupContent();
-        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, null);
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, osgiController);
         ro.activate(null);
 
         final String newPaths [] = { "libs/tnwf/install", "apps/tnwf/install" };

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java?rev=693802&r1=693801&r2=693802&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
Wed Sep 10 04:53:08 2008
@@ -20,6 +20,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.jcr.Session;
 
@@ -78,14 +80,14 @@
         final InputStream data = new ByteArrayInputStream(dummyJar.getBytes());
         final long lastModifiedA = System.currentTimeMillis();
         final long lastModifiedB = lastModifiedA + 1;
-        
+        final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
-        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
-        ro.activate(null);
         
         // Define the whole sequence of calls to OsgiController,
         // Using getLastModified calls to mark the test phases
         mockery.checking(new Expectations() {{
+            allowing(c).getInstalledUris(); will(returnValue(installedUri));
+            
             one(c).getLastModified("phase1"); 
             inSequence(sequence);
             one(c).getLastModified(dummyJar); will(returnValue(-1L));
@@ -106,11 +108,15 @@
             inSequence(sequence);
         }});
         
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
+        ro.activate(null);
+        
         // Add two files, run one cycle must install the bundles
         c.getLastModified("phase1");
         contentHelper.createOrUpdateFile(dummyJar, data, lastModifiedA);
         eventHelper.waitForEvents(5000L);
         ro.runOneCycle();
+        installedUri.add(dummyJar);
         
         // Updating with the same timestamp must not call install again
         c.getLastModified("phase2");
@@ -137,20 +143,22 @@
         };
         final InputStream data = new ByteArrayInputStream("hello".getBytes());
         final long lastModifiedA = System.currentTimeMillis();
-        
+        final Set<String> installedUri = new HashSet<String>();
         final OsgiController c = mockery.mock(OsgiController.class);
-        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
-        ro.activate(null);
         
         // Define the whole sequence of calls to OsgiController,
         // Using getLastModified calls to mark the test phases
         mockery.checking(new Expectations() {{
+            allowing(c).getInstalledUris(); will(returnValue(installedUri));
             allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

             one(c).installOrUpdate(with(equal(resources[0])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
             one(c).installOrUpdate(with(equal(resources[1])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
             one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)),
with(any(InputStream.class)));
         }});
         
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
+        ro.activate(null);
+        
         // Add two files, run one cycle must install the bundles
         for(String file : resources) {
             contentHelper.createOrUpdateFile(file, data, lastModifiedA);
@@ -160,4 +168,27 @@
         
         mockery.assertIsSatisfied();
     }
-}
+    
+    public void testInitialDeletions() throws Exception {
+        contentHelper.setupContent();
+        
+        final Set<String> installedUri = new HashSet<String>();
+        installedUri.add("/libs/foo/bar/install/dummy.jar");
+        installedUri.add("/libs/foo/bar/install/dummy.cfg");
+        
+        final OsgiController c = mockery.mock(OsgiController.class);
+        final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c);
+        
+        mockery.checking(new Expectations() {{
+            allowing(c).getInstalledUris(); will(returnValue(installedUri));
+            allowing(c).getLastModified(with(any(String.class))); will(returnValue(-1L));

+            one(c).uninstall("/libs/foo/bar/install/dummy.jar");
+            one(c).uninstall("/libs/foo/bar/install/dummy.cfg");
+        }});
+        
+        // Activating with installed resources that are not in
+        // the repository must cause them to be uninstalled
+        ro.activate(null);
+        mockery.assertIsSatisfied();
+    }
+}
\ No newline at end of file



Mime
View raw message