You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/08/26 16:01:37 UTC
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/
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 <JcrInstaller.NodeConverter> converters;
+ private final Set<String> existingResourceUrls = new HashSet<String>();
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<String> resourcesSeen = new HashSet<String>();
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<String, String> 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