cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1487608 - 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 Wed, 29 May 2013 19:32:58 GMT
Author: amichai
Date: Wed May 29 19:32:57 2013
New Revision: 1487608

URL: http://svn.apache.org/r1487608
Log:
More discovery.zookeeper package cleanup and little refactorings

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerTrackerCustomizer.java
Wed May 29 19:32:57 2013
@@ -21,7 +21,6 @@ package org.apache.cxf.dosgi.discovery.z
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
@@ -37,7 +36,7 @@ public class EndpointListenerTrackerCust
 
     private InterfaceMonitorManager imManager;
 
-    public EndpointListenerTrackerCustomizer(BundleContext bc, InterfaceMonitorManager imManager)
{
+    public EndpointListenerTrackerCustomizer(InterfaceMonitorManager imManager) {
         this.imManager = imManager;
     }
 
@@ -62,8 +61,7 @@ public class EndpointListenerTrackerCust
             }
         }
 
-        String[] scopes = Util.getScopes(sref);
-        for (String scope : scopes) {
+        for (String scope : Util.getScopes(sref)) {
             String objClass = getObjectClass(scope);
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Adding interest in scope: " + scope + " objectClass: " + objClass);
@@ -78,9 +76,6 @@ public class EndpointListenerTrackerCust
     }
 
     private String getObjectClass(String scope) {
-        if (scope == null) {
-            return null;
-        }
         Matcher m = OBJECTCLASS_PATTERN.matcher(scope);
         return m.matches() ? m.group(1) : null;
     }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
Wed May 29 19:32:57 2013
@@ -32,12 +32,19 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.jdom.Element;
-import org.osgi.framework.BundleContext;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Monitors ZooKeeper for changes in published endpoints.
+ * <p>
+ * Specifically, it monitors the node path associated with a given interface class,
+ * whose data is a serialized version of an EndpointDescription, and notifies an
+ * EndpointListener when changes are detected (which can then propagate the
+ * notification to other EndpointListeners with a matching scope).
+ */
 public class InterfaceMonitor implements Watcher, StatCallback {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceMonitor.class);
 
@@ -50,7 +57,7 @@ public class InterfaceMonitor implements
     // This map reference changes, so don't synchronize on it
     private Map<String, EndpointDescription> nodes = new HashMap<String, EndpointDescription>();
 
-    public InterfaceMonitor(ZooKeeper zk, String intf, EndpointListener epListener, String
scope, BundleContext bctx) {
+    public InterfaceMonitor(ZooKeeper zk, String intf, EndpointListener epListener, String
scope) {
         this.zookeeper = zk;
         this.znode = Util.getZooKeeperPath(intf);
         this.recursive = intf == null || intf.isEmpty();

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorManager.java
Wed May 29 19:32:57 2013
@@ -117,7 +117,7 @@ public class InterfaceMonitorManager {
                 notifyListeners(endpoint, true, interest.relatedServiceListeners);
             }
         };
-        return new InterfaceMonitor(zooKeeper, objClass, epListener, scope, bctx);
+        return new InterfaceMonitor(zooKeeper, objClass, epListener, scope);
     }
 
     public void removeInterest(ServiceReference sref) {

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishingEndpointListener.java
Wed May 29 19:32:57 2013
@@ -91,24 +91,7 @@ public class PublishingEndpointListener 
             }
 
             try {
-
-                Collection<String> interfaces = endpoint.getInterfaces();
-                String endpointKey = getKey(endpoint.getId());
-
-                for (String name : interfaces) {
-                    Map<String, Object> props = new HashMap<String, Object>(endpoint.getProperties());
-                    for (DiscoveryPlugin plugin : discoveryPlugins) {
-                        endpointKey = plugin.process(props, endpointKey);
-                    }
-
-                    String path = Util.getZooKeeperPath(name);
-                    ensurePath(path, zookeeper);
-
-                    String fullPath = path + '/' + endpointKey;
-                    LOG.debug("Creating ZooKeeper node: {}", fullPath);
-                    zookeeper.create(fullPath, getData(props), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
-                }
-
+                addEndpoint(endpoint);
                 endpoints.add(endpoint);
             } catch (Exception ex) {
                 LOG.error("Exception while processing the addition of an endpoint.", ex);
@@ -117,6 +100,26 @@ public class PublishingEndpointListener 
 
     }
 
+    private void addEndpoint(EndpointDescription endpoint) throws URISyntaxException, KeeperException,
+                                                                  InterruptedException, IOException
{
+        Collection<String> interfaces = endpoint.getInterfaces();
+        String endpointKey = getKey(endpoint.getId());
+
+        for (String name : interfaces) {
+            Map<String, Object> props = new HashMap<String, Object>(endpoint.getProperties());
+            for (DiscoveryPlugin plugin : discoveryPlugins) {
+                endpointKey = plugin.process(props, endpointKey);
+            }
+
+            String path = Util.getZooKeeperPath(name);
+            ensurePath(path, zookeeper);
+
+            String fullPath = path + '/' + endpointKey;
+            LOG.debug("Creating ZooKeeper node: {}", fullPath);
+            zookeeper.create(fullPath, getData(props), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
+        }
+    }
+
     public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) {
         LOG.info("Local EndpointDescription removed: " + endpoint);
 
@@ -174,8 +177,7 @@ public class PublishingEndpointListener 
     }
 
     static byte[] getData(Map<String, Object> props) throws IOException {
-        String s = LocalDiscoveryUtils.getEndpointDescriptionXML(props);
-        return s.getBytes();
+        return LocalDiscoveryUtils.getEndpointDescriptionXML(props).getBytes();
     }
 
     static String getKey(String endpoint) throws UnknownHostException, URISyntaxException
{

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
Wed May 29 19:32:57 2013
@@ -18,11 +18,8 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.UUID;
 
 import org.osgi.framework.BundleContext;
@@ -30,22 +27,11 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 
 public final class Util {
+
     static final String PATH_PREFIX = "/osgi/service_registry";
+
     private Util() {
-        //never constructed
-    }
-    
-    @SuppressWarnings("unchecked")
-    static Collection<String> getMultiValueProperty(Object property) {
-        if (property instanceof Collection) {
-            return (Collection<String>)property;
-        } else if (property instanceof String[]) {
-            return Arrays.asList((String[])property);
-        } else if (property == null) {
-            return Collections.emptySet();
-        } else {
-            return Collections.singleton(property.toString());
-        }
+        // never constructed
     }
 
     static String getZooKeeperPath(String name) {
@@ -55,46 +41,55 @@ public final class Util {
         return PATH_PREFIX + '/' + name.replace('.', '/');
     }
 
-    
-    static String[] getStringPlusProperty(Object property) {
-
+    /**
+     * Returns the value of a "string+" property as an array of strings.
+     * <p>
+     * A "string+" property can have a value which is either a string,
+     * an array of strings, or a collection of strings.
+     * <p>
+     * If the given value is not of one of the valid types, or is null,
+     * an empty array is returned.
+     *
+     * @param property a "string+" property value
+     * @return the property value as an array of strings, or an empty array
+     */
+    public static String[] getStringPlusProperty(Object property) {
         if (property instanceof String) {
-            // System.out.println("String");
-            String[] ret = new String[1];
-            ret[0] = (String)property;
-            return ret;
-        }
-
-        if (property instanceof String[]) {
-            // System.out.println("String[]");
+            return new String[] {(String)property};
+        } else if (property instanceof String[]) {
             return (String[])property;
-        }
-
-        if (property instanceof Collection) {
-            @SuppressWarnings("rawtypes")
-            Collection col = (Collection)property;
-            // System.out.println("Collection: size "+col.size());
-            String[] ret = new String[col.size()];
-            int x = 0;
-            for (Object s : col) {
-                ret[x] = (String)s;
-                ++x;
+        } else if (property instanceof Collection) {
+            try {
+                @SuppressWarnings("unchecked")
+                Collection<String> strings = (Collection<String>)property;
+                return strings.toArray(new String[strings.size()]);
+            } catch (ArrayStoreException ase) {
+                // ignore collections with wrong type
             }
-            return ret;
         }
-
         return new String[0];
     }
 
-    public static String[] getScopes(ServiceReference sref) {
-        String[] scopes = Util.getStringPlusProperty(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE));
-        List<String> normalizedScopes = new ArrayList<String>(scopes.length);
-        for (String scope : scopes) {
-            if (scope != null && !"".equals(scope)) {
-                normalizedScopes.add(scope);
+    /**
+     * Removes nulls and empty strings from the given string array.
+     *
+     * @param strings an array of strings
+     * @return a new array containing the non-null and non-empty
+     *         elements of the original array in the same order
+     */
+    public static String[] removeEmpty(String[] strings) {
+        String[] result = new String[strings.length];
+        int copied = 0;
+        for (String s : strings) {
+            if (s != null && !s.isEmpty()) {
+                result[copied++] = s;
             }
         }
-        return normalizedScopes.toArray(new String[normalizedScopes.size()]);
+        return copied == result.length ? result : Arrays.copyOf(result, copied);
+    }
+
+    public static String[] getScopes(ServiceReference sref) {
+        return removeEmpty(getStringPlusProperty(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)));
     }
 
     // copied from the DSW OSGiUtils class

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
Wed May 29 19:32:57 2013
@@ -23,7 +23,6 @@ import java.util.Dictionary;
 
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZooKeeper;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ConfigurationException;
@@ -68,32 +67,30 @@ public class ZooKeeperDiscovery implemen
             return;
         }
         curConfiguration = configuration;
-        try {
-            zooKeeper = createZooKeeper(configuration);
-        } catch (IOException e) {
-            LOG.error("Failed to start the Zookeeper Discovery component.", e);
-        }
+        createZooKeeper(configuration);
     }
 
-    private void startModules() {
+    private void start() {
+        LOG.debug("starting ZookeeperDiscovery");
         endpointListenerFactory = new PublishingEndpointListenerFactory(zooKeeper, bctx);
         endpointListenerFactory.start();
         imManager = new InterfaceMonitorManager(bctx, zooKeeper);
-        EndpointListenerTrackerCustomizer customizer = new EndpointListenerTrackerCustomizer(bctx,
imManager);
+        EndpointListenerTrackerCustomizer customizer = new EndpointListenerTrackerCustomizer(imManager);
         endpointListenerTracker = new ServiceTracker(bctx, EndpointListener.class.getName(),
customizer);
         endpointListenerTracker.open();
     }
 
     public synchronized void stop() {
         if (endpointListenerFactory != null) {
+            LOG.debug("stopping ZookeeperDiscovery");
             endpointListenerFactory.stop();
         }
-        if (imManager != null) {
-            imManager.close();
-        }
         if (endpointListenerTracker != null) {
             endpointListenerTracker.close();
         }
+        if (imManager != null) {
+            imManager.close();
+        }
         if (zooKeeper != null) {
             try {
                 zooKeeper.close();
@@ -104,22 +101,21 @@ public class ZooKeeperDiscovery implemen
     }
 
     @SuppressWarnings("rawtypes")
-    private ZooKeeper createZooKeeper(Dictionary props) throws IOException {
+    private void createZooKeeper(Dictionary props) {
         String zkHost = getProp(props, "zookeeper.host", "localhost");
         String zkPort = getProp(props, "zookeeper.port", "2181");
         int zkTimeout = Integer.parseInt(getProp(props, "zookeeper.timeout", "3000"));
-        return new ZooKeeper(zkHost + ":" + zkPort, zkTimeout, this);
+        try {
+            zooKeeper = new ZooKeeper(zkHost + ":" + zkPort, zkTimeout, this);
+        } catch (IOException e) {
+            LOG.error("Failed to start the Zookeeper Discovery component.", e);
+        }
     }
 
     @SuppressWarnings("rawtypes")
     private static String getProp(Dictionary props, String key, String def) {
         Object val = props.get(key);
-        String rv;
-        if (val == null) {
-            rv = def;
-        } else {
-            rv = val.toString();
-        }
+        String rv = val == null ? def : val.toString();
 
         LOG.debug("Reading Config Admin property: {} value returned: {}", key, rv);
         return rv;
@@ -127,19 +123,21 @@ public class ZooKeeperDiscovery implemen
 
     /* Callback for ZooKeeper */
     public void process(WatchedEvent event) {
-        KeeperState state = event.getState();
-        if (state == KeeperState.SyncConnected) {
+        switch (event.getState()) {
+        case SyncConnected:
             LOG.info("Connection to zookeeper established");
-            startModules();
-        }
-        if (state == KeeperState.Expired) {
+            start();
+            break;
+
+        case Expired:
             LOG.info("Connection to zookeeper expired. Trying to create a new connection");
             stop();
-            try {
-                zooKeeper = createZooKeeper(curConfiguration);
-            } catch (IOException e) {
-                LOG.error("Failed to start the Zookeeper Discovery component.", e);
-            }
+            createZooKeeper(curConfiguration);
+            break;
+
+        default:
+            // ignore other events
+            break;
         }
     }
 }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
Wed May 29 19:32:57 2013
@@ -31,7 +31,6 @@ import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
-import org.osgi.framework.BundleContext;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 
 import static org.easymock.EasyMock.eq;
@@ -43,7 +42,6 @@ public class InterfaceMonitorTest extend
 
         IMocksControl c = EasyMock.createControl();
 
-        BundleContext ctx = c.createMock(BundleContext.class);
         ZooKeeper zk = c.createMock(ZooKeeper.class);
         expect(zk.getState()).andReturn(ZooKeeper.States.CONNECTED).anyTimes();
 
@@ -52,7 +50,7 @@ public class InterfaceMonitorTest extend
         String node = Util.getZooKeeperPath(interf);
 
         EndpointListener epListener = c.createMock(EndpointListener.class);
-        InterfaceMonitor im = new InterfaceMonitor(zk, interf, epListener, scope, ctx);
+        InterfaceMonitor im = new InterfaceMonitor(zk, interf, epListener, scope);
         zk.exists(eq(node), eq(im), eq(im), EasyMock.anyObject());
         EasyMock.expectLastCall().once();
 

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java?rev=1487608&r1=1487607&r2=1487608&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/UtilTest.java
Wed May 29 19:32:57 2013
@@ -18,10 +18,7 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -31,28 +28,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 
 public class UtilTest extends TestCase {
-    
-    public void testMultiValuePropertyAsString() {
-        assertEquals(Collections.singleton("hi"), 
-            Util.getMultiValueProperty("hi"));            
-    }
-    
-    public void testMultiValuePropertyAsArray() {
-        assertEquals(Arrays.asList("a", "b"), 
-            Util.getMultiValueProperty(new String [] {"a", "b"}));
-    }
-    
-    public void testMultiValuePropertyAsCollection() {
-        List<String> list = new ArrayList<String>();
-        list.add("1");
-        list.add("2");
-        list.add("3");
-        assertEquals(list, Util.getMultiValueProperty(list)); 
-        
-        assertEquals(Collections.emptySet(), Util.getMultiValueProperty(null));
-        
-    }
-    
+
     public void testGetZooKeeperPath() {
         assertEquals(Util.PATH_PREFIX + '/' + "org/example/Test", 
             Util.getZooKeeperPath("org.example.Test"));
@@ -61,31 +37,58 @@ public class UtilTest extends TestCase {
         assertEquals(Util.PATH_PREFIX, Util.getZooKeeperPath(null));
         assertEquals(Util.PATH_PREFIX, Util.getZooKeeperPath(""));
     }
-    
-    
+
     @SuppressWarnings("unchecked")
     public void testGetStringPlusProperty() {
-        Object in = "MyString";
-        String[] out = Util.getStringPlusProperty(in);
+        String[] out = Util.getStringPlusProperty("MyString");
         assertEquals(1, out.length);
         assertEquals("MyString", out[0]);
         
-        
-        in = new String[]{"MyString"};
-        out = Util.getStringPlusProperty(in);
+        out = Util.getStringPlusProperty(new String[]{"MyString"});
         assertEquals(1, out.length);
         assertEquals("MyString", out[0]);
         
-        in = new ArrayList<String>();
-        ((List<String>)in).add("MyString");
-        out = Util.getStringPlusProperty(in);
+        out = Util.getStringPlusProperty(Arrays.asList("MyString"));
         assertEquals(1, out.length);
         assertEquals("MyString", out[0]);
-        
-        in = new Object();
-        out = Util.getStringPlusProperty(in);
+
+        out = Util.getStringPlusProperty(Arrays.asList(1));
+        assertEquals(0, out.length);
+
+        out = Util.getStringPlusProperty(new Object());
+        assertEquals(0, out.length);
+
+        out = Util.getStringPlusProperty(null);
         assertEquals(0, out.length);
     }
+
+    public void testRemoveEmpty() {
+        String[] out = Util.removeEmpty(new String[0]);
+        assertEquals(0, out.length);
+
+        out = Util.removeEmpty(new String[] {null});
+        assertEquals(0, out.length);
+
+        out = Util.removeEmpty(new String[] {""});
+        assertEquals(0, out.length);
+
+        out = Util.removeEmpty(new String[] {"hi"});
+        assertEquals(1, out.length);
+        assertEquals("hi", out[0]);
+
+        out = Util.removeEmpty(new String[] {"", "hi", null});
+        assertEquals(1, out.length);
+        assertEquals("hi", out[0]);
+
+        out = Util.removeEmpty(new String[] {"hi", null, "", ""});
+        assertEquals(1, out.length);
+        assertEquals("hi", out[0]);
+
+        out = Util.removeEmpty(new String[] {"", "hi", null, "", "", "bye", null});
+        assertEquals(2, out.length);
+        assertEquals("hi", out[0]);
+        assertEquals("bye", out[1]);
+    }
     
     public void testGetScopes() {
         IMocksControl c = EasyMock.createNiceControl();



Mime
View raw message