helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: HELIX-485: Remove controller leader election duplicate code
Date Thu, 14 Aug 2014 22:06:09 GMT
Repository: helix
Updated Branches:
  refs/heads/master ecfedff24 -> 325fe8b14


HELIX-485: Remove controller leader election duplicate code


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/325fe8b1
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/325fe8b1
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/325fe8b1

Branch: refs/heads/master
Commit: 325fe8b147b7f9c139364f89044e2b78e141a7b9
Parents: ecfedff
Author: zzhang <zzhang@apache.org>
Authored: Thu Aug 14 14:08:34 2014 -0700
Committer: zzhang <zzhang@apache.org>
Committed: Thu Aug 14 14:08:34 2014 -0700

----------------------------------------------------------------------
 .../manager/zk/DistributedLeaderElection.java   | 110 --------
 .../helix/manager/zk/ZkCallbackHandler.java     |  10 +-
 .../apache/helix/manager/zk/MockController.java |   5 +
 .../manager/zk/MockMultiClusterController.java  |   8 +
 .../helix/manager/zk/MockParticipant.java       |   4 +
 .../helix/participant/MockZKHelixManager.java   | 248 -------------------
 .../participant/TestControllerElection.java     | 121 +++++++++
 .../participant/TestDistControllerElection.java | 192 --------------
 8 files changed, 141 insertions(+), 557 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
