Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 14153 invoked from network); 26 Aug 2009 14:02:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Aug 2009 14:02:06 -0000 Received: (qmail 87535 invoked by uid 500); 26 Aug 2009 14:02:06 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 87478 invoked by uid 500); 26 Aug 2009 14:02:06 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 87469 invoked by uid 99); 26 Aug 2009 14:02:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Aug 2009 14:02:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Aug 2009 14:01:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 52DC723888E5; Wed, 26 Aug 2009 14:01:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r808013 - in /sling/trunk/installer/jcr/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/impl/ test/java/org/apache/sling/jcr/jcrinstall/impl/ Date: Wed, 26 Aug 2009 14:01:37 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090826140137.52DC723888E5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Wed Aug 26 14:01:36 2009 New Revision: 808013 URL: http://svn.apache.org/viewvc?rev=808013&view=rev Log: SLING-1078 - test*update added Modified: sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ContentHelper.java sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ResourceDetectionTest.java Modified: sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java?rev=808013&r1=808012&r2=808013&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java Wed Aug 26 14:01:36 2009 @@ -187,7 +187,7 @@ resources.addAll(r.toAdd); } - log.info("Registering {} resources with OSGi installer", resources.size()); + log.info("Registering {} resources with OSGi installer: {}", resources.size(), resources); installer.registerResources(resources, URL_SCHEME); final Thread t = new Thread(this, getClass().getSimpleName() + "." + deactivationCounter); @@ -333,7 +333,7 @@ installer.removeResource(r); } for(InstallableResource r : sr.toAdd) { - log.info("Adding resource to OSGi installer: {}",r); + log.info("Registering resource with OSGi installer: {}",r); installer.addResource(r); } } Modified: sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java?rev=808013&r1=808012&r2=808013&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java Wed Aug 26 14:01:36 2009 @@ -21,8 +21,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.jcr.Item; import javax.jcr.Node; @@ -48,6 +50,7 @@ private boolean needsScan; private final String urlScheme; private final Collection converters; + private final Set existingResourceUrls = new HashSet(); protected final Logger log = LoggerFactory.getLogger(getClass()); static class ScanResult { @@ -129,6 +132,7 @@ // Return an InstallableResource for all child nodes for which we have a NodeConverter final ScanResult result = new ScanResult(); + final Set resourcesSeen = new HashSet(); if(folder != null) { final NodeIterator it = folder.getNodes(); while(it.hasNext()) { @@ -136,11 +140,9 @@ for(JcrInstaller.NodeConverter nc : converters) { final InstallableResource r = nc.convertNode(urlScheme, n); if(r != null) { + resourcesSeen.add(r.getUrl()); final String oldDigest = digests.get(r.getUrl()); - if(r.getDigest().equals(oldDigest)) { - // Already returned that resource, ignore - digests.remove(r.getUrl()); - } else { + if(!r.getDigest().equals(oldDigest)) { r.setPriority(priority); result.toAdd.add(r); } @@ -150,16 +152,22 @@ } } - // Resources left in the digests map have been deleted since last scan, - // need to be removed from OsgiInstaller - for(Map.Entry e : digests.entrySet()) { - InstallableResource r = new InstallableResource(e.getKey()); - result.toRemove.add(r); + // Resources that existed but are not in resourcesSeen need to be + // unregistered from OsgiInstaller + for(String url : existingResourceUrls) { + if(!resourcesSeen.contains(url)) { + InstallableResource r = new InstallableResource(url); + result.toRemove.add(r); + } + } + for(InstallableResource r : result.toRemove) { + existingResourceUrls.remove(r.getUrl()); + digests.remove(r.getUrl()); } - // Store digests of the resources that we're adding, for next time - digests.clear(); + // Update saved digests of the resources that we're returning for(InstallableResource r : result.toAdd) { + existingResourceUrls.add(r.getUrl()); digests.put(r.getUrl(), r.getDigest()); } Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ContentHelper.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ContentHelper.java?rev=808013&r1=808012&r2=808013&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ContentHelper.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ContentHelper.java Wed Aug 26 14:01:36 2009 @@ -127,9 +127,7 @@ } void createOrUpdateFile(String path) throws RepositoryException { - final String data = "Fake data for " + path; - final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes()); - createOrUpdateFile(path, is, System.currentTimeMillis()); + createOrUpdateFile(path, null, System.currentTimeMillis()); } void createOrUpdateFile(String path, MockInstallableResource d) throws RepositoryException { @@ -137,6 +135,11 @@ } void createOrUpdateFile(String path, InputStream data, long lastModified) throws RepositoryException { + if(data == null) { + final String content = "Fake data for " + path; + data = new ByteArrayInputStream(content.getBytes()); + } + final String relPath = relPath(path); Node f = null; Node res = null; Modified: sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ResourceDetectionTest.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ResourceDetectionTest.java?rev=808013&r1=808012&r2=808013&view=diff ============================================================================== --- sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ResourceDetectionTest.java (original) +++ sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/ResourceDetectionTest.java Wed Aug 26 14:01:36 2009 @@ -18,6 +18,7 @@ */ package org.apache.sling.jcr.jcrinstall.impl; +import javax.jcr.Node; import javax.jcr.Session; import org.apache.sling.commons.testing.jcr.RepositoryTestBase; @@ -149,9 +150,8 @@ assertRegistered(contentHelper.FAKE_CONFIGS[i], i != toRemove); } - final int nCalls = contentHelper.FAKE_RESOURCES.length + contentHelper.FAKE_CONFIGS.length; - assertEquals("Expecting both remove and add calls when resources are deleted", - nCalls, osgiInstaller.getRecordedCalls().size()); + assertEquals("Expecting only remove calls when resources are deleted", + 2, osgiInstaller.getRecordedCalls().size()); } public void testStopAndRestart() throws Exception { @@ -222,4 +222,60 @@ assertRegistered(path, !path.startsWith("/libs")); } } + + public void testFileUpdate() throws Exception { + final String path = contentHelper.FAKE_RESOURCES[0]; + assertRegistered(path, true); + + // Make a change that does not influence the file's digest, + // and verify that no OSGi registrations result + int nCalls = osgiInstaller.getRecordedCalls().size(); + ((Node)session.getItem(path + "/jcr:content")).setProperty("jcr:mimeType", "application/" + getClass().getName()); + session.save(); + eventHelper.waitForEvents(TIMEOUT); + MiscUtil.waitForCycles(installer, 2, TIMEOUT); + assertEquals("Expected no OsgiInstaller calls for no-impact file change", + nCalls, osgiInstaller.getRecordedCalls().size()); + + // Make a content change -> resource must be re-registered + osgiInstaller.clearRecordedCalls(); + contentHelper.createOrUpdateFile(path, null, System.currentTimeMillis()); + eventHelper.waitForEvents(TIMEOUT); + MiscUtil.waitForCycles(installer, 2, TIMEOUT); + assertEquals("Expected one OsgiInstaller call for file content change", + 1, osgiInstaller.getRecordedCalls().size()); + assertRecordedCall("add", path); + } + + public void testConfigUpdate() throws Exception { + final String path = contentHelper.FAKE_CONFIGS[0]; + assertRegistered(path, true); + + // Setup a known value for the config + final String key = "foo" + System.currentTimeMillis(); + final String value = "value" + System.currentTimeMillis(); + ((Node)session.getItem(path)).setProperty(key, value); + session.save(); + eventHelper.waitForEvents(TIMEOUT); + MiscUtil.waitForCycles(installer, 2, TIMEOUT); + + // Make a change that does not influence the configs's digest, + // and verify that no OSGi registrations result + int nCalls = osgiInstaller.getRecordedCalls().size(); + ((Node)session.getItem(path)).setProperty(key, value); + session.save(); + eventHelper.waitForEvents(TIMEOUT); + MiscUtil.waitForCycles(installer, 2, TIMEOUT); + assertEquals("Expected no OsgiInstaller calls for no-impact config change", + nCalls, osgiInstaller.getRecordedCalls().size()); + + // Make a content change -> resource must be re-registered + osgiInstaller.clearRecordedCalls(); + ((Node)session.getItem(path)).setProperty(key, value + "-changed"); + eventHelper.waitForEvents(TIMEOUT); + MiscUtil.waitForCycles(installer, 2, TIMEOUT); + assertEquals("Expected one OsgiInstaller call for config content change", + 1, osgiInstaller.getRecordedCalls().size()); + assertRecordedCall("add", path); + } } \ No newline at end of file