cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r768256 - in /cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src: main/java/org/apache/cxf/dosgi/discovery/zookeeper/ test/java/org/apache/cxf/dosgi/discovery/zookeeper/
Date Fri, 24 Apr 2009 11:03:11 GMT
Author: davidb
Date: Fri Apr 24 11:03:10 2009
New Revision: 768256

URL: http://svn.apache.org/viewvc?rev=768256&view=rev
Log:
[Discovery] Adding support for DiscoveredServiceNotification.MODIFIED

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java?rev=768256&r1=768255&r2=768256&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
Fri Apr 24 11:03:10 2009
@@ -63,14 +63,7 @@
                 p.load(new ByteArrayInputStream(data));
                 
                 Map<String, Object> m = new HashMap<String, Object>();
-                for (Map.Entry<Object, Object> entry : p.entrySet()) {
-                    /* TODO this is probably not necessary
-                    if (Constants.SERVICE_ID.equals(entry.getKey()) ||
-                        Constants.SERVICE_PID.equals(entry.getKey()) ||
-                        Constants.OBJECTCLASS.equals(entry.getKey())) {
-                        continue;
-                    } */
-                    
+                for (Map.Entry<Object, Object> entry : p.entrySet()) {            
       
                     m.put(entry.getKey().toString(), entry.getValue());
                 }
                 
@@ -82,10 +75,13 @@
                     DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
                         Collections.singleton(interFace), DiscoveredServiceNotification.AVAILABLE,
sed);
                     discoveredServiceTracker.serviceChanged(dsn);                    
-                } else {
+                } else if (!prevVal.equals(m)){
                     // There's been a modification
-                }
-                
+                    ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(Collections.singletonList(interFace),
m);
+                    DiscoveredServiceNotification dsn = new DiscoveredServiceNotificationImpl(Collections.emptyList(),
+                        Collections.singleton(interFace), DiscoveredServiceNotification.MODIFIED,
sed);
+                    discoveredServiceTracker.serviceChanged(dsn);                    
+                }                
             }
 
             for (Map<String, Object> props : prevNodes.values()) {

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java?rev=768256&r1=768255&r2=768256&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
Fri Apr 24 11:03:10 2009
@@ -42,16 +42,19 @@
             }            
         };
         
+        //----------------------------------------------------------------
+        // Test DiscoveredServiceNotification.AVAILABLE
+        //----------------------------------------------------------------
         Properties initial = new Properties();
         initial.put("a", "b");     
         ByteArrayOutputStream propBytes = new ByteArrayOutputStream();
         initial.store(propBytes, "");
         
         ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
-        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false)).
-            andReturn(Arrays.asList("x#y#z"));
-        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z",
false, null)).
-            andReturn(propBytes.toByteArray());
+        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
+            .andReturn(Arrays.asList("x#y#z"));
+        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z",
false, null))
+            .andReturn(propBytes.toByteArray());
         EasyMock.replay(zk);
 
         InterfaceDataMonitorListenerImpl dml = new InterfaceDataMonitorListenerImpl(zk, String.class.getName(),
dst);
@@ -66,5 +69,83 @@
         ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
         assertEquals(Collections.singleton(String.class.getName()), sed.getProvidedInterfaces());
       
         assertEquals(initial, sed.getProperties());
+        EasyMock.verify(zk);
+        
+        // Again with the same data
+        EasyMock.reset(zk);
+        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
+            .andReturn(Arrays.asList("x#y#z"));
+        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z",
false, null))
+            .andReturn(propBytes.toByteArray());
+        EasyMock.replay(zk);
+
+        dsnCallbacks.clear();
+        assertEquals("Precondition failed", 0, dsnCallbacks.size());
+        dml.change();
+        assertEquals(0, dsnCallbacks.size());
+        
+        EasyMock.verify(zk);
+        //----------------------------------------------------------------
+        // Test DiscoveredServiceNotification.MODIFIED
+        //----------------------------------------------------------------
+        Properties modified = new Properties();
+        modified.put("c", "d");
+        ByteArrayOutputStream modBytes = new ByteArrayOutputStream();
+        modified.store(modBytes, "");
+        
+        EasyMock.reset(zk);
+        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
+            .andReturn(Arrays.asList("x#y#z"));
+        EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + "/x#y#z",
false, null))
+            .andReturn(modBytes.toByteArray());
+        EasyMock.replay(zk);
+
+        dsnCallbacks.clear();
+        assertEquals("Precondition failed", 0, dsnCallbacks.size());
+        dml.change();
+        assertEquals(1, dsnCallbacks.size());
+        DiscoveredServiceNotification dsn2 = dsnCallbacks.iterator().next();
+        assertEquals(Collections.singleton(String.class.getName()), dsn2.getInterfaces());
+        assertEquals(DiscoveredServiceNotification.MODIFIED, dsn2.getType());
+        assertEquals(0, dsn2.getFilters().size());
+        ServiceEndpointDescription sed2 = dsn2.getServiceEndpointDescription();
+        assertEquals(Collections.singleton(String.class.getName()), sed2.getProvidedInterfaces());
       
+        assertEquals(modified, sed2.getProperties());
+        
+        EasyMock.verify(zk);
+
+        //----------------------------------------------------------------
+        // Test DiscoveredServiceNotification.UNAVAILABLE
+        //----------------------------------------------------------------
+        EasyMock.reset(zk);
+        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
+            .andReturn(Collections.<String>emptyList());
+        EasyMock.replay(zk);
+
+        dsnCallbacks.clear();
+        assertEquals("Precondition failed", 0, dsnCallbacks.size());
+        dml.change();
+        assertEquals(1, dsnCallbacks.size());
+        DiscoveredServiceNotification dsn3 = dsnCallbacks.iterator().next();
+        assertEquals(Collections.singleton(String.class.getName()), dsn3.getInterfaces());
+        assertEquals(DiscoveredServiceNotification.UNAVAILABLE, dsn3.getType());
+        assertEquals(0, dsn3.getFilters().size());
+        ServiceEndpointDescription sed3 = dsn3.getServiceEndpointDescription();
+        assertEquals(Collections.singleton(String.class.getName()), sed3.getProvidedInterfaces());
       
+        assertEquals(modified, sed3.getProperties());
+        
+        EasyMock.verify(zk);
+        
+        // Try the same again...
+        EasyMock.reset(zk);
+        EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), false))
+            .andReturn(Collections.<String>emptyList());
+        EasyMock.replay(zk);
+
+        dsnCallbacks.clear();
+        assertEquals("Precondition failed", 0, dsnCallbacks.size());
+        dml.change();
+        assertEquals("Should not receive a callback again...", 0, dsnCallbacks.size());
+        EasyMock.verify(zk);
     }
 }



Mime
View raw message