You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2012/10/31 13:07:02 UTC
svn commit: r1404107 - in
/cxf/dosgi/trunk/discovery/distributed/zookeeper-server: ./
src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/
src/main/resources/ src/main/resources/OSGI-INF/
src/main/resources/OSGI-INF/metatype/ src/test/java/or...
Author: cschneider
Date: Wed Oct 31 12:07:02 2012
New Revision: 1404107
URL: http://svn.apache.org/viewvc?rev=1404107&view=rev
Log:
DOSGI-136 Refactoring zookeeper starter, improved error handling, metatype configs
Added:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
- copied, changed from r1402482, cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedService.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml (with props)
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java
- copied, changed from r1402482, cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedServiceTest.java
Removed:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedService.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ActivatorTest.java
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedServiceTest.java
Modified:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml?rev=1404107&r1=1404106&r2=1404107&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/pom.xml Wed Oct 31 12:07:02 2012
@@ -103,7 +103,7 @@
<configuration>
<instructions>
<Bundle-Name>ZooKeeper server control bundle</Bundle-Name>
- <Bundle-Description>This bundle can run the ZooKeeper server in an OSGi Framework</Bundle-Description>
+ <Bundle-Description>Runs the ZooKeeper server</Bundle-Description>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.apache.cxf.dosgi.discovery.zookeeper.server.Activator</Bundle-Activator>
<Import-Package>*</Import-Package>
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java?rev=1404107&r1=1404106&r2=1404107&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/Activator.java Wed Oct 31 12:07:02 2012
@@ -17,33 +17,26 @@
*/
package org.apache.cxf.dosgi.discovery.zookeeper.server;
+import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.Constants;
public class Activator implements BundleActivator {
- ManagedService ms;
- ServiceRegistration reg;
+ ZookeeperStarter zkStarter;
public void start(BundleContext context) throws Exception {
- ms = new ManagedService(context);
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- ms.setDefaults(props);
-
- // cannot use the org.osgi.service.cm.ManagedService class object directly from
- // Activator because we have an optional dependency on it...
- reg = context.registerService(org.osgi.service.cm.ManagedService.class.getName(), ms, props);
- ms.setRegistration(reg);
+ zkStarter = new ZookeeperStarter(context);
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper.server");
+ context.registerService(org.osgi.service.cm.ManagedService.class.getName(), zkStarter, props );
}
public void stop(BundleContext context) throws Exception {
- if (reg != null) {
- reg.unregister();
- }
- if (ms != null) {
- ms.shutdown();
+ if (zkStarter != null) {
+ zkStarter.shutdown();
}
}
}
Copied: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java (from r1402482, cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedService.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java?p2=cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java&p1=cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedService.java&r1=1402482&r2=1404107&rev=1404107&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedService.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java Wed Oct 31 12:07:02 2012
@@ -23,129 +23,109 @@ import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Properties;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
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.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
-public class ManagedService implements org.osgi.service.cm.ManagedService {
- private static final Logger LOG = Logger.getLogger(ManagedService.class);
+public class ZookeeperStarter implements org.osgi.service.cm.ManagedService {
+ private static final Logger LOG = Logger.getLogger(ZookeeperStarter.class);
private final BundleContext bundleContext;
- ServiceRegistration serviceRegistration;
- MyZooKeeperServerMain main;
- Thread zkMainThread;
-
- public ManagedService(BundleContext ctx) {
+ protected MyZooKeeperServerMain main;
+ private Thread zkMainThread;
+
+ public ZookeeperStarter(BundleContext ctx) {
bundleContext = ctx;
}
-
- public synchronized void shutdown() {
+
+ synchronized void shutdown() {
if (main != null) {
LOG.info("Shutting down ZooKeeper server");
- main.shutdown();
try {
- zkMainThread.join();
- } catch (InterruptedException e) {
- // ignore
+ main.shutdown();
+ if (zkMainThread != null) {
+ zkMainThread.join();
+ }
+ } catch (Throwable e) {
+ LOG.log(Level.ERROR, e.getMessage(), e);
}
main = null;
zkMainThread = null;
}
}
-
- @SuppressWarnings("unchecked")
+
+ @SuppressWarnings("rawtypes")
public void setDefaults(Dictionary dict) throws IOException {
- setDefault(dict, "tickTime", "2000");
+ setDefault(dict, "tickTime", "2000");
setDefault(dict, "initLimit", "10");
setDefault(dict, "syncLimit", "5");
- setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath());
- setDefault(dict, Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper.server");
+ setDefault(dict, "clientPort", "2181");
+ setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath());
}
-
- @SuppressWarnings("unchecked")
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private void setDefault(Dictionary dict, String key, String value) {
if (dict.get(key) == null) {
dict.put(key, value);
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public synchronized void updated(Dictionary dict) throws ConfigurationException {
+ shutdown();
if (dict == null) {
- shutdown();
return;
}
-
- if (main != null) {
- // stop the current instance
- shutdown();
- // then reconfigure and start again.
- }
-
- if (dict.get("clientPort") == null) {
- LOG.info("Ignoring configuration update because required property 'clientPort' isn't set.");
- return;
+ try {
+ setDefaults(dict);
+ QuorumPeerConfig config = parseConfig(dict);
+ startFromConfig(config);
+ LOG.info("Applied configuration update :" + dict);
+ } catch (Exception th) {
+ LOG.error("Problem applying configuration update: " + dict, th);
}
-
+ }
+
+ @SuppressWarnings("rawtypes")
+ private QuorumPeerConfig parseConfig(Dictionary dict) throws IOException, ConfigException {
Properties props = new Properties();
- for (Enumeration e = dict.keys(); e.hasMoreElements(); ) {
+ for (Enumeration e = dict.keys(); e.hasMoreElements();) {
Object key = e.nextElement();
props.put(key, dict.get(key));
}
-
- try {
- setDefaults(props);
- if (serviceRegistration != null) {
- serviceRegistration.setProperties(props);
- }
-
- QuorumPeerConfig config = new QuorumPeerConfig();
- config.parseProperties(props);
- final ServerConfig serverConfig = new ServerConfig();
- serverConfig.readFrom(config);
-
- main = getZooKeeperMain();
- zkMainThread = new Thread(new Runnable() {
- public void run() {
- try {
- main.runFromConfig(serverConfig);
- } catch (IOException e) {
- LOG.error("Problem running ZooKeeper server.", e);
- }
- }
- });
- startThread();
-
- LOG.info("Applied configuration update :" + props);
- } catch (Exception th) {
- LOG.error("Problem applying configuration update: " + props, th);
- }
+ QuorumPeerConfig config = new QuorumPeerConfig();
+ config.parseProperties(props);
+ return config;
}
- // Isolated for testing
- void startThread() {
+ protected void startFromConfig(QuorumPeerConfig config) throws IOException, InterruptedException {
+ final ServerConfig serverConfig = new ServerConfig();
+ serverConfig.readFrom(config);
+
+ main = new MyZooKeeperServerMain();
+ zkMainThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ main.runFromConfig(serverConfig);
+ } catch (Throwable e) {
+ LOG.error("Problem running ZooKeeper server.", e);
+ }
+ }
+ });
zkMainThread.start();
}
- // Isolated for testing
- MyZooKeeperServerMain getZooKeeperMain() {
- return new MyZooKeeperServerMain();
- }
-
- public void setRegistration(ServiceRegistration reg) {
- serviceRegistration = reg;
- }
-
+ // Make the shutdown accessible from here
static class MyZooKeeperServerMain extends ZooKeeperServerMain {
@Override
protected void shutdown() {
super.shutdown();
- // Make the shutdown accessible from here.
}
}
+
}
Added: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml?rev=1404107&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml (added)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml Wed Oct 31 12:07:02 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<MetaData xmlns="http://www.osgi.org/xmlns/metadata/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/metadata/v1.0.0 http://www.osgi.org/xmlns/metatype/v1.1.0/metatype.xsd
+ ">
+ <OCD description="" name="Zookeeper server config" id="org.apache.cxf.dosgi.discovery.zookeeper.server">
+ <AD id="clientPort" required="false" type="String" default="2181" description=""/>
+ <AD id="tickTime" required="false" type="String" default="2000" description=""/>
+ <AD id="initLimit" required="false" type="String" default="10" description=""/>
+ <AD id="syncLimit" required="false" type="String" default="5" description=""/>
+ </OCD>
+ <Designate pid="org.apache.cxf.dosgi.discovery.zookeeper.server">
+ <Object ocdref="org.apache.cxf.dosgi.discovery.zookeeper.server"/>
+ </Designate>
+</MetaData>
\ No newline at end of file
Propchange: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/resources/OSGI-INF/metatype/zookeeper.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java (from r1402482, cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedServiceTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java?p2=cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java&p1=cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedServiceTest.java&r1=1402482&r2=1404107&rev=1404107&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ManagedServiceTest.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarterTest.java Wed Oct 31 12:07:02 2012
@@ -17,173 +17,66 @@
*/
package org.apache.cxf.dosgi.discovery.zookeeper.server;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
import java.io.File;
-import java.util.Dictionary;
+import java.io.IOException;
import java.util.Hashtable;
import junit.framework.TestCase;
-import org.apache.cxf.dosgi.discovery.zookeeper.server.ManagedService.MyZooKeeperServerMain;
-import org.apache.zookeeper.ZooKeeperMain;
-import org.apache.zookeeper.server.ServerConfig;
-import org.easymock.IAnswer;
+import org.apache.cxf.dosgi.discovery.zookeeper.server.ZookeeperStarter.MyZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
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.cm.ConfigurationException;
-public class ManagedServiceTest extends TestCase {
- public void testManagedService() throws Exception {
+public class ZookeeperStarterTest extends TestCase {
+ public void testUpdateConfig() throws Exception {
final File tempDir = new File(System.getProperty("java.io.tmpdir"));
-
- final ManagedService.MyZooKeeperServerMain zkMain =
- EasyMock.createMock(ManagedService.MyZooKeeperServerMain.class);
- zkMain.runFromConfig((ServerConfig) EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- ServerConfig sc = (ServerConfig) EasyMock.getCurrentArguments()[0];
- assertEquals(new File(tempDir, "zkdata").getCanonicalFile().toString(),
- sc.getDataDir());
- assertEquals(1234, sc.getClientPortAddress().getPort());
- assertEquals(2000, sc.getTickTime());
- return null;
- }
- });
- EasyMock.replay(zkMain);
-
- BundleContext bc = EasyMock.createMock(BundleContext.class);
- EasyMock.expect(bc.getDataFile("")).andReturn(tempDir);
- EasyMock.replay(bc);
-
- final StringBuilder threadStatus = new StringBuilder();
- ManagedService ms = new ManagedService(bc) {
- @Override
- ManagedService.MyZooKeeperServerMain getZooKeeperMain() {
- return zkMain;
+ 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) throws IOException, InterruptedException {
+ assertEquals(1234, config.getClientPortAddress().getPort());
+ assertEquals(tempDir + File.separator + "zkdata", config.getDataDir());
+ assertEquals(2000, config.getTickTime());
+ assertEquals(10, config.getInitLimit());
+ assertEquals(5, config.getSyncLimit());
+ this.main = mockServer;
}
- @Override
- void startThread() {
- threadStatus.append("started");
- }
};
-
- ServiceRegistration sreg = EasyMock.createMock(ServiceRegistration.class);
- final Hashtable<String, Object> expected = new Hashtable<String, Object>();
- expected.put("tickTime", "2000");
- expected.put("initLimit", "10");
- expected.put("syncLimit", "5");
- expected.put("dataDir", new File(tempDir, "zkdata").getCanonicalFile().toString());
- expected.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper.server");
- expected.put("clientPort", "1234");
- sreg.setProperties(expected);
- EasyMock.expectLastCall();
- EasyMock.replay(sreg);
- ms.setRegistration(sreg);
-
Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper.server");
props.put("clientPort", "1234");
-
- ms.updated(props);
- EasyMock.verify(sreg);
+ starter.updated(props);
+ assertNotNull(starter.main);
- assertEquals("started", threadStatus.toString());
- ms.zkMainThread.run();
-
- EasyMock.verify(zkMain);
- EasyMock.verify(bc);
-
- EasyMock.reset(zkMain);
- zkMain.shutdown();
- EasyMock.expectLastCall();
- EasyMock.verify();
-
- assertNotNull(ms.main);
- ms.shutdown();
- assertNull(ms.main);
- assertNull(ms.zkMainThread);
+ control.verify();
}
public void testRemoveConfiguration() throws Exception {
BundleContext bc = EasyMock.createMock(BundleContext.class);
+ MyZooKeeperServerMain zkServer = EasyMock.createMock(MyZooKeeperServerMain.class);
+ zkServer.shutdown();
+ EasyMock.expectLastCall();
- final StringBuilder shutDownTracker = new StringBuilder();
- ManagedService ms = new ManagedService(bc) {
- @Override
- public synchronized void shutdown() {
- shutDownTracker.append("called");
- }
-
- @Override
- void startThread() {}
- };
-
- assertEquals("Precondition failed", 0, shutDownTracker.length());
- ms.updated(null);
- assertEquals("called", shutDownTracker.toString());
- // check that it didn't get reinitialized TODO
- }
-
- public void testNewConfiguration() throws Exception {
- BundleContext bc = EasyMock.createMock(BundleContext.class);
-
- final StringBuilder shutDownTracker = new StringBuilder();
- ManagedService ms = new ManagedService(bc) {
- @Override
- public synchronized void shutdown() {
- shutDownTracker.append("called");
- }
+ replay(zkServer);
- @Override
- void startThread() {}
- };
-
- assertEquals("Precondition failed", 0, shutDownTracker.length());
- assertNull("Precondition failed", ms.main);
- assertNull("Precondition failed", ms.zkMainThread);
+ ZookeeperStarter starter = new ZookeeperStarter(bc);
+ starter.main = zkServer;
+ starter.updated(null);
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put("clientPort", "9911");
- ms.updated(props);
- assertEquals("Shutdown should not have been called", 0, shutDownTracker.length());
- assertNotNull(ms.main);
- assertNotNull(ms.zkMainThread);
+ verify(zkServer);
+ assertNull("main should be null", starter.main);
}
- public void testChangeConfiguration() throws Exception {
- BundleContext bc = EasyMock.createMock(BundleContext.class);
-
- final StringBuilder shutDownTracker = new StringBuilder();
- ManagedService ms = new ManagedService(bc) {
- @Override
- public synchronized void shutdown() {
- shutDownTracker.append("called");
- }
-
- @Override
- void startThread() {}
- };
-
- MyZooKeeperServerMain initialMsMain =
- EasyMock.createMock(ManagedService.MyZooKeeperServerMain.class);
- ms.main = initialMsMain;
- Thread initialZkThread = new Thread();
- ms.zkMainThread = initialZkThread;
-
- assertEquals("Precondition failed", 0, shutDownTracker.length());
- assertNotNull("Precondition failed", ms.main);
- assertNotNull("Precondition failed", ms.zkMainThread);
-
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put("clientPort", "9911");
- ms.updated(props);
- assertEquals("We are reconfiguring, so shutdown should be called",
- "called", shutDownTracker.toString());
- assertNotNull(ms.main);
- assertNotNull(ms.zkMainThread);
- assertNotSame(ms.main, initialMsMain);
- assertNotSame(ms.zkMainThread, initialZkThread);
- }
}