incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r809559 - in /sling/trunk/installer: jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/ osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ osgi/in...
Date Mon, 31 Aug 2009 12:40:58 GMT
Author: bdelacretaz
Date: Mon Aug 31 12:40:57 2009
New Revision: 809559

URL: http://svn.apache.org/viewvc?rev=809559&view=rev
Log:
SLING-1078 - resource digest ignored in RegisteredResource comparisons

Modified:
    sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/WatchedFolder.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparatorTest.java

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=809559&r1=809558&r2=809559&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
Mon Aug 31 12:40:57 2009
@@ -143,7 +143,9 @@
             		if(r != null) {
             			resourcesSeen.add(r.getUrl());
             		    final String oldDigest = digests.get(r.getUrl());
-            		    if(!r.getDigest().equals(oldDigest)) {
+            		    if(r.getDigest().equals(oldDigest)) {
+            		    	log.debug("Digest didn't change, ignoring " + r);
+            		    } else {
                             r.setPriority(priority);
                             result.toAdd.add(r);
             		    }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=809559&r1=809558&r2=809559&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Mon Aug 31 12:40:57 2009
@@ -26,6 +26,9 @@
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 /** A piece of data that can be installed by the OSGi controller.
  * 	Wraps either a Dictionary or an InputStream.
@@ -159,13 +162,21 @@
         return new String(bigInt.toString(16));
     }
     
-    /** Digest is needed to detect changes in data 
-     * @throws  */
+    /** Digest is needed to detect changes in data, and must not depend on dictionary ordering
*/
     public static String computeDigest(Dictionary<String, Object> data) throws IOException,
NoSuchAlgorithmException {
         final MessageDigest d = MessageDigest.getInstance(DIGEST_TYPE);
         final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         final ObjectOutputStream oos = new ObjectOutputStream(bos);
-        oos.writeObject(data);
+        
+        final SortedSet<String> sortedKeys = new TreeSet<String>();
+        for(Enumeration<String> e = data.keys(); e.hasMoreElements(); ) {
+        	sortedKeys.add(e.nextElement());
+        }
+        for(String key : sortedKeys) {
+        	oos.writeObject(key);
+        	oos.writeObject(data.get(key));
+        }
+        
         bos.flush();
         d.update(bos.toByteArray());
         return digestToString(d);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java?rev=809559&r1=809558&r2=809559&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
Mon Aug 31 12:40:57 2009
@@ -66,18 +66,13 @@
             }
         }
         
-        if(result == 0) {
-            if(isSnapshot) {
-                // For snapshots, compare serial numbers so that snapshots registered
-                // later get priority
-                if(a.getSerialNumber() < b.getSerialNumber()) {
-                    result = 1;
-                } else if(a.getSerialNumber() > b.getSerialNumber()) {
-                    result = -1;
-                }
-            } else {
-                // Non-snapshot: compare digests
-                result = a.getDigest().compareTo(b.getDigest());
+        if(result == 0 && isSnapshot) {
+            // For snapshots, compare serial numbers so that snapshots registered
+            // later get priority
+            if(a.getSerialNumber() < b.getSerialNumber()) {
+                result = 1;
+            } else if(a.getSerialNumber() > b.getSerialNumber()) {
+                result = -1;
             }
         }
         
@@ -103,13 +98,6 @@
             }
         }
         
-        // Then by digest
-        if(result == 0) {
-            if(a.getDigest() != null) {
-                result = a.getDigest().compareTo(b.getDigest());
-            }
-        }
-        
         return result;
     }
 }

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java?rev=809559&r1=809558&r2=809559&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryDigestTest.java
Mon Aug 31 12:40:57 2009
@@ -89,4 +89,21 @@
 		d.put("another", new String [] { "a", "b", "D"});
 		digest = testDigestChanged(d, digest, step, true);
 	}
-}
+	
+	@org.junit.Test public void testDictionaryOrderDoesNotMatter() throws Exception {
+		final Dictionary<String, Object> a = new Hashtable<String, Object>();
+		a.put("one", "A");
+		a.put("two", "B");
+		a.put("three", "C");
+		
+		final Dictionary<String, Object> b = new Hashtable<String, Object>();
+		b.put("two", "B");
+		b.put("one", "A");
+		b.put("three", "C");
+		
+		assertEquals("Same data in different order must have same digest", 
+				InstallableResource.computeDigest(a),
+				InstallableResource.computeDigest(b)
+		);
+	}
+}
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparatorTest.java?rev=809559&r1=809558&r2=809559&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparatorTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparatorTest.java
Mon Aug 31 12:40:57 2009
@@ -114,13 +114,11 @@
     }
     
     @Test
-    public void testDigest() {
-        final RegisteredResource [] inOrder = {
-                new MockBundleResource("a", "1.2.0", 0, "digestA"),
-                new MockBundleResource("a", "1.2.0", 0, "digestB"),
-                new MockBundleResource("a", "1.2.0", 0, "digestC"),
-        };
-        assertOrder(inOrder);
+    public void testBundleDigests() {
+        final RegisteredResource a = new MockBundleResource("a", "1.2.0", 0, "digestA");
+        final RegisteredResource b = new MockBundleResource("a", "1.2.0", 0, "digestB");
+        final RegisteredResourceComparator c = new RegisteredResourceComparator();
+        assertEquals("Digests must not be included in bundles comparison", 0, c.compare(a,
b));
     }
     
     @Test
@@ -143,15 +141,16 @@
     }
     
     @Test
-    public void testConfigDigest() throws IOException {
-        final Dictionary<String, Object> data = new Hashtable<String, Object>();
-        final RegisteredResource [] inOrder = new RegisteredResource [2];
-        data.put("three", "bar");
-        inOrder[0] = getConfig("pid", data, 0); 
-        data.put("two", "bar");
-        inOrder[1] = getConfig("pid", data, 0); 
-        assertOrder(inOrder);
-        
+    /** Digests must not be included in comparisons: a and b might represent the same
+     * 	config even if their digests are different */
+    public void testConfigDigests() throws IOException {
+    	final Dictionary<String, Object> data = new Hashtable<String, Object>();
+        data.put("foo", "bar");
+        final RegisteredResource a = getConfig("pid", data, 0);
+        data.put("foo", "changed");
+        final RegisteredResource b = getConfig("pid", data, 0);
+        final RegisteredResourceComparator c = new RegisteredResourceComparator();
+        assertEquals("Digests must not be included in configs comparison", 0, c.compare(a,
b));
     }
     
     @Test



Mime
View raw message