You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2009/05/06 12:06:44 UTC
svn commit: r772127 - in /cxf/dosgi/trunk/discovery/local/src:
main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java
test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java
Author: davidb
Date: Wed May 6 10:06:43 2009
New Revision: 772127
URL: http://svn.apache.org/viewvc?rev=772127&view=rev
Log:
Fix relating to CXF-2200.
The algorithm to compute deltas to the DiscoveredServiceTracker used in the LocalDiscoveryService sometimes missed certain deltas. This is now fixed.
New unit tests included - more unit tests to come.
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java
Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java?rev=772127&r1=772126&r2=772127&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryService.java Wed May 6 10:06:43 2009
@@ -33,7 +33,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
@@ -49,7 +48,6 @@
import org.osgi.service.discovery.DiscoveredServiceTracker;
import org.osgi.service.discovery.Discovery;
import org.osgi.service.discovery.ServiceEndpointDescription;
-import org.osgi.service.discovery.ServicePublication;
import org.osgi.util.tracker.ServiceTracker;
public class LocalDiscoveryService implements Discovery, BundleListener {
@@ -224,7 +222,7 @@
}
@SuppressWarnings("unchecked")
- private Collection<String> addTracker(
+ static Collection<String> addTracker(
ServiceReference reference,
DiscoveredServiceTracker tracker,
String property,
@@ -251,18 +249,23 @@
return collection;
}
- private Collection<String> removeTracker(
+ static Collection<String> removeTracker(
DiscoveredServiceTracker tracker,
Map<String, List<DiscoveredServiceTracker>> forwardMap,
Map<DiscoveredServiceTracker, Collection<String>> reverseMap) {
Collection<String> collection = reverseMap.get(tracker);
if (nonEmpty(collection)) {
+ collection = new ArrayList<String>(collection); // work on a copy
reverseMap.remove(tracker);
Iterator<String> i = collection.iterator();
while (i.hasNext()) {
String element = i.next();
if (forwardMap.containsKey(element)) {
forwardMap.get(element).remove(tracker);
+ } else {
+ // if the element wasn't on the forwardmap, its a new element and
+ // shouldn't be returned as part of the collection of old ones
+ i.remove();
}
}
}
Modified: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java?rev=772127&r1=772126&r2=772127&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java (original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryServiceTest.java Wed May 6 10:06:43 2009
@@ -31,7 +31,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import junit.framework.TestCase;
@@ -456,6 +455,27 @@
assertEquals("addBundleListener", bundleListenerRegs.get(0));
assertEquals("removeBundleListener", bundleListenerRegs.get(1));
}
+
+ public void testRemoveTracker() {
+ DiscoveredServiceTracker dst = new DiscoveredServiceTracker(){
+ public void serviceChanged(DiscoveredServiceNotification notification) {
+ }
+ };
+
+ Map<String, List<DiscoveredServiceTracker>> forwardMap =
+ new HashMap<String, List<DiscoveredServiceTracker>>();
+ Map<DiscoveredServiceTracker, Collection<String>> reverseMap =
+ new HashMap<DiscoveredServiceTracker, Collection<String>>();
+ ArrayList<String> l = new ArrayList<String>(Arrays.asList("A", "B"));
+ reverseMap.put(dst, l);
+ List<DiscoveredServiceTracker> l2 = new ArrayList<DiscoveredServiceTracker>(Arrays.asList(dst));
+ forwardMap.put("A", l2);
+ Collection<String> old = LocalDiscoveryService.removeTracker(dst, forwardMap, reverseMap);
+ assertEquals(1, old.size());
+ assertEquals("A", old.iterator().next());
+ assertEquals("this list should not have been modified yet", 2, l.size());
+ assertEquals("This list should be emptu now", 0, l2.size());
+ }
private void verifyNotification(DiscoveredServiceNotification dsn,
int filterCount,