Author: davidb
Date: Fri Jun 5 15:41:21 2009
New Revision: 782053
URL: http://svn.apache.org/viewvc?rev=782053&view=rev
Log:
Properly handle defaults with the Configuration Admin callbacks.
The following defaults are used for the zookeeper client:
zookeeper.port=2181
zookeeper.timeout=3000
The following configuration variable is required (it has no default value) to
enable the zookeeper client:
zookeeper.host
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java?rev=782053&r1=782052&r2=782053&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
(original)
+++
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
Fri Jun 5 15:41:21 2009
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -46,18 +47,28 @@
return;
}
+ Dictionary effective = getCMDefaults();
+ // apply all values on top of the defaults
+ for (Enumeration e = configuration.keys(); e.hasMoreElements(); ) {
+ Object key = e.nextElement();
+ if (key != null) {
+ Object val = configuration.get(key);
+ effective.put(key, val);
+ }
+ }
+
+ cmReg.setProperties(effective);
synchronized (this) {
try {
if (driver == null) {
- driver = createDriver(configuration);
+ driver = createDriver(effective);
} else {
- driver.updateConfiguration(configuration);
+ driver.updateConfiguration(effective);
}
} catch (IOException e) {
LOG.log(Level.WARNING, "Could now create the ZooKeeper
client", e);
}
}
- cmReg.setProperties(configuration);
}
// Isolated for testing
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java?rev=782053&r1=782052&r2=782053&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
(original)
+++
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
Fri Jun 5 15:41:21 2009
@@ -28,17 +28,14 @@
Activator a = new Activator();
a.start(bc);
- Dictionary<String, Object> expected = new Hashtable<String, Object>();
- expected.put("zookeeper.timeout", "3000");
- expected.put("zookeeper.port", "2181");
- expected.put(Constants.SERVICE_PID,
"org.apache.cxf.dosgi.discovery.zookeeper");
+ Dictionary<String, Object> expected = getDefaultProperties();
assertEquals(expected, propsAsDict(a.cmReg.getReference()));
assertFalse("Precondition failed", ((TestServiceRegistration)
a.cmReg).unregisterCalled);
a.stop(bc);
assertTrue(((TestServiceRegistration) a.cmReg).unregisterCalled);
}
-
+
public void testConfigUpdate() throws Exception {
final DiscoveryDriver mockDriver =
EasyMock.createMock(DiscoveryDriver.class);
@@ -64,20 +61,27 @@
Dictionary<String, Object> d = new Hashtable<String, Object>();
d.put("a", "b");
a.updated(d);
- assertEquals(Arrays.asList(d), configs);
+
+ Dictionary<String, Object> expected = getDefaultProperties();
+ expected.put("a", "b");
+ assertEquals(Arrays.asList(expected), configs);
assertTrue(((TestServiceRegistration) a.cmReg).setPropertiesCalled);
- assertEquals(d, propsAsDict(a.cmReg.getReference()));
+ assertEquals(expected, propsAsDict(a.cmReg.getReference()));
EasyMock.verify(mockDriver);
Dictionary<String, Object> d2 = new Hashtable<String, Object>();
d2.put("c", "d");
+
+ Dictionary<String, Object> expected2 = getDefaultProperties();
+ expected2.put("c", "d");
EasyMock.reset(mockDriver);
- mockDriver.updateConfiguration(d2);
+ mockDriver.updateConfiguration(expected2);
EasyMock.expectLastCall();
EasyMock.replay(mockDriver);
a.updated(d2);
+ assertEquals(expected2, propsAsDict(a.cmReg.getReference()));
EasyMock.verify(mockDriver);
EasyMock.reset(mockDriver);
@@ -104,6 +108,14 @@
return bc;
}
+ private Dictionary<String, Object> getDefaultProperties() {
+ Dictionary<String, Object> expected = new Hashtable<String, Object>();
+ expected.put("zookeeper.timeout", "3000");
+ expected.put("zookeeper.port", "2181");
+ expected.put(Constants.SERVICE_PID,
"org.apache.cxf.dosgi.discovery.zookeeper");
+ return expected;
+ }
+
public Dictionary<String, Object> propsAsDict(ServiceReference ref) {
Dictionary<String, Object> m = new Hashtable<String, Object>();