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/31 11:09:02 UTC
svn commit: r809510 - in /sling/trunk/installer/osgi/installer/src:
main/java/org/apache/sling/osgi/installer/impl/
test/java/org/apache/sling/osgi/installer/impl/
Author: bdelacretaz
Date: Mon Aug 31 09:09:01 2009
New Revision: 809510
URL: http://svn.apache.org/viewvc?rev=809510&view=rev
Log:
SLING-1078 - RegisteredResourceComparator now correctly compares configs
Modified:
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/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=809510&r1=809509&r2=809510&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 09:09:01 2009
@@ -42,7 +42,7 @@
// Order first by symbolic name
final String nameA = (String)a.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
final String nameB = (String)b.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
- if(nameA != null) {
+ if(nameA != null && nameB != null) {
result = nameA.compareTo(nameB);
}
@@ -85,6 +85,31 @@
}
int compareConfig(RegisteredResource a, RegisteredResource b) {
- return 0;
+ int result = 0;
+
+ // First compare by pid
+ final ConfigurationPid pA = (ConfigurationPid)a.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE);
+ final ConfigurationPid pB = (ConfigurationPid)b.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE);
+ if(pA != null && pA.getCompositePid() != null && pB != null && pB.getCompositePid() != null) {
+ result = pA.getCompositePid().compareTo(pB.getCompositePid());
+ }
+
+ // Then by priority, higher values first
+ if(result == 0) {
+ if(a.getPriority() < b.getPriority()) {
+ result = 1;
+ } else if(a.getPriority() > b.getPriority()) {
+ result = -1;
+ }
+ }
+
+ // Then by digest
+ if(result == 0) {
+ if(a.getDigest() != null) {
+ result = a.getDigest().compareTo(b.getDigest());
+ }
+ }
+
+ return result;
}
-}
\ No newline at end of file
+}
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=809510&r1=809509&r2=809510&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 09:09:01 2009
@@ -70,7 +70,9 @@
digest = testDigestChanged(d, digest, step, true);
d.put("key", "value");
digest = testDigestChanged(d, digest, step, false);
-
+ d.put("key", "valueB");
+ digest = testDigestChanged(d, digest, step, true);
+
d.put("int", new Integer(12));
digest = testDigestChanged(d, digest, step, true);
d.put("int", new Integer(12));
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=809510&r1=809509&r2=809510&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 09:09:01 2009
@@ -18,20 +18,23 @@
*/
package org.apache.sling.osgi.installer.impl;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.sling.osgi.installer.InstallableResource;
import org.junit.Test;
public class RegisteredResourceComparatorTest {
- private void assertOrder(List<RegisteredResource> toTest, RegisteredResource[] inOrder) {
+ private void assertOrder(Set<RegisteredResource> toTest, RegisteredResource[] inOrder) {
assertEquals("Expected sizes to match", toTest.size(), inOrder.length);
- Collections.sort(toTest, new RegisteredResourceComparator());
int i = 0;
for(RegisteredResource r : toTest) {
final RegisteredResource ref = inOrder[i];
@@ -40,8 +43,18 @@
}
}
+ private RegisteredResource getConfig(String url, Dictionary<String, Object> data, int priority) throws IOException {
+ if(data == null) {
+ data = new Hashtable<String, Object>();
+ data.put("foo", "bar");
+ }
+ final InstallableResource r = new InstallableResource("test:" + url, data);
+ r.setPriority(priority);
+ return new RegisteredResourceImpl(null, r);
+ }
+
private void assertOrder(RegisteredResource[] inOrder) {
- final List<RegisteredResource> toTest = new ArrayList<RegisteredResource>();
+ final SortedSet<RegisteredResource> toTest = new TreeSet<RegisteredResource>(new RegisteredResourceComparator());
for(int i = inOrder.length - 1 ; i >= 0; i--) {
toTest.add(inOrder[i]);
}
@@ -119,4 +132,44 @@
inOrder[0] = new MockBundleResource("a", "1.2.0.SNAPSHOT", 0, "digestA");
assertOrder(inOrder);
}
+
+ @Test
+ public void testConfigPriority() throws IOException {
+ final RegisteredResource [] inOrder = new RegisteredResource [3];
+ inOrder[0] = getConfig("pid", null, 2);
+ inOrder[1] = getConfig("pid", null, 1);
+ inOrder[2] = getConfig("pid", null, 0);
+ assertOrder(inOrder);
+ }
+
+ @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);
+
+ }
+
+ @Test
+ public void testConfigPid() throws IOException {
+ final RegisteredResource [] inOrder = new RegisteredResource [3];
+ inOrder[0] = getConfig("pidA", null, 0);
+ inOrder[1] = getConfig("pidB", null, 0);
+ inOrder[2] = getConfig("pidC", null, 0);
+ assertOrder(inOrder);
+ }
+
+ @Test
+ public void testConfigComposite() throws IOException {
+ final RegisteredResource [] inOrder = new RegisteredResource [4];
+ inOrder[0] = getConfig("pidA", null, 10);
+ inOrder[1] = getConfig("pidA", null, 0);
+ inOrder[2] = getConfig("pidB", null, 1);
+ inOrder[3] = getConfig("pidB", null, 0);
+ assertOrder(inOrder);
+ }
}
\ No newline at end of file