cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r772139 - 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
Date Wed, 06 May 2009 10:37:16 GMT
Author: davidb
Date: Wed May  6 10:37:16 2009
New Revision: 772139

URL: http://svn.apache.org/viewvc?rev=772139&view=rev
Log:
Additional unit tests for the previous fix to the LocalDiscoveryService

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=772139&r1=772138&r2=772139&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:37:16 2009
@@ -232,7 +232,7 @@
             (Collection<String>) reference.getProperty(property);
         LOG.info("adding tracker: " + tracker + " collection: " + collection + " registered
against prop: " + property);
         if (nonEmpty(collection)) {
-            reverseMap.put(tracker, collection);
+            reverseMap.put(tracker, new ArrayList<String>(collection));
             Iterator<String> i = collection.iterator();
             while (i.hasNext()) {
                 String element = i.next();
@@ -255,7 +255,6 @@
                       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()) {

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=772139&r1=772138&r2=772139&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:37:16 2009
@@ -456,6 +456,40 @@
         assertEquals("removeBundleListener", bundleListenerRegs.get(1));
     }
     
+    public void testAddTracker() {
+        String prop = DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA;
+
+        DiscoveredServiceTracker dst = EasyMock.createMock(DiscoveredServiceTracker.class);
+        EasyMock.replay(dst);
+        ServiceReference ref = EasyMock.createMock(ServiceReference.class);
+        List<String> interfaces = new ArrayList<String>(Arrays.asList("A", "B"));
+        EasyMock.expect(ref.getProperty(prop)).andReturn(interfaces);
+        EasyMock.replay(ref);
+        
+        Map<String, List<DiscoveredServiceTracker>> forwardMap = 
+            new HashMap<String, List<DiscoveredServiceTracker>>();
+        Map<DiscoveredServiceTracker, Collection<String>> reverseMap = 
+            new HashMap<DiscoveredServiceTracker, Collection<String>>();
+        
+        assertEquals("Precondition failed", 0, forwardMap.size());
+        assertEquals("Precondition failed", 0, reverseMap.size());
+        Collection<String> result = LocalDiscoveryService.addTracker(ref, dst, prop,

+            forwardMap, reverseMap);
+        assertEquals(interfaces, result);
+        
+        assertEquals(interfaces, reverseMap.get(dst));
+        // check that the data in the reversemap is backed by a different array
+        reverseMap.get(dst).clear();
+        assertEquals("The data in the reverseMap should be backed by a different object,
not the DST property",
+            Arrays.asList("A", "B"), interfaces);
+        
+        assertEquals(2, forwardMap.size());
+        assertEquals(Collections.singletonList(dst), forwardMap.get("A"));
+        assertEquals(Collections.singletonList(dst), forwardMap.get("B"));
+
+        EasyMock.verify(ref);
+    }
+    
     public void testRemoveTracker() {
         DiscoveredServiceTracker dst = new DiscoveredServiceTracker(){
             public void serviceChanged(DiscoveredServiceNotification notification) {
@@ -464,19 +498,36 @@
         
         Map<String, List<DiscoveredServiceTracker>> forwardMap = 
             new HashMap<String, List<DiscoveredServiceTracker>>();
+        forwardMap.put("A", new ArrayList<DiscoveredServiceTracker>(Arrays.asList(dst)));
+
         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);
+        reverseMap.put(dst, new ArrayList<String>(Arrays.asList("A", "B")));
+        
+        assertEquals("Precondition failed", 1, reverseMap.size());
+        assertEquals("Precondition failed", 1, forwardMap.get("A").size());
         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());
+        
+        assertEquals(0, forwardMap.get("A").size());
+        assertEquals(0, reverseMap.size());
     }
 
+    public void testRemoveTrackerNull() {
+        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>>();
+        
+        assertNull(LocalDiscoveryService.removeTracker(dst, forwardMap, reverseMap));
+    }
+ 
     private void verifyNotification(DiscoveredServiceNotification dsn,
                                int filterCount,
                                int interfaceCount,



Mime
View raw message