deleted file mode 100644
index fe1ca4b..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * 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.
- */
-
-import java.util.List;
-
-import org.apache.helix.ControllerChangeListener;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.InstanceType;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.GenericHelixController;
-import org.apache.log4j.Logger;
-
-/**
- * do distributed leader election
- */
-public class DistributedLeaderElection implements ControllerChangeListener {
-  private static Logger LOG = Logger.getLogger(DistributedLeaderElection.class);
-
-  final HelixManager _manager;
-  final GenericHelixController _controller;
-  final List<HelixTimerTask> _controllerTimerTasks;
-
-  public DistributedLeaderElection(HelixManager manager, GenericHelixController controller,
-      List<HelixTimerTask> controllerTimerTasks) {
-    _manager = manager;
-    _controller = controller;
-    _controllerTimerTasks = controllerTimerTasks;
-  }
-
-  /**
-   * may be accessed by multiple threads: zk-client thread and
-   * ZkHelixManager.disconnect()->reset() TODO: Refactor accessing
-   * HelixMangerMain class statically
-   */
-  @Override
-  public synchronized void onControllerChange(NotificationContext changeContext) {
-    HelixManager manager = changeContext.getManager();
-    if (manager == null) {
-      LOG.error("missing attributes in changeContext. requires HelixManager");
-      return;
-    }
-
-    InstanceType type = manager.getInstanceType();
-    if (type != InstanceType.CONTROLLER && type != InstanceType.CONTROLLER_PARTICIPANT)
{
-      LOG.error("fail to become controller because incorrect instanceType (was " + type.toString()
-          + ", requires CONTROLLER | CONTROLLER_PARTICIPANT)");
-      return;
-    }
-
-    ControllerManagerHelper controllerHelper =
-        new ControllerManagerHelper(_manager, _controllerTimerTasks);
-    try {
-      if (changeContext.getType().equals(NotificationContext.Type.INIT)
-          || changeContext.getType().equals(NotificationContext.Type.CALLBACK)) {
-        LOG.info(_manager.getInstanceName() + " is trying to acquire leadership for cluster:
"
-            + _manager.getClusterName());
-        HelixDataAccessor accessor = manager.getHelixDataAccessor();
-        Builder keyBuilder = accessor.keyBuilder();
-
-        while (accessor.getProperty(keyBuilder.controllerLeader()) == null) {
-          boolean success = ZkHelixLeaderElection.tryUpdateController(manager);
-          if (success) {
-            LOG.info(_manager.getInstanceName() + " acquired leadership for cluster: "
-                + _manager.getClusterName());
-
-            ZkHelixLeaderElection.updateHistory(manager);
-            _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
-            controllerHelper.addListenersToController(_controller);
-            controllerHelper.startControllerTimerTasks();
-          }
-        }
-      } else if (changeContext.getType().equals(NotificationContext.Type.FINALIZE)) {
-        LOG.info(_manager.getInstanceName() + " reqlinquish leadership for cluster: "
-            + _manager.getClusterName());
-        controllerHelper.stopControllerTimerTasks();
-        controllerHelper.removeListenersFromController(_controller);
-        _controller.shutdownClusterStatusMonitor(_manager.getClusterName());
-
-        /**
-         * clear write-through cache
-         */
-        _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
-      }
-
-    } catch (Exception e) {
-      LOG.error("Exception when trying to become leader", e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackHandler.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackHandler.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackHandler.java
index 374a30b..ee420b9 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackHandler.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackHandler.java
@@ -67,18 +67,14 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher.Event.EventType;
 
 /**
- * This is a copy of {@link CallbackHandler} We need to synchronize on ZkHelixConnection
- * instead ofHelixManager to avoid dead-lock.
- * Otherwise an example deadlock scenario would be:
+ * We need to synchronize on {@link ZkHelixConnection} instead of {@link HelixManager} to
avoid
+ * dead-lock. Otherwise an example deadlock scenario would be:
  * 1) main-thread calls ZkHelixConnection#disconnect(), results in:
  * - ZkHelixController#reset(), holding ZkHelixConnection, waiting HelixConnectionAdaptor
  * 2) zk-event-thread calls CallbackHandler#handleChildChange(), results in:
  * - CallbackHandler#invoke(), holding HelixConnectionAdaptor, waiting ZkHelixConnection
- * TODO remove code duplication
  */
-public class ZkCallbackHandler implements IZkChildListener, IZkDataListener
-
-{
+public class ZkCallbackHandler implements IZkChildListener, IZkDataListener {
   private static Logger logger = Logger.getLogger(ZkCallbackHandler.class);
 
   /**

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/manager/zk/MockController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/MockController.java b/helix-core/src/test/java/org/apache/helix/manager/zk/MockController.java
index f4d2159..8649aa9 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/MockController.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/MockController.java
@@ -83,4 +83,9 @@ public class MockController extends ZKHelixManager implements Runnable {
     ZkHelixConnection conn = (ZkHelixConnection)getConn();
     return conn._handlers.get(_role);
   }
+
+  public ZkHelixController getController() {
+    return (ZkHelixController) _role;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
b/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
index a39bd84..f68444c 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/MockMultiClusterController.java
@@ -97,4 +97,12 @@ public class MockMultiClusterController extends ZKHelixManager implements
Runnab
 
     return handlers;
   }
+
+  public ZkHelixMultiClusterController getRole() {
+    return (ZkHelixMultiClusterController) _role;
+  }
+
+  public ZkHelixController getController() {
+    return getRole()._controller;
+  }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java b/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
index 3936680..15451b5 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/MockParticipant.java
@@ -117,4 +117,8 @@ public class MockParticipant extends ZKHelixManager implements Runnable
{
     ZkHelixConnection conn = (ZkHelixConnection)getConn();
     return conn._handlers.get(_role);
   }
+
+  public ZkHelixParticipant getParticipant() {
+    return (ZkHelixParticipant) _role;
+  }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
deleted file mode 100644
index 3efbffb..0000000
--- a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
+++ /dev/null
@@ -1,248 +0,0 @@
-package org.apache.helix.participant;
-
-/*
- * 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.
- */
-
-import java.util.UUID;
-
-import org.apache.helix.ClusterMessagingService;
-import org.apache.helix.ConfigAccessor;
-import org.apache.helix.ControllerChangeListener;
-import org.apache.helix.CurrentStateChangeListener;
-import org.apache.helix.ExternalViewChangeListener;
-import org.apache.helix.HelixAdmin;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixManagerProperties;
-import org.apache.helix.IdealStateChangeListener;
-import org.apache.helix.InstanceConfigChangeListener;
-import org.apache.helix.InstanceType;
-import org.apache.helix.LiveInstanceChangeListener;
-import org.apache.helix.LiveInstanceInfoProvider;
-import org.apache.helix.MessageListener;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.PropertyKey;
-import org.apache.helix.ScopedConfigChangeListener;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.messaging.DefaultMessagingService;
-import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
-import org.apache.helix.store.zk.ZkHelixPropertyStore;
-
-public class MockZKHelixManager implements HelixManager {
-  private final ZKHelixDataAccessor _accessor;
-  private final String _instanceName;
-  private final String _clusterName;
-  private final InstanceType _type;
-
-  public MockZKHelixManager(String clusterName, String instanceName, InstanceType type,
-      ZkClient zkClient) {
-    _instanceName = instanceName;
-    _clusterName = clusterName;
-    _type = type;
-    _accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
-  }
-
-  @Override
-  public void connect() throws Exception {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public boolean isConnected() {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  @Override
-  public void disconnect() {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addIdealStateChangeListener(IdealStateChangeListener listener) throws Exception
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addLiveInstanceChangeListener(LiveInstanceChangeListener listener) throws Exception
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addMessageListener(MessageListener listener, String instanceName) throws Exception
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
-      String instanceName, String sessionId) throws Exception {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public boolean removeListener(PropertyKey key, Object listener) {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  @Override
-  public HelixDataAccessor getHelixDataAccessor() {
-    return _accessor;
-  }
-
-  @Override
-  public String getClusterName() {
-    return _clusterName;
-  }
-
-  @Override
-  public String getInstanceName() {
-    return _instanceName;
-  }
-
-  @Override
-  public String getSessionId() {
-    // TODO Auto-generated method stub
-    return UUID.randomUUID().toString();
-  }
-
-  @Override
-  public long getLastNotificationTime() {
-    // TODO Auto-generated method stub
-    return 0;
-  }
-
-  @Override
-  public void addControllerListener(ControllerChangeListener listener) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public HelixAdmin getClusterManagmentTool() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public ClusterMessagingService getMessagingService() {
-    return new DefaultMessagingService(this);
-  }
-
-  @Override
-  public InstanceType getInstanceType() {
-    return _type;
-  }
-
-  @Override
-  public String getVersion() {
-    // TODO Auto-generated method stub
-    return UUID.randomUUID().toString();
-  }
-
-  @Override
-  public StateMachineEngine getStateMachineEngine() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public boolean isLeader() {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  @Override
-  public ConfigAccessor getConfigAccessor() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public void startTimerTasks() {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void stopTimerTasks() {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addPreConnectCallback(PreConnectCallback callback) {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public void addInstanceConfigChangeListener(InstanceConfigChangeListener listener)
-      throws Exception {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void addConfigChangeListener(ScopedConfigChangeListener listener, ConfigScopeProperty
scope)
-      throws Exception {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider)
{
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public HelixManagerProperties getProperties() {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public void addControllerMessageListener(MessageListener listener) {
-    // TODO Auto-generated method stub
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/participant/TestControllerElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestControllerElection.java
b/helix-core/src/test/java/org/apache/helix/participant/TestControllerElection.java
new file mode 100644
index 0000000..ddc4d4b
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestControllerElection.java
@@ -0,0 +1,121 @@
+package org.apache.helix.participant;
+
+/*
+ * 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.
+ */
+
+import java.util.Date;
+
+import org.apache.helix.NotificationContext;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.TestHelper;
+import org.apache.helix.controller.GenericHelixController;
+import org.apache.helix.manager.zk.MockController;
+import org.apache.helix.manager.zk.MockMultiClusterController;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkHelixLeaderElection;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
+import org.apache.log4j.Logger;
+import org.testng.AssertJUnit;
+import org.testng.annotations.Test;
+
+public class TestControllerElection extends ZkTestBase {
+  private static Logger LOG = Logger.getLogger(TestControllerElection.class);
+
+  @Test()
+  public void testController() throws Exception {
+    String clusterName = TestUtil.getTestName();
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
+
+    String controllerName = "controller_0";
+    MockController controller = new MockController(_zkaddr, clusterName, controllerName);
+    GenericHelixController pipeline = new GenericHelixController();
+
+    ZkHelixLeaderElection leader = new ZkHelixLeaderElection(controller.getController(),
pipeline);
+    NotificationContext context = new NotificationContext(controller);
+    context.setType(NotificationContext.Type.INIT);
+    leader.onControllerChange(context);
+
+    LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
+    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
+
+    // Start another controller, leader should remain unchanged
+    String controllerName1 = "controller_1";
+    MockController controller1 = new MockController(_zkaddr, clusterName, controllerName1);
+    GenericHelixController pipeline1 = new GenericHelixController();
+    ZkHelixLeaderElection leader1 = new ZkHelixLeaderElection(controller1.getController(),
pipeline1);
+    NotificationContext context1 = new NotificationContext(controller1);
+    context1.setType(NotificationContext.Type.INIT);
+    leader1.onControllerChange(context1);
+    liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
+    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
+
+    // clean up
+    controller1.getConn().disconnect();
+    controller.getConn().disconnect();
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+
+  @Test()
+  public void testMultiClusterController() throws Exception {
+    String clusterName = TestUtil.getTestName();
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
+
+    String controllerName = "controller_0";
+    MockMultiClusterController controller = new MockMultiClusterController(_zkaddr, clusterName,
controllerName);
+    GenericHelixController pipeline = new GenericHelixController();
+
+    ZkHelixLeaderElection leader = new ZkHelixLeaderElection(controller.getController(),
pipeline);
+    NotificationContext context = new NotificationContext(controller);
+    context.setType(NotificationContext.Type.CALLBACK);
+    leader.onControllerChange(context);
+
+    LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
+    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
+
+    // Start another controller, leader should remain unchanged
+    MockMultiClusterController controller1 = new MockMultiClusterController(_zkaddr, clusterName,
"controller_1");
+
+    GenericHelixController pipeline1 = new GenericHelixController();
+    ZkHelixLeaderElection leader1 = new ZkHelixLeaderElection(controller.getController(),
pipeline1);
+    context = new NotificationContext(controller);
+    context.setType(NotificationContext.Type.CALLBACK);
+    leader1.onControllerChange(context);
+    liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
+    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
+
+    // clean up
+    controller1.getConn().disconnect();
+    controller.getConn().disconnect();
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/325fe8b1/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
deleted file mode 100644
index de510c1..0000000
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package org.apache.helix.participant;
-
-/*
- * 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.
- */
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.InstanceType;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.GenericHelixController;
-import org.apache.helix.manager.zk.DistributedLeaderElection;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.testutil.TestUtil;
-import org.apache.helix.testutil.ZkTestBase;
-import org.apache.log4j.Logger;
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-public class TestDistControllerElection extends ZkTestBase {
-  private static Logger LOG = Logger.getLogger(TestDistControllerElection.class);
-
-  @Test()
-  public void testController() throws Exception {
-    System.out.println("START TestDistControllerElection at "
-        + new Date(System.currentTimeMillis()));
-    String className = TestUtil.getTestName();
-
-    final String clusterName = className;
-    String path = "/" + clusterName;
-    if (_zkclient.exists(path)) {
-      _zkclient.deleteRecursive(path);
-    }
-
-    ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, _baseAccessor);
-    Builder keyBuilder = accessor.keyBuilder();
-
-    TestHelper.setupEmptyCluster(_zkclient, clusterName);
-
-    final String controllerName = "controller_0";
-    HelixManager manager =
-        new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER, _zkclient);
-    GenericHelixController controller0 = new GenericHelixController();
-
-    List<HelixTimerTask> timerTasks = Collections.emptyList();
-    DistributedLeaderElection election =
-        new DistributedLeaderElection(manager, controller0, timerTasks);
-    NotificationContext context = new NotificationContext(manager);
-    context.setType(NotificationContext.Type.INIT);
-    election.onControllerChange(context);
-
-    // path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    // ZNRecord leaderRecord = zkclient.<ZNRecord> readData(path);
-    LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
-    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-    // AssertJUnit.assertNotNull(election.getController());
-    // AssertJUnit.assertNull(election.getLeader());
-
-    manager =
-        new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER, _zkclient);
-    GenericHelixController controller1 = new GenericHelixController();
-    election = new DistributedLeaderElection(manager, controller1, timerTasks);
-    context = new NotificationContext(manager);
-    context.setType(NotificationContext.Type.INIT);
-    election.onControllerChange(context);
-    // leaderRecord = zkclient.<ZNRecord> readData(path);
-    liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
-    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-    // AssertJUnit.assertNull(election.getController());
-    // AssertJUnit.assertNull(election.getLeader());
-
-    System.out.println("END TestDistControllerElection at " + new Date(System.currentTimeMillis()));
-  }
-
-  @Test()
-  public void testControllerParticipant() throws Exception {
-    String className = TestUtil.getTestName();
-    LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
-
-    final String clusterName = className;
-
-    String path = "/" + clusterName;
-    if (_zkclient.exists(path)) {
-      _zkclient.deleteRecursive(path);
-    }
-
-    ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, _baseAccessor);
-    Builder keyBuilder = accessor.keyBuilder();
-
-    TestHelper.setupEmptyCluster(_zkclient, clusterName);
-
-    final String controllerName = "controller_0";
-    HelixManager manager =
-        new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT,
-            _zkclient);
-    GenericHelixController controller0 = new GenericHelixController();
-    List<HelixTimerTask> timerTasks = Collections.emptyList();
-
-    DistributedLeaderElection election =
-        new DistributedLeaderElection(manager, controller0, timerTasks);
-    NotificationContext context = new NotificationContext(manager);
-    context.setType(NotificationContext.Type.CALLBACK);
-    election.onControllerChange(context);
-
-    LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
-    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-
-    // path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    // ZNRecord leaderRecord = zkclient.<ZNRecord> readData(path);
-    // AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
-    // AssertJUnit.assertNotNull(election.getController());
-    // AssertJUnit.assertNotNull(election.getLeader());
-
-    manager =
-        new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER_PARTICIPANT,
-            _zkclient);
-    GenericHelixController controller1 = new GenericHelixController();
-    election = new DistributedLeaderElection(manager, controller1, timerTasks);
-    context = new NotificationContext(manager);
-    context.setType(NotificationContext.Type.CALLBACK);
-    election.onControllerChange(context);
-
-    liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
-    AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
-
-    // leaderRecord = zkclient.<ZNRecord> readData(path);
-    // AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
-    // AssertJUnit.assertNull(election.getController());
-    // AssertJUnit.assertNull(election.getLeader());
-
-    LOG.info("END " + className + " at " + new Date(System.currentTimeMillis()));
-  }
-
-  @Test()
-  public void testParticipant() throws Exception {
-    String className = TestUtil.getTestName();
-    LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
-
-    final String clusterName = className;
-    String path = "/" + clusterName;
-    if (_zkclient.exists(path)) {
-      _zkclient.deleteRecursive(path);
-    }
-    TestHelper.setupEmptyCluster(_zkclient, clusterName);
-
-    final String controllerName = "participant_0";
-    HelixManager manager =
-        new MockZKHelixManager(clusterName, controllerName, InstanceType.PARTICIPANT, _zkclient);
-    GenericHelixController participant0 = new GenericHelixController();
-    List<HelixTimerTask> timerTasks = Collections.emptyList();
-
-    DistributedLeaderElection election =
-        new DistributedLeaderElection(manager, participant0, timerTasks);
-    NotificationContext context = new NotificationContext(manager);
-    context.setType(NotificationContext.Type.INIT);
-    election.onControllerChange(context);
-
-    path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    ZNRecord leaderRecord = _zkclient.<ZNRecord> readData(path, true);
-    AssertJUnit.assertNull(leaderRecord);
-    // AssertJUnit.assertNull(election.getController());
-    // AssertJUnit.assertNull(election.getLeader());
-  }
-
-}


Mime
View raw message