cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msch...@apache.org
Subject svn commit: r933566 - in /cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src: main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java
Date Tue, 13 Apr 2010 11:52:23 GMT
Author: mschaaf
Date: Tue Apr 13 11:52:23 2010
New Revision: 933566

URL: http://svn.apache.org/viewvc?rev=933566&view=rev
Log:
fixed an issue with the Zookeeper discovery which also published endpoints to Zookeeper that
where previously discovered via the local discovery.

Added:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java
Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java?rev=933566&r1=933565&r2=933566&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactory.java
Tue Apr 13 11:52:23 2010
@@ -21,6 +21,7 @@ package org.apache.cxf.dosgi.discovery.z
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+import java.util.UUID;
 import java.util.logging.Logger;
 
 import org.osgi.framework.Bundle;
@@ -29,6 +30,7 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 public class EndpointListenerFactory implements ServiceFactory {
 
@@ -73,10 +75,22 @@ public class EndpointListenerFactory imp
 
     private void updateServiceRegistration() {
         Properties props = new Properties();
-        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(" + Constants.OBJECTCLASS +
"=*)");
+        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(&(" + Constants.OBJECTCLASS
+ "=*)("+RemoteConstants.ENDPOINT_FRAMEWORK_UUID+"="+getUUID(bctx)+"))");
         serviceRegistartion.setProperties(props);
     }
 
+    // copied from the DSW OSGiUtils class
+    public static String getUUID(BundleContext bc) {
+        synchronized ("org.osgi.framework.uuid") {
+            String uuid = bc.getProperty("org.osgi.framework.uuid");
+            if (uuid == null) {
+                uuid = UUID.randomUUID().toString();
+                System.setProperty("org.osgi.framework.uuid", uuid);
+            }
+            return uuid;
+        }
+    }
+    
     public synchronized void stop() {
         if (serviceRegistartion != null)
             serviceRegistartion.unregister();

Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java?rev=933566&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java
(added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerFactoryTest.java
Tue Apr 13 11:52:23 2010
@@ -0,0 +1,87 @@
+/** 
+ * Licensed to the Apache Software Foundation (ASF) under one 
+ * or more contributor license agreements. See the NOTICE file 
+ * distributed with this work for additional information 
+ * regarding copyright ownership. The ASF licenses this file 
+ * to you under the Apache License, Version 2.0 (the 
+ * "License"); you may not use this file except in compliance 
+ * with the License. You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0 
+ * 
+ * Unless required by applicable law or agreed to in writing, 
+ * software distributed under the License is distributed on an 
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+ * KIND, either express or implied. See the License for the 
+ * specific language governing permissions and limitations 
+ * under the License. 
+ */
+package org.apache.cxf.dosgi.discovery.zookeeper;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class EndpointListenerFactoryTest extends TestCase {
+
+    public void testScope() {
+        IMocksControl c = EasyMock.createNiceControl();
+
+        BundleContext ctx = c.createMock(BundleContext.class);
+        ZooKeeperDiscovery zkd = c.createMock(ZooKeeperDiscovery.class);
+        ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
+        
+        EndpointListenerFactory eplf = new EndpointListenerFactory(zkd, ctx);
+
+        EasyMock.expect(
+                        ctx.registerService(EasyMock.eq(EndpointListener.class.getName()),
EasyMock.eq(eplf),
+                                            (Properties)EasyMock.anyObject())).andReturn(sreg).once();
+
+        
+        sreg.setProperties((Properties)EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+
+            public Object answer() throws Throwable {
+                Properties p = (Properties)EasyMock.getCurrentArguments()[0];
+                assertNotNull(p);
+                String scope = (String)p.get(EndpointListener.ENDPOINT_LISTENER_SCOPE);
+                assertNotNull(scope);
+                assertEquals("(&(" + Constants.OBJECTCLASS + "=*)(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID
+                             + "=myUUID))", scope);
+                return null;
+            }
+        }).once();
+
+        
+        EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID")
+            .anyTimes();
+
+        
+        
+        
+        c.replay();
+        eplf.start();
+        c.verify();
+
+        
+        
+        c.reset();
+        sreg.unregister();
+        EasyMock.expectLastCall().once();
+        c.replay();
+        eplf.stop();
+        c.verify();
+        
+        
+    }
+
+}



Mime
View raw message