You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2019/10/28 10:34:34 UTC
[aries-rsa] branch master updated: ARIES-1936 - Switch zookeeper
starter to DS and mockito
This is an automated email from the ASF dual-hosted git repository.
cschneider pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
The following commit(s) were added to refs/heads/master by this push:
new 40ffcb3 ARIES-1936 - Switch zookeeper starter to DS and mockito
40ffcb3 is described below
commit 40ffcb37c5abb7090f61b90604426473d7c258a1
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Mon Oct 28 11:34:20 2019 +0100
ARIES-1936 - Switch zookeeper starter to DS and mockito
---
discovery/zookeeper/pom.xml | 14 +
.../aries/rsa/discovery/zookeeper/Activator.java | 10 +-
.../zookeeper/server/MyQuorumPeerMain.java | 43 +++
.../zookeeper/server/MyZooKeeperServerMain.java | 51 ++++
.../rsa/discovery/zookeeper/server/Utils.java | 108 --------
.../zookeeper/server/ZookeeperServer.java | 26 ++
.../zookeeper/server/ZookeeperStarter.java | 163 +++++------
.../discovery/zookeeper/DiscoveryDriverTest.java | 135 ---------
.../zookeeper/FindInZooKeeperCustomizerTest.java | 301 ---------------------
.../InterfaceDataMonitorListenerImplTest.java | 183 -------------
.../zookeeper/ZookeeperDiscoveryTest.java | 22 +-
.../ZookeeperEndpointRepositoryTest.java | 6 +-
.../zookeeper/server/ZookeeperStarterTest.java | 105 +++----
13 files changed, 272 insertions(+), 895 deletions(-)
diff --git a/discovery/zookeeper/pom.xml b/discovery/zookeeper/pom.xml
index 466c350..81fce9d 100644
--- a/discovery/zookeeper/pom.xml
+++ b/discovery/zookeeper/pom.xml
@@ -81,6 +81,20 @@
<artifactId>org.apache.aries.rsa.discovery.local</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Activator.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Activator.java
index 076159b..8003849 100644
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Activator.java
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Activator.java
@@ -21,7 +21,6 @@ package org.apache.aries.rsa.discovery.zookeeper;
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.aries.rsa.discovery.zookeeper.server.ZookeeperStarter;
import org.apache.zookeeper.server.ZooTrace;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -31,16 +30,13 @@ import org.osgi.service.cm.ManagedService;
public class Activator implements BundleActivator {
private static final String PID_DISCOVERY_ZOOKEEPER = "org.apache.aries.rsa.discovery.zookeeper";
- private static final String PID_ZOOKEEPER_SERVER = "org.apache.aries.rsa.discovery.zookeeper.server";
+
private ZooKeeperDiscovery zkd;
- private ZookeeperStarter zkStarter;
public synchronized void start(BundleContext bc) throws Exception {
zkd = new ZooKeeperDiscovery(bc);
bc.registerService(ManagedService.class, zkd, configProperties(PID_DISCOVERY_ZOOKEEPER));
- zkStarter = new ZookeeperStarter(bc);
- bc.registerService(ManagedService.class, zkStarter, configProperties(PID_ZOOKEEPER_SERVER));
}
public synchronized void stop(BundleContext bc) throws Exception {
@@ -48,10 +44,6 @@ public class Activator implements BundleActivator {
ZooTrace.getTextTraceLevel();
zkd.stop(true);
-
- if (zkStarter != null) {
- zkStarter.shutdown();
- }
}
private Dictionary<String, String> configProperties(String pid) {
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyQuorumPeerMain.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyQuorumPeerMain.java
new file mode 100644
index 0000000..9f078f9
--- /dev/null
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyQuorumPeerMain.java
@@ -0,0 +1,43 @@
+/**
+ * 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.aries.rsa.discovery.zookeeper.server;
+
+import java.io.IOException;
+
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.apache.zookeeper.server.quorum.QuorumPeerMain;
+
+class MyQuorumPeerMain extends QuorumPeerMain implements ZookeeperServer {
+
+ private QuorumPeerConfig config;
+
+ MyQuorumPeerMain(QuorumPeerConfig config) {
+ this.config = config;
+ }
+
+ public void startup() throws IOException {
+ runFromConfig(config);
+ }
+
+ public void shutdown() {
+ if (null != quorumPeer) {
+ quorumPeer.shutdown();
+ }
+ }
+}
\ No newline at end of file
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyZooKeeperServerMain.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyZooKeeperServerMain.java
new file mode 100644
index 0000000..33097b1
--- /dev/null
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/MyZooKeeperServerMain.java
@@ -0,0 +1,51 @@
+/**
+ * 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.aries.rsa.discovery.zookeeper.server;
+
+import java.io.IOException;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class MyZooKeeperServerMain extends ZooKeeperServerMain implements ZookeeperServer {
+ private static final Logger LOG = LoggerFactory.getLogger(ZookeeperStarter.class);
+
+ private QuorumPeerConfig config;
+
+ MyZooKeeperServerMain(QuorumPeerConfig config) {
+ this.config = config;
+ }
+
+ public void startup() throws IOException {
+ ServerConfig serverConfig = new ServerConfig();
+ serverConfig.readFrom(config);
+ runFromConfig(serverConfig);
+ }
+
+ public void shutdown() {
+ try {
+ super.shutdown();
+ } catch (Exception e) {
+ LOG.warn("Error shutting down ZooKeeper", e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/Utils.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/Utils.java
deleted file mode 100644
index fd7d151..0000000
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/Utils.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * 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.aries.rsa.discovery.zookeeper.server;
-
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * General purpose utility methods.
- */
-public final class Utils {
-
- private Utils() {
- // prevent instantiation
- }
-
- /**
- * Remove entries whose values are empty from the given dictionary.
- *
- * @param dict a dictionary
- */
- public static void removeEmptyValues(Dictionary<String, ?> dict) {
- List<String> keysToRemove = new ArrayList<>();
- Enumeration<String> keys = dict.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement();
- Object value = dict.get(key);
- if (value instanceof String && "".equals(value)) {
- keysToRemove.add(key);
- }
- }
- for (String key : keysToRemove) {
- dict.remove(key);
- }
- }
-
- /**
- * Puts the given key-value pair in the given dictionary if the key does not
- * already exist in it or if its existing value is null.
- *
- * @param dict a dictionary
- * @param key the key
- * @param value the default value to set
- */
- public static void setDefault(Dictionary<String, String> dict, String key, String value) {
- if (dict.get(key) == null) {
- dict.put(key, value);
- }
- }
-
- /**
- * Converts the given Dictionary to a Map.
- *
- * @param dict a dictionary
- * @param <K> the key type
- * @param <V> the value type
- * @return the converted map, or an empty map if the given dictionary is null
- */
- public static <K, V> Map<K, V> toMap(Dictionary<K, V> dict) {
- Map<K, V> map = new HashMap<>();
- if (dict != null) {
- Enumeration<K> keys = dict.keys();
- while (keys.hasMoreElements()) {
- K key = keys.nextElement();
- map.put(key, dict.get(key));
- }
- }
- return map;
- }
-
- /**
- * Converts a Dictionary into a Properties instance.
- *
- * @param dict a dictionary
- * @param <K> the key type
- * @param <V> the value type
- * @return the properties
- */
- public static <K, V> Properties toProperties(Dictionary<K, V> dict) {
- Properties props = new Properties();
- for (Enumeration<K> e = dict.keys(); e.hasMoreElements();) {
- K key = e.nextElement();
- props.put(key, dict.get(key));
- }
- return props;
- }
-}
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperServer.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperServer.java
new file mode 100644
index 0000000..663f9c2
--- /dev/null
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperServer.java
@@ -0,0 +1,26 @@
+/**
+ * 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.aries.rsa.discovery.zookeeper.server;
+
+import java.io.IOException;
+
+interface ZookeeperServer {
+ void startup() throws IOException;
+ void shutdown();
+}
\ No newline at end of file
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarter.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarter.java
index 520aa99..65341cd 100644
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarter.java
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarter.java
@@ -20,93 +20,72 @@ package org.apache.aries.rsa.discovery.zookeeper.server;
import java.io.File;
import java.io.IOException;
-import java.util.Dictionary;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
-import org.apache.zookeeper.server.ServerConfig;
-import org.apache.zookeeper.server.ZooKeeperServerMain;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
-import org.apache.zookeeper.server.quorum.QuorumPeerMain;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ZookeeperStarter implements org.osgi.service.cm.ManagedService {
+@Component( //
+ configurationPolicy = ConfigurationPolicy.REQUIRE, //
+ configurationPid = "org.apache.aries.rsa.discovery.zookeeper.server" //
+)
+public class ZookeeperStarter {
private static final Logger LOG = LoggerFactory.getLogger(ZookeeperStarter.class);
- protected ZookeeperServer main;
- private final BundleContext bundleContext;
+ protected ZookeeperServer server;
private Thread zkMainThread;
- private Map<String, ?> curConfiguration;
- public ZookeeperStarter(BundleContext ctx) {
- bundleContext = ctx;
- }
-
- public synchronized void shutdown() {
- if (main != null) {
- LOG.info("Shutting down ZooKeeper server");
- try {
- main.shutdown();
- if (zkMainThread != null) {
- zkMainThread.join();
- }
- } catch (Throwable e) {
- LOG.error(e.getMessage(), e);
- }
- main = null;
- zkMainThread = null;
+ @Activate
+ public synchronized void activate(BundleContext context, Map<String, String> config) throws ConfigurationException {
+ LOG.info("Activating zookeeper server with config: {}", config);
+ try {
+ QuorumPeerConfig peerConfig = parseConfig(config, context);
+ startFromConfig(peerConfig);
+ } catch (Exception th) {
+ LOG.warn("Problem applying configuration update: " + config, th);
}
}
- private void setDefaults(Dictionary<String, String> dict) throws IOException {
- Utils.removeEmptyValues(dict); // to avoid NumberFormatExceptions
- Utils.setDefault(dict, "tickTime", "2000");
- Utils.setDefault(dict, "initLimit", "10");
- Utils.setDefault(dict, "syncLimit", "5");
- Utils.setDefault(dict, "clientPort", "2181");
- Utils.setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath());
- }
-
- @SuppressWarnings("unchecked")
- public synchronized void updated(Dictionary<String, ?> dict) throws ConfigurationException {
- LOG.debug("Received configuration update for Zookeeper Server: " + dict);
+ @Deactivate
+ public synchronized void deactivate() {
+ if (server == null) {
+ return;
+ }
+ LOG.info("Shutting down ZooKeeper server");
try {
- if (dict != null) {
- setDefaults((Dictionary<String, String>)dict);
- }
- Map<String, ?> configMap = Utils.toMap(dict);
- if (!configMap.equals(curConfiguration)) { // only if something actually changed
- shutdown();
- curConfiguration = configMap;
- // config is null if it doesn't exist, is being deleted or has not yet been loaded
- // in which case we just stop running
- if (dict != null) {
- startFromConfig(parseConfig(dict));
- LOG.info("Applied configuration update: " + dict);
- }
+ server.shutdown();
+ if (zkMainThread != null) {
+ zkMainThread.join();
}
- } catch (Exception th) {
- LOG.error("Problem applying configuration update: " + dict, th);
+ } catch (Throwable e) {
+ LOG.error(e.getMessage(), e);
}
}
- private QuorumPeerConfig parseConfig(Dictionary<String, ?> dict) throws IOException, ConfigException {
- QuorumPeerConfig config = new QuorumPeerConfig();
- config.parseProperties(Utils.toProperties(dict));
- return config;
+ protected ZookeeperServer createServer(final QuorumPeerConfig config) {
+ int numServers = config.getServers().size();
+ return numServers > 1 ? new MyQuorumPeerMain(config) : new MyZooKeeperServerMain(config);
}
- protected void startFromConfig(final QuorumPeerConfig config) {
- int numServers = config.getServers().size();
- main = numServers > 1 ? new MyQuorumPeerMain(config) : new MyZooKeeperServerMain(config);
+ private void startFromConfig(final QuorumPeerConfig config) {
+ this.server = createServer(config);
zkMainThread = new Thread(new Runnable() {
public void run() {
try {
- main.startup();
+ server.startup();
} catch (Throwable e) {
LOG.error("Problem running ZooKeeper server.", e);
}
@@ -115,50 +94,34 @@ public class ZookeeperStarter implements org.osgi.service.cm.ManagedService {
zkMainThread.start();
}
- interface ZookeeperServer {
- void startup() throws IOException;
- void shutdown();
+ private QuorumPeerConfig parseConfig(Map<String, ?> config, BundleContext context) throws IOException, ConfigException {
+ Properties props = copyWithoutEmptyValues(config); // to avoid NumberFormatExceptions
+ String dataDir = new File(context.getDataFile(""), "zkdata").getCanonicalPath();
+ props.putIfAbsent("dataDir", dataDir);
+ props.putIfAbsent("tickTime", "2000");
+ props.putIfAbsent("initLimit", "10");
+ props.putIfAbsent("syncLimit", "5");
+ props.putIfAbsent("clientPort", "2181");
+ QuorumPeerConfig qconf = new QuorumPeerConfig();
+ qconf.parseProperties(props);
+ return qconf;
}
- static class MyQuorumPeerMain extends QuorumPeerMain implements ZookeeperServer {
-
- private QuorumPeerConfig config;
-
- MyQuorumPeerMain(QuorumPeerConfig config) {
- this.config = config;
- }
-
- public void startup() throws IOException {
- runFromConfig(config);
- }
-
- public void shutdown() {
- if (null != quorumPeer) {
- quorumPeer.shutdown();
+ /**
+ * Remove entries whose values are empty from the given dictionary.
+ *
+ * @param dict a dictionary
+ * @return
+ */
+ private static Properties copyWithoutEmptyValues(Map<String, ?> dict) {
+ Properties props = new Properties();
+ for (String key : dict.keySet()) {
+ Object value = dict.get(key);
+ if (!(value instanceof String && "".equals(value))) {
+ props.put(key, value);
}
}
+ return props;
}
- static class MyZooKeeperServerMain extends ZooKeeperServerMain implements ZookeeperServer {
-
- private QuorumPeerConfig config;
-
- MyZooKeeperServerMain(QuorumPeerConfig config) {
- this.config = config;
- }
-
- public void startup() throws IOException {
- ServerConfig serverConfig = new ServerConfig();
- serverConfig.readFrom(config);
- runFromConfig(serverConfig);
- }
-
- public void shutdown() {
- try {
- super.shutdown();
- } catch (Exception e) {
- LOG.error("Error shutting down ZooKeeper", e);
- }
- }
- }
}
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/DiscoveryDriverTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/DiscoveryDriverTest.java
deleted file mode 100644
index b0b187a..0000000
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/DiscoveryDriverTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * 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.aries.rsa.discovery.zookeeper;
-
-import junit.framework.TestCase;
-
-public class DiscoveryDriverTest extends TestCase {
-
- public void testDUMMY() {
- assertTrue(true);
- }
-
-// public void testDiscoveryDriver() throws Exception {
-// BundleContext bc = getDefaultBundleContext();
-// Dictionary<String, String> props = getDefaultProps();
-//
-// final StringBuilder sb = new StringBuilder();
-// DiscoveryDriver dd = new DiscoveryDriver(bc, props) {
-// @Override
-// ZooKeeper createZooKeeper() throws IOException {
-// sb.append(zkHost + ":" + zkPort);
-// ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
-// EasyMock.replay(zk);
-// return zk;
-// }
-// };
-// EasyMock.verify(bc);
-// assertEquals("somehost:1910", sb.toString());
-//
-// EasyMock.verify(dd.zooKeeper);
-// EasyMock.reset(dd.zooKeeper);
-// dd.zooKeeper.close();
-// EasyMock.expectLastCall();
-// EasyMock.replay(dd.zooKeeper);
-//
-// ServiceTracker st1 = EasyMock.createMock(ServiceTracker.class);
-// st1.close();
-// EasyMock.expectLastCall();
-// EasyMock.replay(st1);
-// ServiceTracker st2 = EasyMock.createMock(ServiceTracker.class);
-// st2.close();
-// EasyMock.expectLastCall();
-// EasyMock.replay(st2);
-//
-// dd.lookupTracker = st1;
-// dd.publicationTracker = st2;
-//
-// dd.destroy();
-// }
-//
-// private void expectServiceTrackerCalls(BundleContext bc, String objectClass)
-// throws InvalidSyntaxException {
-// Filter filter = EasyMock.createNiceMock(Filter.class);
-// EasyMock.replay(filter);
-//
-// EasyMock.expect(bc.createFilter("(objectClass=" + objectClass + ")"))
-// .andReturn(filter).anyTimes();
-// bc.addServiceListener((ServiceListener) EasyMock.anyObject(),
-// EasyMock.eq("(objectClass=" + objectClass + ")"));
-// EasyMock.expectLastCall().anyTimes();
-// EasyMock.expect(bc.getServiceReferences(objectClass, null))
-// .andReturn(new ServiceReference [0]).anyTimes();
-// }
-//
-// public void testProcessEvent() throws Exception {
-// DiscoveryDriver db = new DiscoveryDriver(getDefaultBundleContext(), getDefaultProps()) {
-// @Override
-// ZooKeeper createZooKeeper() throws IOException {
-// return null;
-// }
-// };
-//
-// FindInZooKeeperCustomizer fc = new FindInZooKeeperCustomizer(null, null);
-// List<InterfaceMonitor> l1 = new ArrayList<InterfaceMonitor>();
-// InterfaceMonitor dm1a = EasyMock.createMock(InterfaceMonitor.class);
-// dm1a.process();
-// EasyMock.expectLastCall();
-// EasyMock.replay(dm1a);
-// InterfaceMonitor dm1b = EasyMock.createMock(InterfaceMonitor.class);
-// dm1b.process();
-// EasyMock.expectLastCall();
-// EasyMock.replay(dm1b);
-// l1.add(dm1a);
-// l1.add(dm1b);
-//
-// List<InterfaceMonitor> l2 = new ArrayList<InterfaceMonitor>();
-// InterfaceMonitor dm2 = EasyMock.createMock(InterfaceMonitor.class);
-// dm2.process();
-// EasyMock.expectLastCall();
-// EasyMock.replay(dm2);
-// l2.add(dm2);
-//
-// fc.watchers.put(EasyMock.createMock(DiscoveredServiceTracker.class), l1);
-// fc.watchers.put(EasyMock.createMock(DiscoveredServiceTracker.class), l2);
-//
-// db.finderCustomizer = fc;
-// db.process(null);
-//
-// EasyMock.verify(dm1a);
-// EasyMock.verify(dm1b);
-// EasyMock.verify(dm2);
-// }
-//
-// private BundleContext getDefaultBundleContext() throws InvalidSyntaxException {
-// BundleContext bc = EasyMock.createMock(BundleContext.class);
-// expectServiceTrackerCalls(bc, ServicePublication.class.getName());
-// expectServiceTrackerCalls(bc, DiscoveredServiceTracker.class.getName());
-// EasyMock.replay(bc);
-// return bc;
-// }
-//
-// private Dictionary<String, String> getDefaultProps() {
-// Dictionary<String, String> props = new Hashtable<String, String>();
-// props.put("zookeeper.host", "somehost");
-// props.put("zookeeper.port", "1910");
-// props.put("zookeeper.timeout", "1500");
-// return props;
-// }
-}
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/FindInZooKeeperCustomizerTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/FindInZooKeeperCustomizerTest.java
deleted file mode 100644
index a0a828a..0000000
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/FindInZooKeeperCustomizerTest.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/**
- * 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.aries.rsa.discovery.zookeeper;
-
-import junit.framework.TestCase;
-
-public class FindInZooKeeperCustomizerTest extends TestCase {
-
- public void testDUMMY() {
- assertTrue(true);
- }
-
-// public void testAddingServiceInterface() {
-// DiscoveredServiceTracker dst = new DiscoveredServiceTracker() {
-// public void serviceChanged(DiscoveredServiceNotification dsn) {}
-// };
-//
-// ServiceReference sr = EasyMock.createMock(ServiceReference.class);
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(Collections.singleton(String.class.getName()));
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(null);
-// EasyMock.replay(sr);
-//
-// DiscoveredServiceTracker dst2 = new DiscoveredServiceTracker() {
-// public void serviceChanged(DiscoveredServiceNotification dsn) {}
-// };
-//
-// ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
-// EasyMock.expect(sr2.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(Arrays.asList(Integer.class.getName(), Comparable.class.getName()));
-// EasyMock.expect(sr2.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(null);
-// EasyMock.replay(sr2);
-//
-// BundleContext bc = EasyMock.createMock(BundleContext.class);
-// EasyMock.expect(bc.getService(sr)).andReturn(dst);
-// EasyMock.expect(bc.getService(sr2)).andReturn(dst2);
-// EasyMock.replay(bc);
-//
-// ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
-// zkExpectExists(zk, String.class.getName());
-// zkExpectExists(zk, Integer.class.getName());
-// zkExpectExists(zk, Comparable.class.getName());
-// EasyMock.expectLastCall();
-// EasyMock.replay(zk);
-//
-// FindInZooKeeperCustomizer fc = new FindInZooKeeperCustomizer(bc, zk);
-//
-// // ---------------------------------------------------------------
-// // Test the addingService APIs
-// // ---------------------------------------------------------------
-//
-// assertEquals("Precondition failed", 0, fc.watchers.size());
-// fc.addingService(sr);
-// assertEquals(1, fc.watchers.size());
-//
-// DiscoveredServiceTracker key = fc.watchers.keySet().iterator().next();
-// assertSame(dst, key);
-// List<InterfaceMonitor> dmList = fc.watchers.get(key);
-// assertEquals(1, dmList.size());
-// InterfaceMonitor dm = dmList.iterator().next();
-// assertNotNull(dm.listener);
-// assertSame(zk, dm.zookeeper);
-// assertEquals(Utils.getZooKeeperPath(String.class.getName()), dm.znode);
-//
-// assertEquals("Precondition failed", 1, fc.watchers.size());
-// fc.addingService(sr2);
-// assertEquals(2, fc.watchers.size());
-//
-// assertTrue(fc.watchers.containsKey(dst));
-// assertTrue(fc.watchers.containsKey(dst2));
-// assertEquals(dmList, fc.watchers.get(dst));
-// List<InterfaceMonitor> dmList2 = fc.watchers.get(dst2);
-// assertEquals(2, dmList2.size());
-//
-// Set<String> actual = new HashSet<String>();
-// for (InterfaceMonitor im : dmList2) {
-// actual.add(im.znode);
-// }
-// Set<String> expected = new HashSet<String>(Arrays.asList(
-// Utils.getZooKeeperPath(Integer.class.getName()),
-// Utils.getZooKeeperPath(Comparable.class.getName())));
-// assertEquals(expected, actual);
-//
-// EasyMock.verify(zk);
-//
-// // ---------------------------------------------------------------
-// // Test the modifiedService APIs
-// // ---------------------------------------------------------------
-// EasyMock.reset(zk);
-// zkExpectExists(zk, List.class.getName());
-// EasyMock.replay(zk);
-//
-// EasyMock.reset(sr);
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(Collections.singleton(List.class.getName()));
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(null);
-// EasyMock.replay(sr);
-//
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-// fc.modifiedService(sr, dst);
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-//
-// assertTrue(fc.watchers.containsKey(dst));
-// assertTrue(fc.watchers.containsKey(dst2));
-// assertEquals(dmList2, fc.watchers.get(dst2));
-// List<InterfaceMonitor> dmList3 = fc.watchers.get(dst);
-// assertEquals(1, dmList3.size());
-// assertEquals(Utils.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode);
-//
-// EasyMock.verify(zk);
-//
-// // ---------------------------------------------------------------
-// // Test the removedService APIs
-// // ---------------------------------------------------------------
-// EasyMock.reset(zk);
-// EasyMock.replay(zk);
-//
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-// fc.removedService(sr2, dst2);
-// assertEquals("Precondition failed", 1, fc.watchers.size());
-//
-// assertEquals(dmList3, fc.watchers.get(dst));
-// assertNull(fc.watchers.get(dst2));
-//
-// EasyMock.verify(zk);
-// }
-//
-// public void testAddingServiceFilter() {
-// DiscoveredServiceTracker dst = new DiscoveredServiceTracker() {
-// public void serviceChanged(DiscoveredServiceNotification dsn) {}
-// };
-//
-// ServiceReference sr = EasyMock.createMock(ServiceReference.class);
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(null);
-// Set<String> stringFilter = Collections.singleton("(objectClass=java.lang.String)");
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(stringFilter);
-// EasyMock.replay(sr);
-//
-// DiscoveredServiceTracker dst2 = new DiscoveredServiceTracker() {
-// public void serviceChanged(DiscoveredServiceNotification dsn) {}
-// };
-//
-// ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
-// EasyMock.expect(sr2.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(null);
-// List<String> combinedFilter =
-// Arrays.asList("(objectClass=java.lang.Integer)", "(objectClass=java.lang.Comparable)");
-// EasyMock.expect(sr2.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(combinedFilter);
-// EasyMock.replay(sr2);
-//
-// BundleContext bc = EasyMock.createMock(BundleContext.class);
-// EasyMock.expect(bc.getService(sr)).andReturn(dst);
-// EasyMock.expect(bc.getService(sr2)).andReturn(dst2);
-// EasyMock.replay(bc);
-//
-// ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
-// zkExpectExists(zk, String.class.getName());
-// zkExpectExists(zk, Integer.class.getName());
-// zkExpectExists(zk, Comparable.class.getName());
-// EasyMock.expectLastCall();
-// EasyMock.replay(zk);
-//
-// FindInZooKeeperCustomizer fc = new FindInZooKeeperCustomizer(bc, zk);
-//
-// // ---------------------------------------------------------------
-// // Test the addingService APIs
-// // ---------------------------------------------------------------
-//
-// assertEquals("Precondition failed", 0, fc.watchers.size());
-// fc.addingService(sr);
-// assertEquals(1, fc.watchers.size());
-//
-// DiscoveredServiceTracker key = fc.watchers.keySet().iterator().next();
-// assertSame(dst, key);
-// List<InterfaceMonitor> dmList = fc.watchers.get(key);
-// assertEquals(1, dmList.size());
-// InterfaceMonitor dm = dmList.iterator().next();
-// assertNotNull(dm.listener);
-// assertSame(zk, dm.zookeeper);
-// assertEquals(Utils.getZooKeeperPath(String.class.getName()), dm.znode);
-//
-// assertEquals("Precondition failed", 1, fc.watchers.size());
-// fc.addingService(sr2);
-// assertEquals(2, fc.watchers.size());
-//
-// assertTrue(fc.watchers.containsKey(dst));
-// assertTrue(fc.watchers.containsKey(dst2));
-// assertEquals(dmList, fc.watchers.get(dst));
-// List<InterfaceMonitor> dmList2 = fc.watchers.get(dst2);
-// assertEquals(2, dmList2.size());
-// Set<String> actual = new HashSet<String>();
-// for (InterfaceMonitor im : dmList2) {
-// actual.add(im.znode);
-// }
-// Set<String> expected = new HashSet<String>(Arrays.asList(
-// Utils.getZooKeeperPath(Integer.class.getName()),
-// Utils.getZooKeeperPath(Comparable.class.getName())));
-// assertEquals(expected, actual);
-//
-// EasyMock.verify(zk);
-//
-// // ---------------------------------------------------------------
-// // Test the modifiedService APIs
-// // ---------------------------------------------------------------
-// EasyMock.reset(zk);
-// zkExpectExists(zk, List.class.getName());
-// EasyMock.replay(zk);
-//
-// EasyMock.reset(sr);
-// Set<String> listFilter = Collections.singleton("(objectClass=java.util.List)");
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.INTERFACE_MATCH_CRITERIA))
-// .andReturn(null);
-// EasyMock.expect(sr.getProperty(DiscoveredServiceTracker.FILTER_MATCH_CRITERIA))
-// .andReturn(listFilter);
-// EasyMock.replay(sr);
-//
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-// fc.modifiedService(sr, dst);
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-//
-// assertTrue(fc.watchers.containsKey(dst));
-// assertTrue(fc.watchers.containsKey(dst2));
-// assertEquals(dmList2, fc.watchers.get(dst2));
-// List<InterfaceMonitor> dmList3 = fc.watchers.get(dst);
-// assertEquals(1, dmList3.size());
-// assertEquals(Utils.getZooKeeperPath(List.class.getName()), dmList3.iterator().next().znode);
-//
-// EasyMock.verify(zk);
-//
-// // ---------------------------------------------------------------
-// // Test the removedService APIs
-// // ---------------------------------------------------------------
-// EasyMock.reset(zk);
-// EasyMock.replay(zk);
-//
-// assertEquals("Precondition failed", 2, fc.watchers.size());
-// fc.removedService(sr2, dst2);
-// assertEquals("Precondition failed", 1, fc.watchers.size());
-//
-// assertEquals(dmList3, fc.watchers.get(dst));
-// assertNull(fc.watchers.get(dst2));
-//
-// EasyMock.verify(zk);
-// }
-//
-// public void testGetInterfacesFromFilter() {
-// testGetInterfacesFromFilter("objectClass=org.apache_2.Some$FunnyClass",
-// "org.apache_2.Some$FunnyClass");
-// testGetInterfacesFromFilter("(&(a=b)(objectClass = org.acme.Q)",
-// "org.acme.Q");
-// testGetInterfacesFromFilter("(&(objectClassIdentifier=b)(objectClass = org.acme.Q)",
-// "org.acme.Q");
-// testGetInterfacesFromFilter("(|(OBJECTCLASS= X )(objectclass = Y)",
-// "X", "Y");
-// testGetInterfacesFromFilter(new String[] {"(objectClass=X)", "(objectClass=Y)"},
-// "X", "Y");
-// }
-//
-// private void testGetInterfacesFromFilter(String filter, String ... interfaces) {
-// testGetInterfacesFromFilter(new String[] {filter}, interfaces);
-// }
-//
-// private void testGetInterfacesFromFilter(String[] filters, String ... interfaces) {
-// FindInZooKeeperCustomizer.getInterfacesFromFilter(Arrays.asList(filters));
-// }
-//
-// private void zkExpectExists(ZooKeeper zk, String className) {
-// zk.exists(EasyMock.eq(Utils.getZooKeeperPath(className)),
-// (Watcher) EasyMock.anyObject(),
-// (StatCallback) EasyMock.anyObject(), EasyMock.isNull());
-// EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
-// public Object answer() throws Throwable {
-// assertEquals(EasyMock.getCurrentArguments()[1],
-// EasyMock.getCurrentArguments()[2]);
-// return null;
-// }
-// });
-// }
-}
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
deleted file mode 100644
index bac4f78..0000000
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * 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.aries.rsa.discovery.zookeeper;
-
-import junit.framework.TestCase;
-
-public class InterfaceDataMonitorListenerImplTest extends TestCase {
-
- public void testDUMMY() {
- assertTrue(true);
- }
-
-// public void testChange() throws Exception {
-// final List<DiscoveredServiceNotification> dsnCallbacks = new ArrayList<DiscoveredServiceNotification>();
-// DiscoveredServiceTracker dst = new DiscoveredServiceTracker() {
-// public void serviceChanged(DiscoveredServiceNotification dsn) {
-// dsnCallbacks.add(dsn);
-// }
-// };
-//
-// //----------------------------------------------------------------
-// // Test DiscoveredServiceNotification.AVAILABLE
-// //----------------------------------------------------------------
-// Properties initial = new Properties();
-// initial.put("a", "b");
-// initial.put(ServicePublication.ENDPOINT_LOCATION, "http://somehost:12345/some/context");
-// ByteArrayOutputStream propBytes = new ByteArrayOutputStream();
-// initial.store(propBytes, "");
-//
-// ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
-// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false))
-// .andReturn(Arrays.asList("x#y#z"));
-// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null))
-// .andReturn(propBytes.toByteArray());
-// EasyMock.replay(zk);
-//
-// InterfaceDataMonitorListenerImpl dml = new InterfaceDataMonitorListenerImpl(zk, String.class.getName(), dst);
-//
-// assertEquals("Precondition failed", 0, dsnCallbacks.size());
-// dml.change();
-// assertEquals(1, dsnCallbacks.size());
-// DiscoveredServiceNotification dsn = dsnCallbacks.iterator().next();
-// assertEquals(Collections.singleton(String.class.getName()), dsn.getInterfaces());
-// assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
-// assertEquals(0, dsn.getFilters().size());
-// ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
-// assertEquals(Collections.singleton(String.class.getName()), sed.getProvidedInterfaces());
-//
-// Properties expected = new Properties();
-// expected.load(new ByteArrayInputStream(propBytes.toByteArray()));
-// expected.put("service.exported.configs", "org.apache.cxf.ws");
-// expected.put("org.apache.cxf.ws.address", "http://somehost:12345/some/context");
-//
-// assertEquals(expected, sed.getProperties());
-// EasyMock.verify(zk);
-//
-// // Again with the same data
-// EasyMock.reset(zk);
-// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false))
-// .andReturn(Arrays.asList("x#y#z"));
-// EasyMock.expect(zk.getData(Utils.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");
-// modified.put(ServicePublication.ENDPOINT_LOCATION, "http://somehost:999/some/context");
-// modified.put("service.exported.configs", "org.apache.cxf.rs");
-// ByteArrayOutputStream modBytes = new ByteArrayOutputStream();
-// modified.store(modBytes, "");
-//
-// EasyMock.reset(zk);
-// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false))
-// .andReturn(Arrays.asList("x#y#z"));
-// EasyMock.expect(zk.getData(Utils.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.MODIFIED2
-// //----------------------------------------------------------------
-// Properties modified2 = new Properties();
-// modified2.put("c", "d2");
-// modified2.put(ServicePublication.ENDPOINT_LOCATION, "http://somehost:112/some/context");
-// modified2.put("service.exported.configs", "org.apache.cxf.ws");
-// modified2.put("org.apache.cxf.ws.address", "http://somewhereelse/123");
-// ByteArrayOutputStream modBytes2 = new ByteArrayOutputStream();
-// modified2.store(modBytes2, "");
-//
-// EasyMock.reset(zk);
-// EasyMock.expect(zk.getChildren(Utils.getZooKeeperPath(String.class.getName()), false))
-// .andReturn(Arrays.asList("x#y#z"));
-// EasyMock.expect(zk.getData(Utils.getZooKeeperPath(String.class.getName()) + "/x#y#z", false, null))
-// .andReturn(modBytes2.toByteArray());
-// 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.MODIFIED, dsn3.getType());
-// assertEquals(0, dsn3.getFilters().size());
-// ServiceEndpointDescription sed3 = dsn3.getServiceEndpointDescription();
-// assertEquals(Collections.singleton(String.class.getName()), sed3.getProvidedInterfaces());
-// assertEquals(modified2, sed3.getProperties());
-//
-// EasyMock.verify(zk);
-// //----------------------------------------------------------------
-// // Test DiscoveredServiceNotification.UNAVAILABLE
-// //----------------------------------------------------------------
-// EasyMock.reset(zk);
-// EasyMock.expect(zk.getChildren(Utils.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 dsn4 = dsnCallbacks.iterator().next();
-// assertEquals(Collections.singleton(String.class.getName()), dsn4.getInterfaces());
-// assertEquals(DiscoveredServiceNotification.UNAVAILABLE, dsn4.getType());
-// assertEquals(0, dsn4.getFilters().size());
-// ServiceEndpointDescription sed4 = dsn4.getServiceEndpointDescription();
-// assertEquals(Collections.singleton(String.class.getName()), sed4.getProvidedInterfaces());
-// assertEquals(modified2, sed4.getProperties());
-//
-// EasyMock.verify(zk);
-//
-// // Try the same again...
-// EasyMock.reset(zk);
-// EasyMock.expect(zk.getChildren(Utils.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);
-// }
-}
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/ZookeeperDiscoveryTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/ZookeeperDiscoveryTest.java
index e00e3c7..96a3028 100644
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/ZookeeperDiscoveryTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/ZookeeperDiscoveryTest.java
@@ -21,23 +21,27 @@ package org.apache.aries.rsa.discovery.zookeeper;
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.aries.rsa.discovery.zookeeper.ZooKeeperDiscovery;
import org.apache.zookeeper.ZooKeeper;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Assert;
+import org.junit.Rule;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
-
public class ZookeeperDiscoveryTest {
+ @Rule
+ public MockitoRule rule = MockitoJUnit.rule();
+
+ @Mock
+ BundleContext bc;
+
@Test
public void testDefaults() throws ConfigurationException {
- IMocksControl c = EasyMock.createControl();
- BundleContext bctx = c.createMock(BundleContext.class);
- ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
+ ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bc) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("localhost", host);
@@ -53,9 +57,7 @@ public class ZookeeperDiscoveryTest {
@Test
public void testConfig() throws ConfigurationException {
- IMocksControl c = EasyMock.createControl();
- BundleContext bctx = c.createMock(BundleContext.class);
- ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
+ ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bc) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("myhost", host);
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepositoryTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepositoryTest.java
index 813fd17..00d1a84 100644
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepositoryTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepositoryTest.java
@@ -117,8 +117,10 @@ public class ZookeeperEndpointRepositoryTest {
repository.remove(endpoint);
assertThat(sem.tryAcquire(1000, TimeUnit.SECONDS), equalTo(true));
- assertThat(events.get(0), samePropertyValuesAs(new EndpointEvent(EndpointEvent.ADDED, endpoint)));
- assertThat(events.get(1), samePropertyValuesAs(new EndpointEvent(EndpointEvent.REMOVED, endpoint)));
+ assertThat(events.get(0).getType(), equalTo(EndpointEvent.ADDED));
+ assertThat(events.get(1).getType(), equalTo(EndpointEvent.REMOVED));
+ assertThat(events.get(0).getEndpoint(), equalTo(endpoint));
+ assertThat(events.get(1).getEndpoint(), equalTo(endpoint));
repository.close();
}
diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarterTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarterTest.java
index 8a03861..a4e3fbb 100644
--- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarterTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/server/ZookeeperStarterTest.java
@@ -18,65 +18,76 @@
*/
package org.apache.aries.rsa.discovery.zookeeper.server;
-import java.io.File;
-import java.util.Dictionary;
-import java.util.Hashtable;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.after;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-import junit.framework.TestCase;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
-import org.apache.aries.rsa.discovery.zookeeper.server.ZookeeperStarter;
-import org.apache.aries.rsa.discovery.zookeeper.server.ZookeeperStarter.MyZooKeeperServerMain;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.osgi.framework.BundleContext;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.replay;
-import static org.easymock.classextension.EasyMock.verify;
+public class ZookeeperStarterTest {
+
+ @Rule
+ public MockitoRule mockito = MockitoJUnit.rule();
+
+ @Mock
+ BundleContext bc;
+
+ @Mock
+ ZookeeperServer server;
+
+ private static QuorumPeerConfig config;
+
+ @InjectMocks
+ ZookeeperStarter starter = new ZookeeperStarter() {
-public class ZookeeperStarterTest extends TestCase {
+ @Override
+ protected ZookeeperServer createServer(QuorumPeerConfig config) {
+ ZookeeperStarterTest.config = config;
+ return server;
+ }
+ };
+ @Captor
+ ArgumentCaptor<QuorumPeerConfig> configCaptor;
+
+ @Test
public void testUpdateConfig() throws Exception {
final File tempDir = new File("target");
- IMocksControl control = EasyMock.createControl();
- BundleContext bc = control.createMock(BundleContext.class);
- expect(bc.getDataFile("")).andReturn(tempDir);
- final MyZooKeeperServerMain mockServer = control.createMock(MyZooKeeperServerMain.class);
- control.replay();
-
- ZookeeperStarter starter = new ZookeeperStarter(bc) {
- @Override
- protected void startFromConfig(QuorumPeerConfig config) {
- assertEquals(1234, config.getClientPortAddress().getPort());
- assertTrue(config.getDataDir().contains(tempDir + File.separator + "zkdata"));
- assertEquals(2000, config.getTickTime());
- assertEquals(10, config.getInitLimit());
- assertEquals(5, config.getSyncLimit());
- this.main = mockServer;
- }
- };
- Dictionary<String, Object> props = new Hashtable<>();
+ when(bc.getDataFile("")).thenReturn(tempDir);
+
+ Map<String, String> props = new HashMap<>();
props.put("clientPort", "1234");
- starter.updated(props);
- assertNotNull(starter.main);
-
- control.verify();
- }
+ starter.activate(bc, props);
- public void testRemoveConfiguration() throws Exception {
- BundleContext bc = EasyMock.createMock(BundleContext.class);
- MyZooKeeperServerMain zkServer = EasyMock.createMock(MyZooKeeperServerMain.class);
- zkServer.shutdown();
- EasyMock.expectLastCall();
+ verify(server, after(1000)).startup();
+ verifyConfig(tempDir);
- replay(zkServer);
-
- ZookeeperStarter starter = new ZookeeperStarter(bc);
- starter.main = zkServer;
- starter.updated(null);
+ starter.deactivate();
+
+ verify(server).shutdown();
+ }
- verify(zkServer);
- assertNull("main should be null", starter.main);
+ private void verifyConfig(final File tempDir) {
+ assertEquals(1234, config.getClientPortAddress().getPort());
+ assertTrue(config.getDataDir().contains(tempDir + File.separator + "zkdata"));
+ assertEquals(2000, config.getTickTime());
+ assertEquals(10, config.getInitLimit());
+ assertEquals(5, config.getSyncLimit());
}
+
}