helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject [20/51] [partial] [HELIX-198] Unify helix code style, rb=13710
Date Wed, 21 Aug 2013 20:43:33 GMT
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestHelper.java b/helix-core/src/test/java/org/apache/helix/TestHelper.java
index 59b5665..5c4749e 100644
--- a/helix-core/src/test/java/org/apache/helix/TestHelper.java
+++ b/helix-core/src/test/java/org/apache/helix/TestHelper.java
@@ -69,44 +69,40 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.data.Stat;
 import org.testng.Assert;
 
-
-public class TestHelper
-{
+public class TestHelper {
   private static final Logger LOG = Logger.getLogger(TestHelper.class);
 
   /**
    * Returns a unused random port.
    */
   public static int getRandomPort() throws IOException {
-      ServerSocket sock = new ServerSocket();
-      sock.bind(null);
-      int port = sock.getLocalPort();
-      sock.close();
+    ServerSocket sock = new ServerSocket();
+    sock.bind(null);
+    int port = sock.getLocalPort();
+    sock.close();
 
-      return port;
+    return port;
   }
 
-  static public ZkServer startZkServer(final String zkAddress) throws Exception
-  {
+  static public ZkServer startZkServer(final String zkAddress) throws Exception {
     List<String> empty = Collections.emptyList();
     return TestHelper.startZkServer(zkAddress, empty, true);
   }
 
-  static public ZkServer startZkServer(final String zkAddress, final String rootNamespace) throws Exception
-  {
+  static public ZkServer startZkServer(final String zkAddress, final String rootNamespace)
+      throws Exception {
     List<String> rootNamespaces = new ArrayList<String>();
     rootNamespaces.add(rootNamespace);
     return TestHelper.startZkServer(zkAddress, rootNamespaces, true);
   }
 
-  static public ZkServer startZkServer(final String zkAddress,
-      final List<String> rootNamespaces) throws Exception {
+  static public ZkServer startZkServer(final String zkAddress, final List<String> rootNamespaces)
+      throws Exception {
     return startZkServer(zkAddress, rootNamespaces, true);
   }
 
-  static public ZkServer startZkServer(final String zkAddress,
-                                      final List<String> rootNamespaces, boolean overwrite) throws Exception
-  {
+  static public ZkServer startZkServer(final String zkAddress, final List<String> rootNamespaces,
+      boolean overwrite) throws Exception {
     System.out.println("Start zookeeper at " + zkAddress + " in thread "
         + Thread.currentThread().getName());
 
@@ -119,25 +115,18 @@ public class TestHelper
     }
     ZKClientPool.reset();
 
-    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace()
-    {
+    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {
       @Override
-      public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient)
-      {
+      public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
         if (rootNamespaces == null) {
           return;
         }
 
-        for (String rootNamespace : rootNamespaces)
-        {
-          try
-          {
+        for (String rootNamespace : rootNamespaces) {
+          try {
             zkClient.deleteRecursive(rootNamespace);
-          }
-          catch (Exception e)
-          {
-            LOG.error("fail to deleteRecursive path:" + rootNamespace + "\nexception:"
-                + e);
+          } catch (Exception e) {
+            LOG.error("fail to deleteRecursive path:" + rootNamespace + "\nexception:" + e);
           }
         }
       }
@@ -150,26 +139,19 @@ public class TestHelper
     return zkServer;
   }
 
-  static public void stopZkServer(ZkServer zkServer)
-  {
-    if (zkServer != null)
-    {
+  static public void stopZkServer(ZkServer zkServer) {
+    if (zkServer != null) {
       zkServer.shutdown();
-      System.out.println("Shut down zookeeper at port " + zkServer.getPort()
-          + " in thread " + Thread.currentThread().getName());
+      System.out.println("Shut down zookeeper at port " + zkServer.getPort() + " in thread "
+          + Thread.currentThread().getName());
     }
   }
 
-  public static StartCMResult startDummyProcess(final String zkAddr,
-                                                final String clusterName,
-                                                final String instanceName) throws Exception
-  {
+  public static StartCMResult startDummyProcess(final String zkAddr, final String clusterName,
+      final String instanceName) throws Exception {
     StartCMResult result = new StartCMResult();
     ZkHelixTestManager manager = null;
-    manager = new ZkHelixTestManager(clusterName,
-                                     instanceName,
-                                     InstanceType.PARTICIPANT,
-                                     zkAddr);
+    manager = new ZkHelixTestManager(clusterName, instanceName, InstanceType.PARTICIPANT, zkAddr);
     result._manager = manager;
     Thread thread = new Thread(new DummyProcessThread(manager, instanceName));
     result._thread = thread;
@@ -179,31 +161,29 @@ public class TestHelper
   }
 
   private static ZkHelixTestManager startHelixController(final String zkConnectString,
-	      final String clusterName, final String controllerName, final String controllerMode)
-  {
-	ZkHelixTestManager manager = null;
-    try
-    {
-      if (controllerMode.equalsIgnoreCase(HelixControllerMain.STANDALONE))
-      {
-        manager = new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER, zkConnectString);
+      final String clusterName, final String controllerName, final String controllerMode) {
+    ZkHelixTestManager manager = null;
+    try {
+      if (controllerMode.equalsIgnoreCase(HelixControllerMain.STANDALONE)) {
+        manager =
+            new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER,
+                zkConnectString);
         manager.connect();
-      } else if (controllerMode.equalsIgnoreCase(HelixControllerMain.DISTRIBUTED))
-      {
-        manager = new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);
+      } else if (controllerMode.equalsIgnoreCase(HelixControllerMain.DISTRIBUTED)) {
+        manager =
+            new ZkHelixTestManager(clusterName, controllerName,
+                InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);
 
-        DistClusterControllerStateModelFactory stateModelFactory = new DistClusterControllerStateModelFactory(
-            zkConnectString);
+        DistClusterControllerStateModelFactory stateModelFactory =
+            new DistClusterControllerStateModelFactory(zkConnectString);
 
         StateMachineEngine stateMach = manager.getStateMachineEngine();
         stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
         manager.connect();
-      } else
-      {
+      } else {
         LOG.error("cluster controller mode:" + controllerMode + " NOT supported");
       }
-    } catch (Exception e)
-    {
+    } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
@@ -213,39 +193,28 @@ public class TestHelper
 
   // TODO refactor this
   public static StartCMResult startController(final String clusterName,
-                                              final String controllerName,
-                                              final String zkConnectString,
-                                              final String controllerMode) throws Exception
-  {
+      final String controllerName, final String zkConnectString, final String controllerMode)
+      throws Exception {
     final StartCMResult result = new StartCMResult();
-    final ZkHelixTestManager manager = startHelixController(zkConnectString,
-                                                 	clusterName,
-                                                 	controllerName,
-                                                 	controllerMode);
+    final ZkHelixTestManager manager =
+        startHelixController(zkConnectString, clusterName, controllerName, controllerMode);
     result._manager = manager;
 
-    Thread thread = new Thread(new Runnable()
-    {
+    Thread thread = new Thread(new Runnable() {
       @Override
-      public void run()
-      {
+      public void run() {
         // ClusterManager manager = null;
 
-        try
-        {
+        try {
 
           Thread.currentThread().join();
-        }
-        catch (InterruptedException e)
-        {
+        } catch (InterruptedException e) {
           String msg =
               "controller:" + controllerName + ", " + Thread.currentThread().getName()
                   + " interrupted";
           LOG.info(msg);
           // System.err.println(msg);
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
           e.printStackTrace();
         }
       }
@@ -256,58 +225,49 @@ public class TestHelper
     return result;
   }
 
-  public static class StartCMResult
-  {
-    public Thread       _thread;
+  public static class StartCMResult {
+    public Thread _thread;
     public ZkHelixTestManager _manager;
 
   }
 
-  public static void setupEmptyCluster(ZkClient zkClient, String clusterName)
-  {
+  public static void setupEmptyCluster(ZkClient zkClient, String clusterName) {
     ZKHelixAdmin admin = new ZKHelixAdmin(zkClient);
     admin.addCluster(clusterName, true);
   }
 
   /**
    * convert T[] to set<T>
-   *
    * @param s
    * @return
    */
-  public static <T> Set<T> setOf(T... s)
-  {
+  public static <T> Set<T> setOf(T... s) {
     Set<T> set = new HashSet<T>(Arrays.asList(s));
     return set;
   }
 
-//  public static void verifyWithTimeout(String verifierName, Object... args)
-//  {
-//    verifyWithTimeout(verifierName, 30 * 1000, args);
-//  }
+  // public static void verifyWithTimeout(String verifierName, Object... args)
+  // {
+  // verifyWithTimeout(verifierName, 30 * 1000, args);
+  // }
 
   /**
    * generic method for verification with a timeout
-   *
    * @param verifierName
    * @param args
    */
-  public static void verifyWithTimeout(String verifierName, long timeout, Object... args)
-  {
+  public static void verifyWithTimeout(String verifierName, long timeout, Object... args) {
     final long sleepInterval = 1000; // in ms
     final int loop = (int) (timeout / sleepInterval) + 1;
-    try
-    {
+    try {
       boolean result = false;
       int i = 0;
-      for (; i < loop; i++)
-      {
+      for (; i < loop; i++) {
         Thread.sleep(sleepInterval);
         // verifier should be static method
         result = (Boolean) TestHelper.getMethod(verifierName).invoke(null, args);
 
-        if (result == true)
-        {
+        if (result == true) {
           break;
         }
       }
@@ -315,136 +275,87 @@ public class TestHelper
       // debug
       // LOG.info(verifierName + ": wait " + ((i + 1) * 1000) + "ms to verify ("
       // + result + ")");
-      System.err.println(verifierName + ": wait " + ((i + 1) * 1000) + "ms to verify "
-          + " (" + result + ")");
+      System.err.println(verifierName + ": wait " + ((i + 1) * 1000) + "ms to verify " + " ("
+          + result + ")");
       LOG.debug("args:" + Arrays.toString(args));
       // System.err.println("args:" + Arrays.toString(args));
 
-      if (result == false)
-      {
+      if (result == false) {
         LOG.error(verifierName + " fails");
         LOG.error("args:" + Arrays.toString(args));
       }
 
       Assert.assertTrue(result);
-    }
-    catch (Exception e)
-    {
+    } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 
-  private static Method getMethod(String name)
-  {
+  private static Method getMethod(String name) {
     Method[] methods = TestHelper.class.getMethods();
-    for (Method method : methods)
-    {
-      if (name.equals(method.getName()))
-      {
+    for (Method method : methods) {
+      if (name.equals(method.getName())) {
         return method;
       }
     }
     return null;
   }
 
-  public static boolean verifyEmptyCurStateAndExtView(String clusterName,
-                                                      String resourceName,
-                                                      Set<String> instanceNames,
-                                                      String zkAddr)
-  {
+  public static boolean verifyEmptyCurStateAndExtView(String clusterName, String resourceName,
+      Set<String> instanceNames, String zkAddr) {
     ZkClient zkClient = new ZkClient(zkAddr);
     zkClient.setZkSerializer(new ZNRecordSerializer());
 
-    try
-    {
+    try {
       ZKHelixDataAccessor accessor =
           new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
       Builder keyBuilder = accessor.keyBuilder();
 
-      for (String instanceName : instanceNames)
-      {
-        List<String> sessionIds =
-            accessor.getChildNames(keyBuilder.sessions(instanceName));
+      for (String instanceName : instanceNames) {
+        List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(instanceName));
 
-        for (String sessionId : sessionIds)
-        {
+        for (String sessionId : sessionIds) {
           CurrentState curState =
-              accessor.getProperty(keyBuilder.currentState(instanceName,
-                                                           sessionId,
-                                                           resourceName));
+              accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, resourceName));
 
-          if (curState != null && curState.getRecord().getMapFields().size() != 0)
-          {
+          if (curState != null && curState.getRecord().getMapFields().size() != 0) {
             return false;
           }
         }
 
-        ExternalView extView =
-            accessor.getProperty(keyBuilder.externalView(resourceName));
+        ExternalView extView = accessor.getProperty(keyBuilder.externalView(resourceName));
 
-        if (extView != null && extView.getRecord().getMapFields().size() != 0)
-        {
+        if (extView != null && extView.getRecord().getMapFields().size() != 0) {
           return false;
         }
 
       }
 
       return true;
-    }
-    finally
-    {
+    } finally {
       zkClient.close();
     }
   }
 
-  public static boolean verifyNotConnected(HelixManager manager)
-  {
+  public static boolean verifyNotConnected(HelixManager manager) {
     return !manager.isConnected();
   }
 
-  public static void setupCluster(String clusterName,
-                                  String zkAddr,
-                                  int startPort,
-                                  String participantNamePrefix,
-                                  String resourceNamePrefix,
-                                  int resourceNb,
-                                  int partitionNb,
-                                  int nodesNb,
-                                  int replica,
-                                  String stateModelDef,
-                                  boolean doRebalance) throws Exception
-  {
-    TestHelper.setupCluster(clusterName,
-                            zkAddr,
-                            startPort,
-                            participantNamePrefix,
-                            resourceNamePrefix,
-                            resourceNb,
-                            partitionNb,
-                            nodesNb,
-                            replica,
-                            stateModelDef,
-                            RebalanceMode.SEMI_AUTO,
-                            doRebalance);
+  public static void setupCluster(String clusterName, String zkAddr, int startPort,
+      String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb,
+      int nodesNb, int replica, String stateModelDef, boolean doRebalance) throws Exception {
+    TestHelper.setupCluster(clusterName, zkAddr, startPort, participantNamePrefix,
+        resourceNamePrefix, resourceNb, partitionNb, nodesNb, replica, stateModelDef,
+        RebalanceMode.SEMI_AUTO, doRebalance);
   }
 
-  public static void setupCluster(String clusterName,
-                                  String ZkAddr,
-                                  int startPort,
-                                  String participantNamePrefix,
-                                  String resourceNamePrefix,
-                                  int resourceNb,
-                                  int partitionNb,
-                                  int nodesNb,
-                                  int replica,
-                                  String stateModelDef,
-                                  RebalanceMode mode,
-                                  boolean doRebalance) throws Exception
-  {
+  public static void setupCluster(String clusterName, String ZkAddr, int startPort,
+      String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb,
+      int nodesNb, int replica, String stateModelDef, RebalanceMode mode, boolean doRebalance)
+      throws Exception {
     ZkClient zkClient = new ZkClient(ZkAddr);
-    if (zkClient.exists("/" + clusterName))
-    {
+    if (zkClient.exists("/" + clusterName)) {
       LOG.warn("Cluster already exists:" + clusterName + ". Deleting it");
       zkClient.deleteRecursive("/" + clusterName);
     }
@@ -452,18 +363,16 @@ public class TestHelper
     ClusterSetup setupTool = new ClusterSetup(ZkAddr);
     setupTool.addCluster(clusterName, true);
 
-    for (int i = 0; i < nodesNb; i++)
-    {
+    for (int i = 0; i < nodesNb; i++) {
       int port = startPort + i;
       setupTool.addInstanceToCluster(clusterName, participantNamePrefix + "_" + port);
     }
 
-    for (int i = 0; i < resourceNb; i++)
-    {
+    for (int i = 0; i < resourceNb; i++) {
       String resourceName = resourceNamePrefix + i;
-      setupTool.addResourceToCluster(clusterName, resourceName, partitionNb, stateModelDef, mode.toString());
-      if (doRebalance)
-      {
+      setupTool.addResourceToCluster(clusterName, resourceName, partitionNb, stateModelDef,
+          mode.toString());
+      if (doRebalance) {
         setupTool.rebalanceStorageCluster(clusterName, resourceName, replica);
       }
     }
@@ -471,71 +380,55 @@ public class TestHelper
   }
 
   /**
-   *
    * @param stateMap
    *          : "ResourceName/partitionKey" -> setOf(instances)
    * @param state
    *          : MASTER|SLAVE|ERROR...
    */
-  public static void verifyState(String clusterName,
-                                 String zkAddr,
-                                 Map<String, Set<String>> stateMap,
-                                 String state)
-  {
+  public static void verifyState(String clusterName, String zkAddr,
+      Map<String, Set<String>> stateMap, String state) {
     ZkClient zkClient = new ZkClient(zkAddr);
     zkClient.setZkSerializer(new ZNRecordSerializer());
 
-    try
-    {
+    try {
       ZKHelixDataAccessor accessor =
           new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
       Builder keyBuilder = accessor.keyBuilder();
 
-      for (String resGroupPartitionKey : stateMap.keySet())
-      {
+      for (String resGroupPartitionKey : stateMap.keySet()) {
         Map<String, String> retMap = getResourceAndPartitionKey(resGroupPartitionKey);
         String resGroup = retMap.get("RESOURCE");
         String partitionKey = retMap.get("PARTITION");
 
         ExternalView extView = accessor.getProperty(keyBuilder.externalView(resGroup));
-        for (String instance : stateMap.get(resGroupPartitionKey))
-        {
+        for (String instance : stateMap.get(resGroupPartitionKey)) {
           String actualState = extView.getStateMap(partitionKey).get(instance);
-          Assert.assertNotNull(actualState, "externalView doesn't contain state for "
-              + resGroup + "/" + partitionKey + " on " + instance + " (expect " + state
-              + ")");
+          Assert.assertNotNull(actualState, "externalView doesn't contain state for " + resGroup
+              + "/" + partitionKey + " on " + instance + " (expect " + state + ")");
 
-          Assert.assertEquals(actualState, state, "externalView for " + resGroup + "/"
-              + partitionKey + " on " + instance + " is " + actualState + " (expect "
-              + state + ")");
+          Assert
+              .assertEquals(actualState, state, "externalView for " + resGroup + "/" + partitionKey
+                  + " on " + instance + " is " + actualState + " (expect " + state + ")");
         }
       }
-    }
-    finally
-    {
+    } finally {
       zkClient.close();
     }
   }
 
   /**
-   *
    * @param resourcePartition
    *          : key is in form of "resource/partitionKey" or "resource_x"
-   *
    * @return
    */
-  private static Map<String, String> getResourceAndPartitionKey(String resourcePartition)
-  {
+  private static Map<String, String> getResourceAndPartitionKey(String resourcePartition) {
     String resourceName;
     String partitionName;
     int idx = resourcePartition.indexOf('/');
-    if (idx > -1)
-    {
+    if (idx > -1) {
       resourceName = resourcePartition.substring(0, idx);
       partitionName = resourcePartition.substring(idx + 1);
-    }
-    else
-    {
+    } else {
       idx = resourcePartition.lastIndexOf('_');
       resourceName = resourcePartition.substring(0, idx);
       partitionName = resourcePartition;
@@ -548,45 +441,32 @@ public class TestHelper
   }
 
   public static <T> Map<String, T> startThreadsConcurrently(final int nrThreads,
-                                                            final Callable<T> method,
-                                                            final long timeout)
-  {
+      final Callable<T> method, final long timeout) {
     final CountDownLatch startLatch = new CountDownLatch(1);
     final CountDownLatch finishCounter = new CountDownLatch(nrThreads);
     final Map<String, T> resultsMap = new ConcurrentHashMap<String, T>();
     final List<Thread> threadList = new ArrayList<Thread>();
 
-    for (int i = 0; i < nrThreads; i++)
-    {
-      Thread thread = new Thread()
-      {
+    for (int i = 0; i < nrThreads; i++) {
+      Thread thread = new Thread() {
         @Override
-        public void run()
-        {
-          try
-          {
+        public void run() {
+          try {
             boolean isTimeout = !startLatch.await(timeout, TimeUnit.SECONDS);
-            if (isTimeout)
-            {
+            if (isTimeout) {
               LOG.error("Timeout while waiting for start latch");
             }
-          }
-          catch (InterruptedException ex)
-          {
+          } catch (InterruptedException ex) {
             LOG.error("Interrupted while waiting for start latch");
           }
 
-          try
-          {
+          try {
             T result = method.call();
-            if (result != null)
-            {
+            if (result != null) {
               resultsMap.put("thread_" + this.getId(), result);
             }
             LOG.debug("result=" + result);
-          }
-          catch (Exception e)
-          {
+          } catch (Exception e) {
             LOG.error("Exeption in executing " + method.getClass().getName(), e);
           }
 
@@ -599,33 +479,23 @@ public class TestHelper
     startLatch.countDown();
 
     // wait for all thread to complete
-    try
-    {
+    try {
       boolean isTimeout = !finishCounter.await(timeout, TimeUnit.SECONDS);
-      if (isTimeout)
-      {
+      if (isTimeout) {
         LOG.error("Timeout while waiting for finish latch. Interrupt all threads");
-        for (Thread thread : threadList)
-        {
+        for (Thread thread : threadList) {
           thread.interrupt();
         }
       }
-    }
-    catch (InterruptedException e)
-    {
+    } catch (InterruptedException e) {
       LOG.error("Interrupted while waiting for finish latch", e);
     }
 
     return resultsMap;
   }
 
-  public static Message createMessage(String msgId,
-                                      String fromState,
-                                      String toState,
-                                      String tgtName,
-                                      String resourceName,
-                                      String partitionName)
-  {
+  public static Message createMessage(String msgId, String fromState, String toState,
+      String tgtName, String resourceName, String partitionName) {
     Message msg = new Message(MessageType.STATE_TRANSITION, msgId);
     msg.setFromState(fromState);
     msg.setToState(toState);
@@ -637,61 +507,47 @@ public class TestHelper
     return msg;
   }
 
-  public static String getTestMethodName()
-  {
+  public static String getTestMethodName() {
     StackTraceElement[] calls = Thread.currentThread().getStackTrace();
     return calls[2].getMethodName();
   }
 
-  public static String getTestClassName()
-  {
+  public static String getTestClassName() {
     StackTraceElement[] calls = Thread.currentThread().getStackTrace();
     String fullClassName = calls[2].getClassName();
     return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
   }
 
   public static <T> Map<String, T> startThreadsConcurrently(final List<Callable<T>> methods,
-                                                            final long timeout)
-  {
+      final long timeout) {
     final int nrThreads = methods.size();
     final CountDownLatch startLatch = new CountDownLatch(1);
     final CountDownLatch finishCounter = new CountDownLatch(nrThreads);
     final Map<String, T> resultsMap = new ConcurrentHashMap<String, T>();
     final List<Thread> threadList = new ArrayList<Thread>();
 
-    for (int i = 0; i < nrThreads; i++)
-    {
+    for (int i = 0; i < nrThreads; i++) {
       final Callable<T> method = methods.get(i);
 
-      Thread thread = new Thread()
-      {
+      Thread thread = new Thread() {
         @Override
-        public void run()
-        {
-          try
-          {
+        public void run() {
+          try {
             boolean isTimeout = !startLatch.await(timeout, TimeUnit.SECONDS);
-            if (isTimeout)
-            {
+            if (isTimeout) {
               LOG.error("Timeout while waiting for start latch");
             }
-          }
-          catch (InterruptedException ex)
-          {
+          } catch (InterruptedException ex) {
             LOG.error("Interrupted while waiting for start latch");
           }
 
-          try
-          {
+          try {
             T result = method.call();
-            if (result != null)
-            {
+            if (result != null) {
               resultsMap.put("thread_" + this.getId(), result);
             }
             LOG.debug("result=" + result);
-          }
-          catch (Exception e)
-          {
+          } catch (Exception e) {
             LOG.error("Exeption in executing " + method.getClass().getName(), e);
           }
 
@@ -704,34 +560,27 @@ public class TestHelper
     startLatch.countDown();
 
     // wait for all thread to complete
-    try
-    {
+    try {
       boolean isTimeout = !finishCounter.await(timeout, TimeUnit.SECONDS);
-      if (isTimeout)
-      {
+      if (isTimeout) {
         LOG.error("Timeout while waiting for finish latch. Interrupt all threads");
-        for (Thread thread : threadList)
-        {
+        for (Thread thread : threadList) {
           thread.interrupt();
         }
       }
-    }
-    catch (InterruptedException e)
-    {
+    } catch (InterruptedException e) {
       LOG.error("Interrupted while waiting for finish latch", e);
     }
 
     return resultsMap;
   }
 
-  public static void printCache(Map<String, ZNode> cache)
-  {
+  public static void printCache(Map<String, ZNode> cache) {
     System.out.println("START:Print cache");
     TreeMap<String, ZNode> map = new TreeMap<String, ZNode>();
     map.putAll(cache);
 
-    for (String key : map.keySet())
-    {
+    for (String key : map.keySet()) {
       ZNode node = map.get(key);
       TreeSet<String> childSet = new TreeSet<String>();
       childSet.addAll(node.getChildSet());
@@ -741,12 +590,8 @@ public class TestHelper
     System.out.println("END:Print cache");
   }
 
-  public static void readZkRecursive(String path,
-                                     Map<String, ZNode> map,
-                                     ZkClient zkclient)
-  {
-    try
-    {
+  public static void readZkRecursive(String path, Map<String, ZNode> map, ZkClient zkclient) {
+    try {
       Stat stat = new Stat();
       ZNRecord record = zkclient.readData(path, stat);
       List<String> childNames = zkclient.getChildren(path);
@@ -754,24 +599,18 @@ public class TestHelper
       node.addChildren(childNames);
       map.put(path, node);
 
-      for (String childName : childNames)
-      {
+      for (String childName : childNames) {
         String childPath = path + "/" + childName;
         readZkRecursive(childPath, map, zkclient);
       }
-    }
-    catch (ZkNoNodeException e)
-    {
+    } catch (ZkNoNodeException e) {
       // OK
     }
   }
 
-  public static void readZkRecursive(String path,
-                                     Map<String, ZNode> map,
-                                     BaseDataAccessor<ZNRecord> zkAccessor)
-  {
-    try
-    {
+  public static void readZkRecursive(String path, Map<String, ZNode> map,
+      BaseDataAccessor<ZNRecord> zkAccessor) {
+    try {
       Stat stat = new Stat();
       ZNRecord record = zkAccessor.get(path, stat, 0);
       List<String> childNames = zkAccessor.getChildNames(path, 0);
@@ -780,31 +619,23 @@ public class TestHelper
       node.addChildren(childNames);
       map.put(path, node);
 
-      if (childNames != null && !childNames.isEmpty())
-      {
-        for (String childName : childNames)
-        {
+      if (childNames != null && !childNames.isEmpty()) {
+        for (String childName : childNames) {
           String childPath = path + "/" + childName;
           readZkRecursive(childPath, map, zkAccessor);
         }
       }
-    }
-    catch (ZkNoNodeException e)
-    {
+    } catch (ZkNoNodeException e) {
       // OK
     }
   }
 
-  public static boolean verifyZkCache(List<String> paths,
-                                      BaseDataAccessor<ZNRecord> zkAccessor,
-                                      ZkClient zkclient,
-                                      boolean needVerifyStat)
-  {
+  public static boolean verifyZkCache(List<String> paths, BaseDataAccessor<ZNRecord> zkAccessor,
+      ZkClient zkclient, boolean needVerifyStat) {
     // read everything
     Map<String, ZNode> zkMap = new HashMap<String, ZNode>();
     Map<String, ZNode> cache = new HashMap<String, ZNode>();
-    for (String path : paths)
-    {
+    for (String path : paths) {
       readZkRecursive(path, zkMap, zkclient);
       readZkRecursive(path, cache, zkAccessor);
     }
@@ -813,24 +644,16 @@ public class TestHelper
     return verifyZkCache(paths, null, cache, zkMap, needVerifyStat);
   }
 
-  public static boolean verifyZkCache(List<String> paths,
-                                      Map<String, ZNode> cache,
-                                      ZkClient zkclient,
-                                      boolean needVerifyStat)
-  {
+  public static boolean verifyZkCache(List<String> paths, Map<String, ZNode> cache,
+      ZkClient zkclient, boolean needVerifyStat) {
     return verifyZkCache(paths, null, cache, zkclient, needVerifyStat);
   }
 
-  public static boolean verifyZkCache(List<String> paths,
-                                      List<String> pathsExcludeForStat,
-                                      Map<String, ZNode> cache,
-                                      ZkClient zkclient,
-                                      boolean needVerifyStat)
-  {
+  public static boolean verifyZkCache(List<String> paths, List<String> pathsExcludeForStat,
+      Map<String, ZNode> cache, ZkClient zkclient, boolean needVerifyStat) {
     // read everything on zk under paths
     Map<String, ZNode> zkMap = new HashMap<String, ZNode>();
-    for (String path : paths)
-    {
+    for (String path : paths) {
       readZkRecursive(path, zkMap, zkclient);
     }
     // printCache(map);
@@ -838,15 +661,10 @@ public class TestHelper
     return verifyZkCache(paths, pathsExcludeForStat, cache, zkMap, needVerifyStat);
   }
 
-  public static boolean verifyZkCache(List<String> paths,
-                                      List<String> pathsExcludeForStat,
-                                      Map<String, ZNode> cache,
-                                      Map<String, ZNode> zkMap,
-                                      boolean needVerifyStat)
-  {
+  public static boolean verifyZkCache(List<String> paths, List<String> pathsExcludeForStat,
+      Map<String, ZNode> cache, Map<String, ZNode> zkMap, boolean needVerifyStat) {
     // equal size
-    if (zkMap.size() != cache.size())
-    {
+    if (zkMap.size() != cache.size()) {
       System.err.println("size mismatch: cacheSize: " + cache.size() + ", zkMapSize: "
           + zkMap.size());
       System.out.println("cache: (" + cache.size() + ")");
@@ -859,49 +677,41 @@ public class TestHelper
     }
 
     // everything in cache is also in map
-    for (String path : cache.keySet())
-    {
+    for (String path : cache.keySet()) {
       ZNode cacheNode = cache.get(path);
       ZNode zkNode = zkMap.get(path);
 
-      if (zkNode == null)
-      {
+      if (zkNode == null) {
         // in cache but not on zk
-        System.err.println("path: " + path + " in cache but not on zk: inCacheNode: "
-            + cacheNode);
+        System.err.println("path: " + path + " in cache but not on zk: inCacheNode: " + cacheNode);
         return false;
       }
 
       if ((zkNode.getData() == null && cacheNode.getData() != null)
           || (zkNode.getData() != null && cacheNode.getData() == null)
-          || (zkNode.getData() != null && cacheNode.getData() != null && !zkNode.getData()
-                                                                                .equals(cacheNode.getData())))
-      {
+          || (zkNode.getData() != null && cacheNode.getData() != null && !zkNode.getData().equals(
+              cacheNode.getData()))) {
         // data not equal
-        System.err.println("data mismatch on path: " + path + ", inCache: "
-            + cacheNode.getData() + ", onZk: " + zkNode.getData());
+        System.err.println("data mismatch on path: " + path + ", inCache: " + cacheNode.getData()
+            + ", onZk: " + zkNode.getData());
         return false;
       }
 
       if ((zkNode.getChildSet() == null && cacheNode.getChildSet() != null)
           || (zkNode.getChildSet() != null && cacheNode.getChildSet() == null)
-          || (zkNode.getChildSet() != null && cacheNode.getChildSet() != null && !zkNode.getChildSet()
-                                                                                        .equals(cacheNode.getChildSet())))
-      {
+          || (zkNode.getChildSet() != null && cacheNode.getChildSet() != null && !zkNode
+              .getChildSet().equals(cacheNode.getChildSet()))) {
         // childSet not equal
         System.err.println("childSet mismatch on path: " + path + ", inCache: "
             + cacheNode.getChildSet() + ", onZk: " + zkNode.getChildSet());
         return false;
       }
 
-      if (needVerifyStat && pathsExcludeForStat != null
-          && !pathsExcludeForStat.contains(path))
-      {
-        if (cacheNode.getStat() == null || !zkNode.getStat().equals(cacheNode.getStat()))
-        {
+      if (needVerifyStat && pathsExcludeForStat != null && !pathsExcludeForStat.contains(path)) {
+        if (cacheNode.getStat() == null || !zkNode.getStat().equals(cacheNode.getStat())) {
           // stat not equal
-          System.err.println("Stat mismatch on path: " + path + ", inCache: "
-              + cacheNode.getStat() + ", onZk: " + zkNode.getStat());
+          System.err.println("Stat mismatch on path: " + path + ", inCache: " + cacheNode.getStat()
+              + ", onZk: " + zkNode.getStat());
           return false;
         }
       }
@@ -910,8 +720,7 @@ public class TestHelper
     return true;
   }
 
-  public static StateModelDefinition generateStateModelDefForBootstrap()
-  {
+  public static StateModelDefinition generateStateModelDefForBootstrap() {
     ZNRecord record = new ZNRecord("Bootstrap");
     record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "IDLE");
     List<String> statePriorityList = new ArrayList<String>();
@@ -922,84 +731,62 @@ public class TestHelper
     statePriorityList.add("DROPPED");
     statePriorityList.add("ERROR");
     record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
-                        statePriorityList);
-    for (String state : statePriorityList)
-    {
+        statePriorityList);
+    for (String state : statePriorityList) {
       String key = state + ".meta";
       Map<String, String> metadata = new HashMap<String, String>();
-      if (state.equals("ONLINE"))
-      {
+      if (state.equals("ONLINE")) {
         metadata.put("count", "R");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("BOOTSTRAP"))
-      {
+      } else if (state.equals("BOOTSTRAP")) {
         metadata.put("count", "-1");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("OFFLINE"))
-      {
+      } else if (state.equals("OFFLINE")) {
         metadata.put("count", "-1");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("IDLE"))
-      {
+      } else if (state.equals("IDLE")) {
         metadata.put("count", "-1");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("DROPPED"))
-      {
+      } else if (state.equals("DROPPED")) {
         metadata.put("count", "-1");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("ERROR"))
-      {
+      } else if (state.equals("ERROR")) {
         metadata.put("count", "-1");
         record.setMapField(key, metadata);
       }
     }
 
-    for (String state : statePriorityList)
-    {
+    for (String state : statePriorityList) {
       String key = state + ".next";
-      if (state.equals("ONLINE"))
-      {
+      if (state.equals("ONLINE")) {
         Map<String, String> metadata = new HashMap<String, String>();
         metadata.put("BOOTSTRAP", "OFFLINE");
         metadata.put("OFFLINE", "OFFLINE");
         metadata.put("DROPPED", "OFFLINE");
         metadata.put("IDLE", "OFFLINE");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("BOOTSTRAP"))
-      {
+      } else if (state.equals("BOOTSTRAP")) {
         Map<String, String> metadata = new HashMap<String, String>();
         metadata.put("ONLINE", "ONLINE");
         metadata.put("OFFLINE", "OFFLINE");
         metadata.put("DROPPED", "OFFLINE");
         metadata.put("IDLE", "OFFLINE");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("OFFLINE"))
-      {
+      } else if (state.equals("OFFLINE")) {
         Map<String, String> metadata = new HashMap<String, String>();
         metadata.put("ONLINE", "BOOTSTRAP");
         metadata.put("BOOTSTRAP", "BOOTSTRAP");
         metadata.put("DROPPED", "IDLE");
         metadata.put("IDLE", "IDLE");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("IDLE"))
-      {
+      } else if (state.equals("IDLE")) {
         Map<String, String> metadata = new HashMap<String, String>();
         metadata.put("ONLINE", "OFFLINE");
         metadata.put("BOOTSTRAP", "OFFLINE");
         metadata.put("OFFLINE", "OFFLINE");
         metadata.put("DROPPED", "DROPPED");
         record.setMapField(key, metadata);
-      }
-      else if (state.equals("ERROR"))
-      {
+      } else if (state.equals("ERROR")) {
         Map<String, String> metadata = new HashMap<String, String>();
         metadata.put("IDLE", "IDLE");
         record.setMapField(key, metadata);
@@ -1015,32 +802,27 @@ public class TestHelper
     stateTransitionPriorityList.add("IDLE-DROPPED");
     stateTransitionPriorityList.add("ERROR-IDLED");
     record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
-                        stateTransitionPriorityList);
+        stateTransitionPriorityList);
     return new StateModelDefinition(record);
   }
 
-  public static String znrecordToString(ZNRecord record)
-  {
+  public static String znrecordToString(ZNRecord record) {
     StringBuffer sb = new StringBuffer();
     sb.append(record.getId() + "\n");
     Map<String, String> simpleFields = record.getSimpleFields();
-    if (simpleFields != null)
-    {
+    if (simpleFields != null) {
       sb.append("simpleFields\n");
-      for (String key : simpleFields.keySet())
-      {
+      for (String key : simpleFields.keySet()) {
         sb.append("  " + key + "\t: " + simpleFields.get(key) + "\n");
       }
     }
 
     Map<String, List<String>> listFields = record.getListFields();
     sb.append("listFields\n");
-    for (String key : listFields.keySet())
-    {
+    for (String key : listFields.keySet()) {
       List<String> list = listFields.get(key);
       sb.append("  " + key + "\t: ");
-      for (String listValue : list)
-      {
+      for (String listValue : list) {
         sb.append(listValue + ", ");
       }
       sb.append("\n");
@@ -1048,12 +830,10 @@ public class TestHelper
 
     Map<String, Map<String, String>> mapFields = record.getMapFields();
     sb.append("mapFields\n");
-    for (String key : mapFields.keySet())
-    {
+    for (String key : mapFields.keySet()) {
       Map<String, String> map = mapFields.get(key);
       sb.append("  " + key + "\t: \n");
-      for (String mapKey : map.keySet())
-      {
+      for (String mapKey : map.keySet()) {
         sb.append("    " + mapKey + "\t: " + map.get(mapKey) + "\n");
       }
     }
@@ -1077,20 +857,17 @@ public class TestHelper
   }
 
   // debug code
-  public static String printHandlers(ZkTestManager manager)
-  {
+  public static String printHandlers(ZkTestManager manager) {
     StringBuilder sb = new StringBuilder();
     List<CallbackHandler> handlers = manager.getHandlers();
     sb.append(manager.getInstanceName() + " has " + handlers.size() + " cb-handlers. [");
 
-    for (int i = 0; i < handlers.size(); i++)
-    {
+    for (int i = 0; i < handlers.size(); i++) {
       CallbackHandler handler = handlers.get(i);
       String path = handler.getPath();
       sb.append(path.substring(manager.getClusterName().length() + 1) + ": "
           + handler.getListener());
-      if (i < (handlers.size() - 1))
-      {
+      if (i < (handlers.size() - 1)) {
         sb.append(", ");
       }
     }
@@ -1099,29 +876,29 @@ public class TestHelper
     return sb.toString();
   }
 
-  public static void printZkListeners(ZkClient client) throws  Exception{
+  public static void printZkListeners(ZkClient client) throws Exception {
     Map<String, Set<IZkDataListener>> datalisteners = ZkTestHelper.getZkDataListener(client);
     Map<String, Set<IZkChildListener>> childListeners = ZkTestHelper.getZkChildListener(client);
 
     System.out.println("dataListeners {");
     for (String path : datalisteners.keySet()) {
-        System.out.println("\t" + path + ": ");
-        Set<IZkDataListener> set = datalisteners.get(path);
-        for (IZkDataListener listener : set) {
-            CallbackHandler handler = (CallbackHandler)listener;
-            System.out.println("\t\t" + handler.getListener());
-        }
+      System.out.println("\t" + path + ": ");
+      Set<IZkDataListener> set = datalisteners.get(path);
+      for (IZkDataListener listener : set) {
+        CallbackHandler handler = (CallbackHandler) listener;
+        System.out.println("\t\t" + handler.getListener());
+      }
     }
     System.out.println("}");
 
     System.out.println("childListeners {");
     for (String path : childListeners.keySet()) {
-        System.out.println("\t" + path + ": ");
-        Set<IZkChildListener> set = childListeners.get(path);
-        for (IZkChildListener listener : set) {
-            CallbackHandler handler = (CallbackHandler)listener;
-            System.out.println("\t\t" + handler.getListener());
-        }
+      System.out.println("\t" + path + ": ");
+      Set<IZkChildListener> set = childListeners.get(path);
+      for (IZkChildListener listener : set) {
+        CallbackHandler handler = (CallbackHandler) listener;
+        System.out.println("\t\t" + handler.getListener());
+      }
     }
     System.out.println("}");
   }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestHierarchicalDataStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestHierarchicalDataStore.java b/helix-core/src/test/java/org/apache/helix/TestHierarchicalDataStore.java
index f87dbd0..da6add2 100644
--- a/helix-core/src/test/java/org/apache/helix/TestHierarchicalDataStore.java
+++ b/helix-core/src/test/java/org/apache/helix/TestHierarchicalDataStore.java
@@ -29,14 +29,13 @@ import java.io.FileFilter;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-
-public class TestHierarchicalDataStore extends ZkUnitTestBase
-{
+public class TestHierarchicalDataStore extends ZkUnitTestBase {
   protected static ZkClient _zkClientString = null;
 
-  @Test (groups = {"unitTest"})
-  public void testHierarchicalDataStore()
-  {
+  @Test(groups = {
+    "unitTest"
+  })
+  public void testHierarchicalDataStore() {
     _zkClientString = new ZkClient(ZK_ADDR, 1000, 3000);
 
     String path = "/tmp/testHierarchicalDataStore";
@@ -44,8 +43,8 @@ public class TestHierarchicalDataStore extends ZkUnitTestBase
     // _zkClient.setZkSerializer(new ZNRecordSerializer());
 
     _zkClientString.deleteRecursive(path);
-    HierarchicalDataHolder<ZNRecord> dataHolder = new HierarchicalDataHolder<ZNRecord>(
-        _zkClientString, path, filter);
+    HierarchicalDataHolder<ZNRecord> dataHolder =
+        new HierarchicalDataHolder<ZNRecord>(_zkClientString, path, filter);
     dataHolder.print();
     AssertJUnit.assertFalse(dataHolder.refreshData());
 
@@ -65,21 +64,19 @@ public class TestHierarchicalDataStore extends ZkUnitTestBase
     add(path + "/child1" + "/grandchild2", "grand child 2 data");
     AssertJUnit.assertTrue(dataHolder.refreshData());
     dataHolder.print();
-    
+
     AssertJUnit.assertFalse(dataHolder.refreshData());
-    
+
     set(path + "/child1", "new child 1 data");
     AssertJUnit.assertTrue(dataHolder.refreshData());
     dataHolder.print();
   }
 
-  private void set(String path, String data)
-  {
+  private void set(String path, String data) {
     _zkClientString.writeData(path, data);
   }
 
-  private void add(String path, String data)
-  {
+  private void add(String path, String data) {
     _zkClientString.createPersistent(path, true);
     _zkClientString.writeData(path, data);
   }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestListenerCallback.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestListenerCallback.java b/helix-core/src/test/java/org/apache/helix/TestListenerCallback.java
index 829be06..77bb19d 100644
--- a/helix-core/src/test/java/org/apache/helix/TestListenerCallback.java
+++ b/helix-core/src/test/java/org/apache/helix/TestListenerCallback.java
@@ -28,106 +28,108 @@ import org.apache.helix.model.InstanceConfig;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-
-public class TestListenerCallback extends ZkUnitTestBase 
-{
-	class TestListener implements InstanceConfigChangeListener, ScopedConfigChangeListener
-	{
-		boolean _instanceConfigChanged = false;
-		boolean _configChanged = false;
-
-		@Override
-        public void onConfigChange(List<HelixProperty> configs, NotificationContext context) {
-			_configChanged = true;
-			System.out.println("onConfigChange invoked: " + configs.size() + ", " + configs);
-        }
-
-		@Override
-        public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs,
-                NotificationContext context) {
-			_instanceConfigChanged = true;
-			System.out.println("onInstanceConfigChange invoked: " + instanceConfigs);
-        }
-
-	}
-
-	@Test
-	public void testBasic() throws Exception
-	{
-	    // Logger.getRootLogger().setLevel(Level.INFO);
-	    String className = TestHelper.getTestClassName();
-	    String methodName = TestHelper.getTestMethodName();
-	    String clusterName = className + "_" + methodName;
-	    int n = 2;
-
-	    System.out.println("START " + clusterName + " at "
-	        + new Date(System.currentTimeMillis()));
-
-	    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
-                "localhost", // participant name prefix
-                "TestDB", // resource name prefix
-                1, // resources
-                32, // partitions per resource
-                n, // number of nodes
-                2, // replicas
-                "MasterSlave",
-                true); // do rebalance
-
-	    HelixManager manager = HelixManagerFactory.getZKHelixManager(clusterName, "localhost", InstanceType.SPECTATOR, ZK_ADDR);
-
-	    manager.connect();
-
-	    TestListener listener = new TestListener();
-	    listener._instanceConfigChanged = false;
-	    manager.addInstanceConfigChangeListener(listener);
-	    Assert.assertTrue(listener._instanceConfigChanged, "Should get initial instanceConfig callback invoked");
-
-	    listener._configChanged = false;
-	    manager.addConfigChangeListener(listener, ConfigScopeProperty.CLUSTER);
-	    Assert.assertTrue(listener._configChanged, "Should get initial clusterConfig callback invoked");
-
-	    listener._configChanged = false;
-	    manager.addConfigChangeListener(listener, ConfigScopeProperty.RESOURCE);
-	    Assert.assertTrue(listener._configChanged, "Should get initial resourceConfig callback invoked");
-
-	    // test change content
-	    HelixDataAccessor accessor = manager.getHelixDataAccessor();
-	    Builder keyBuilder = accessor.keyBuilder();
-	    String instanceName = "localhost_12918";
-	    HelixProperty value = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
-	    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
-	    listener._instanceConfigChanged = false;
-	    accessor.setProperty(keyBuilder.instanceConfig(instanceName), value);
-	    Thread.sleep(1000);	// wait zk callback
-	    Assert.assertTrue(listener._instanceConfigChanged, "Should get instanceConfig callback invoked since we change instanceConfig");
-
-	    value = accessor.getProperty(keyBuilder.clusterConfig());
-	    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
-	    listener._configChanged = false;
-	    accessor.setProperty(keyBuilder.clusterConfig(), value);
-	    Thread.sleep(1000);	// wait zk callback
-	    Assert.assertTrue(listener._configChanged, "Should get clusterConfig callback invoked since we change clusterConfig");
-
-	    String resourceName = "TestDB_0";
-	    value = new HelixProperty(resourceName);
-	    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
-	    listener._configChanged = false;
-	    accessor.setProperty(keyBuilder.resourceConfig(resourceName), value);
-	    Thread.sleep(1000);	// wait zk callback
-	    Assert.assertTrue(listener._configChanged, "Should get resourceConfig callback invoked since we add resourceConfig");
-
-	    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
-	    listener._configChanged = false;
-	    accessor.setProperty(keyBuilder.resourceConfig(resourceName), value);
-	    Thread.sleep(1000);	// wait zk callback
-	    Assert.assertTrue(listener._configChanged, "Should get resourceConfig callback invoked since we change resourceConfig");
-
-	    listener._configChanged = false;
-	    accessor.removeProperty(keyBuilder.resourceConfig(resourceName));
-	    Thread.sleep(1000);	// wait zk callback
-	    Assert.assertTrue(listener._configChanged, "Should get resourceConfig callback invoked since we delete resourceConfig");
-
-	    System.out.println("END " + clusterName + " at "
-	            + new Date(System.currentTimeMillis()));
-	}
-}
\ No newline at end of file
+public class TestListenerCallback extends ZkUnitTestBase {
+  class TestListener implements InstanceConfigChangeListener, ScopedConfigChangeListener {
+    boolean _instanceConfigChanged = false;
+    boolean _configChanged = false;
+
+    @Override
+    public void onConfigChange(List<HelixProperty> configs, NotificationContext context) {
+      _configChanged = true;
+      System.out.println("onConfigChange invoked: " + configs.size() + ", " + configs);
+    }
+
+    @Override
+    public void onInstanceConfigChange(List<InstanceConfig> instanceConfigs,
+        NotificationContext context) {
+      _instanceConfigChanged = true;
+      System.out.println("onInstanceConfigChange invoked: " + instanceConfigs);
+    }
+
+  }
+
+  @Test
+  public void testBasic() throws Exception {
+    // Logger.getRootLogger().setLevel(Level.INFO);
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+    int n = 2;
+
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        32, // partitions per resource
+        n, // number of nodes
+        2, // replicas
+        "MasterSlave", true); // do rebalance
+
+    HelixManager manager =
+        HelixManagerFactory.getZKHelixManager(clusterName, "localhost", InstanceType.SPECTATOR,
+            ZK_ADDR);
+
+    manager.connect();
+
+    TestListener listener = new TestListener();
+    listener._instanceConfigChanged = false;
+    manager.addInstanceConfigChangeListener(listener);
+    Assert.assertTrue(listener._instanceConfigChanged,
+        "Should get initial instanceConfig callback invoked");
+
+    listener._configChanged = false;
+    manager.addConfigChangeListener(listener, ConfigScopeProperty.CLUSTER);
+    Assert.assertTrue(listener._configChanged, "Should get initial clusterConfig callback invoked");
+
+    listener._configChanged = false;
+    manager.addConfigChangeListener(listener, ConfigScopeProperty.RESOURCE);
+    Assert
+        .assertTrue(listener._configChanged, "Should get initial resourceConfig callback invoked");
+
+    // test change content
+    HelixDataAccessor accessor = manager.getHelixDataAccessor();
+    Builder keyBuilder = accessor.keyBuilder();
+    String instanceName = "localhost_12918";
+    HelixProperty value = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
+    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
+    listener._instanceConfigChanged = false;
+    accessor.setProperty(keyBuilder.instanceConfig(instanceName), value);
+    Thread.sleep(1000); // wait zk callback
+    Assert.assertTrue(listener._instanceConfigChanged,
+        "Should get instanceConfig callback invoked since we change instanceConfig");
+
+    value = accessor.getProperty(keyBuilder.clusterConfig());
+    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
+    listener._configChanged = false;
+    accessor.setProperty(keyBuilder.clusterConfig(), value);
+    Thread.sleep(1000); // wait zk callback
+    Assert.assertTrue(listener._configChanged,
+        "Should get clusterConfig callback invoked since we change clusterConfig");
+
+    String resourceName = "TestDB_0";
+    value = new HelixProperty(resourceName);
+    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
+    listener._configChanged = false;
+    accessor.setProperty(keyBuilder.resourceConfig(resourceName), value);
+    Thread.sleep(1000); // wait zk callback
+    Assert.assertTrue(listener._configChanged,
+        "Should get resourceConfig callback invoked since we add resourceConfig");
+
+    value._record.setSimpleField("" + System.currentTimeMillis(), "newValue");
+    listener._configChanged = false;
+    accessor.setProperty(keyBuilder.resourceConfig(resourceName), value);
+    Thread.sleep(1000); // wait zk callback
+    Assert.assertTrue(listener._configChanged,
+        "Should get resourceConfig callback invoked since we change resourceConfig");
+
+    listener._configChanged = false;
+    accessor.removeProperty(keyBuilder.resourceConfig(resourceName));
+    Thread.sleep(1000); // wait zk callback
+    Assert.assertTrue(listener._configChanged,
+        "Should get resourceConfig callback invoked since we delete resourceConfig");
+
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestParticipantHealthReportCollectorImpl.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestParticipantHealthReportCollectorImpl.java b/helix-core/src/test/java/org/apache/helix/TestParticipantHealthReportCollectorImpl.java
index 4428fa2..fe4c688 100644
--- a/helix-core/src/test/java/org/apache/helix/TestParticipantHealthReportCollectorImpl.java
+++ b/helix-core/src/test/java/org/apache/helix/TestParticipantHealthReportCollectorImpl.java
@@ -28,46 +28,51 @@ import org.testng.annotations.Test;
 
 public class TestParticipantHealthReportCollectorImpl {
 
-	protected ParticipantHealthReportCollectorImpl _providerImpl;
-	protected ParticipantHealthReportTask _providerTask;
-	protected HelixManager _manager;
-	protected MockHealthReportProvider _mockProvider;
-	
-	 @BeforeMethod (groups = {"unitTest"})
-	public void setup()
-	{
-		 _providerImpl = new ParticipantHealthReportCollectorImpl(new MockManager(), "instance_123");
-		 _providerTask = new ParticipantHealthReportTask(_providerImpl);
-		 _mockProvider = new MockHealthReportProvider();
-	}
-	
-	 @Test (groups = {"unitTest"})
-	  public void testStart() throws Exception
-	  {
-	   _providerTask.start();
-	   _providerTask.start();
-	  }
-	 
-	 @Test (groups = {"unitTest"})
-	  public void testStop() throws Exception
-	  {
-	   _providerTask.stop();
-	   _providerTask.stop();
-	  }
-	 
-	 @Test (groups = {"unitTest"})
-	 public void testAddProvider() throws Exception 
-	 {
-		 _providerImpl.removeHealthReportProvider(_mockProvider);
-		 _providerImpl.addHealthReportProvider(_mockProvider);
-		 _providerImpl.addHealthReportProvider(_mockProvider);
-	 }
-	 
-	 @Test (groups = {"unitTest"})
-	 public void testRemoveProvider() throws Exception
-	 {
-		 _providerImpl.addHealthReportProvider(_mockProvider);
-		 _providerImpl.removeHealthReportProvider(_mockProvider);
-		 _providerImpl.removeHealthReportProvider(_mockProvider);
-	 }
+  protected ParticipantHealthReportCollectorImpl _providerImpl;
+  protected ParticipantHealthReportTask _providerTask;
+  protected HelixManager _manager;
+  protected MockHealthReportProvider _mockProvider;
+
+  @BeforeMethod(groups = {
+    "unitTest"
+  })
+  public void setup() {
+    _providerImpl = new ParticipantHealthReportCollectorImpl(new MockManager(), "instance_123");
+    _providerTask = new ParticipantHealthReportTask(_providerImpl);
+    _mockProvider = new MockHealthReportProvider();
+  }
+
+  @Test(groups = {
+    "unitTest"
+  })
+  public void testStart() throws Exception {
+    _providerTask.start();
+    _providerTask.start();
+  }
+
+  @Test(groups = {
+    "unitTest"
+  })
+  public void testStop() throws Exception {
+    _providerTask.stop();
+    _providerTask.stop();
+  }
+
+  @Test(groups = {
+    "unitTest"
+  })
+  public void testAddProvider() throws Exception {
+    _providerImpl.removeHealthReportProvider(_mockProvider);
+    _providerImpl.addHealthReportProvider(_mockProvider);
+    _providerImpl.addHealthReportProvider(_mockProvider);
+  }
+
+  @Test(groups = {
+    "unitTest"
+  })
+  public void testRemoveProvider() throws Exception {
+    _providerImpl.addHealthReportProvider(_mockProvider);
+    _providerImpl.removeHealthReportProvider(_mockProvider);
+    _providerImpl.removeHealthReportProvider(_mockProvider);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestPerfCounters.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestPerfCounters.java b/helix-core/src/test/java/org/apache/helix/TestPerfCounters.java
index 2a7aa5e..d95bff8 100644
--- a/helix-core/src/test/java/org/apache/helix/TestPerfCounters.java
+++ b/helix-core/src/test/java/org/apache/helix/TestPerfCounters.java
@@ -19,59 +19,51 @@ package org.apache.helix;
  * under the License.
  */
 
-
 import org.apache.helix.healthcheck.DefaultPerfCounters;
 import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
-
 public class TestPerfCounters {
 
-	final String INSTANCE_NAME = "instance_123";
-    final long AVAILABLE_CPUS = 1;
-    final long FREE_PHYSICAL_MEMORY = 2;
-    final long FREE_JVM_MEMORY = 3;
-    final long TOTAL_JVM_MEMORY = 4;
-    final double AVERAGE_SYSTEM_LOAD = 5;
+  final String INSTANCE_NAME = "instance_123";
+  final long AVAILABLE_CPUS = 1;
+  final long FREE_PHYSICAL_MEMORY = 2;
+  final long FREE_JVM_MEMORY = 3;
+  final long TOTAL_JVM_MEMORY = 4;
+  final double AVERAGE_SYSTEM_LOAD = 5;
 
-	DefaultPerfCounters _perfCounters;
+  DefaultPerfCounters _perfCounters;
 
-	@BeforeTest ()
-	public void setup()
-	{
-		_perfCounters = new DefaultPerfCounters(INSTANCE_NAME, AVAILABLE_CPUS,
-				FREE_PHYSICAL_MEMORY, FREE_JVM_MEMORY, TOTAL_JVM_MEMORY,
-				AVERAGE_SYSTEM_LOAD);
-	}
+  @BeforeTest()
+  public void setup() {
+    _perfCounters =
+        new DefaultPerfCounters(INSTANCE_NAME, AVAILABLE_CPUS, FREE_PHYSICAL_MEMORY,
+            FREE_JVM_MEMORY, TOTAL_JVM_MEMORY, AVERAGE_SYSTEM_LOAD);
+  }
 
-	 @Test ()
-	 public void testGetAvailableCpus()
-	 {
-		 AssertJUnit.assertEquals(AVAILABLE_CPUS,_perfCounters.getAvailableCpus());
-	 }
+  @Test()
+  public void testGetAvailableCpus() {
+    AssertJUnit.assertEquals(AVAILABLE_CPUS, _perfCounters.getAvailableCpus());
+  }
 
-	 @Test ()
-	 public void testGetAverageSystemLoad()
-	 {
-		 AssertJUnit.assertEquals(AVERAGE_SYSTEM_LOAD,_perfCounters.getAverageSystemLoad());
-	 }
+  @Test()
+  public void testGetAverageSystemLoad() {
+    AssertJUnit.assertEquals(AVERAGE_SYSTEM_LOAD, _perfCounters.getAverageSystemLoad());
+  }
 
-	 @Test ()
-	 public void testGetTotalJvmMemory()
-	 {
-		 AssertJUnit.assertEquals(TOTAL_JVM_MEMORY,_perfCounters.getTotalJvmMemory());
-	 }
+  @Test()
+  public void testGetTotalJvmMemory() {
+    AssertJUnit.assertEquals(TOTAL_JVM_MEMORY, _perfCounters.getTotalJvmMemory());
+  }
 
-	 @Test ()
-	 public void testGetFreeJvmMemory()
-	 {
-		 AssertJUnit.assertEquals(FREE_JVM_MEMORY,_perfCounters.getFreeJvmMemory());
-	 }
+  @Test()
+  public void testGetFreeJvmMemory() {
+    AssertJUnit.assertEquals(FREE_JVM_MEMORY, _perfCounters.getFreeJvmMemory());
+  }
 
-	 @Test ()
-	 public void testGetFreePhysicalMemory()
-	 {
-		 AssertJUnit.assertEquals(FREE_PHYSICAL_MEMORY,_perfCounters.getFreePhysicalMemory());
-	 }
+  @Test()
+  public void testGetFreePhysicalMemory() {
+    AssertJUnit.assertEquals(FREE_PHYSICAL_MEMORY, _perfCounters.getFreePhysicalMemory());
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestPerformanceHealthReportProvider.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestPerformanceHealthReportProvider.java b/helix-core/src/test/java/org/apache/helix/TestPerformanceHealthReportProvider.java
index fe4f939..60e1bcb 100644
--- a/helix-core/src/test/java/org/apache/helix/TestPerformanceHealthReportProvider.java
+++ b/helix-core/src/test/java/org/apache/helix/TestPerformanceHealthReportProvider.java
@@ -31,138 +31,130 @@ import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-
 public class TestPerformanceHealthReportProvider {
 
-	 protected static final String CLUSTER_NAME = "TestCluster";
-	 protected final String STAT_NAME = "Stat_123";
-	 protected final String PARTITION_NAME = "Partition_456";
-	 protected final String FAKE_STAT_NAME = "Stat_ABC";
-	 protected final String FAKE_PARTITION_NAME = "Partition_DEF";
-	 protected final String STORED_STAT = "789";
-	 protected final String INSTANCE_NAME = "instance:1";
-
-	PerformanceHealthReportProvider _healthProvider;
-	MockManager _helixManager;
-
-	public void incrementPartitionStat() throws Exception
-	{
-		_helixManager = new MockManager(CLUSTER_NAME);
-		_healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
-	}
-
-	public void transmitReport() throws Exception
-	{
-		_helixManager = new MockManager(CLUSTER_NAME);
-		 Map<String, Map<String, String>> partitionReport = _healthProvider
-	                .getRecentPartitionHealthReport();
-		 ZNRecord record = new ZNRecord(_healthProvider.getReportName());
-		 if (partitionReport != null) {
-         	record.setMapFields(partitionReport);
-         }
-		 HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
-
-		 Builder keyBuilder = accessor.keyBuilder();
-		 accessor.setProperty(keyBuilder.healthReport(INSTANCE_NAME, record.getId()), new HealthStat(record));
-	}
-
-	@BeforeMethod ()
-	public void setup()
-	{
-		_healthProvider = new PerformanceHealthReportProvider();
-	}
-
-	 @Test ()
-	  public void testGetRecentHealthReports() throws Exception
-	  {
-		 _healthProvider.getRecentHealthReport();
-		 _healthProvider.getRecentPartitionHealthReport();
-	  }
-
-	 @Test ()
-	 public void testIncrementPartitionStat() throws Exception
-	 {
-		 //stat does not exist yet
-		 _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
-		 transmitReport();
-		 //stat does exist
-		 _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
-		 transmitReport();
-		 String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
-		 AssertJUnit.assertEquals(2.0, Double.parseDouble(retrievedStat));
-
-		 //set to some other value
-		 _healthProvider.submitPartitionStat(STAT_NAME, PARTITION_NAME, STORED_STAT);
-		 transmitReport();
-		 _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
-		 transmitReport();
-		 retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
-		 AssertJUnit.assertEquals(Double.parseDouble(retrievedStat), Double.parseDouble(STORED_STAT)+1);
-	 }
-
-	 @Test ()
-	 public void testSetGetPartitionStat() throws Exception
-	 {
-		 _healthProvider.submitPartitionStat(STAT_NAME, PARTITION_NAME, STORED_STAT);
-		 transmitReport();
-		 String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
-		 //check on correct retrieval for real stat, real partition
-		 AssertJUnit.assertEquals(STORED_STAT, retrievedStat);
-
-		 //real stat, fake partition
-		 retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, FAKE_PARTITION_NAME);
-		 AssertJUnit.assertNull(retrievedStat);
-
-		 //fake stat, real partition
-		 retrievedStat = _healthProvider.getPartitionStat(FAKE_STAT_NAME, PARTITION_NAME);
-		 AssertJUnit.assertNull(retrievedStat);
-
-		 //fake stat, fake partition
-		 retrievedStat = _healthProvider.getPartitionStat(FAKE_STAT_NAME, FAKE_PARTITION_NAME);
-		 AssertJUnit.assertNull(retrievedStat);
-	 }
-
-	 @Test ()
-	 public void testGetPartitionHealthReport() throws Exception
-	 {
-		 //test empty map case
-		 Map<String, Map<String, String>> resultMap = _healthProvider.getRecentPartitionHealthReport();
-		 AssertJUnit.assertEquals(resultMap.size(), 0);
-
-		 //test non-empty case
-		 testSetGetPartitionStat();
-		 resultMap = _healthProvider.getRecentPartitionHealthReport();
-		 //check contains 1 stat
-		 AssertJUnit.assertEquals(1, resultMap.size());
-		 //check contains STAT_NAME STAT
-		 AssertJUnit.assertTrue(resultMap.keySet().contains(STAT_NAME));
-		 Map<String, String> statMap = resultMap.get(STAT_NAME);
-		 //check statMap has size 1
-		 AssertJUnit.assertEquals(1, statMap.size());
-		 //check contains PARTITION_NAME
-		 AssertJUnit.assertTrue(statMap.keySet().contains(PARTITION_NAME));
-		 //check stored val
-		 String statVal = statMap.get(PARTITION_NAME);
-		 AssertJUnit.assertEquals(statVal, STORED_STAT);
-	 }
-
-	 @Test ()
-	 public void testPartitionStatReset() throws Exception
-	 {
-		 incrementPartitionStat();
-		 //ensure stat appears
-		 String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
-		 AssertJUnit.assertEquals(1.0, Double.parseDouble(retrievedStat));
-		 //reset partition stats
-		 _healthProvider.resetStats();
-		 transmitReport();
-		 retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
-		 AssertJUnit.assertEquals(null, retrievedStat);
-	 }
-
-	 @Test ()
-	  public void testGetReportName() throws Exception
-	  {
-		 _healthProvider.getReportName();
-	  }
+  protected static final String CLUSTER_NAME = "TestCluster";
+  protected final String STAT_NAME = "Stat_123";
+  protected final String PARTITION_NAME = "Partition_456";
+  protected final String FAKE_STAT_NAME = "Stat_ABC";
+  protected final String FAKE_PARTITION_NAME = "Partition_DEF";
+  protected final String STORED_STAT = "789";
+  protected final String INSTANCE_NAME = "instance:1";
+
+  PerformanceHealthReportProvider _healthProvider;
+  MockManager _helixManager;
+
+  public void incrementPartitionStat() throws Exception {
+    _helixManager = new MockManager(CLUSTER_NAME);
+    _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
+  }
+
+  public void transmitReport() throws Exception {
+    _helixManager = new MockManager(CLUSTER_NAME);
+    Map<String, Map<String, String>> partitionReport =
+        _healthProvider.getRecentPartitionHealthReport();
+    ZNRecord record = new ZNRecord(_healthProvider.getReportName());
+    if (partitionReport != null) {
+      record.setMapFields(partitionReport);
+    }
+    HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
+
+    Builder keyBuilder = accessor.keyBuilder();
+    accessor.setProperty(keyBuilder.healthReport(INSTANCE_NAME, record.getId()), new HealthStat(
+        record));
+  }
+
+  @BeforeMethod()
+  public void setup() {
+    _healthProvider = new PerformanceHealthReportProvider();
+  }
+
+  @Test()
+  public void testGetRecentHealthReports() throws Exception {
+    _healthProvider.getRecentHealthReport();
+    _healthProvider.getRecentPartitionHealthReport();
+  }
+
+  @Test()
+  public void testIncrementPartitionStat() throws Exception {
+    // stat does not exist yet
+    _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
+    transmitReport();
+    // stat does exist
+    _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
+    transmitReport();
+    String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
+    AssertJUnit.assertEquals(2.0, Double.parseDouble(retrievedStat));
+
+    // set to some other value
+    _healthProvider.submitPartitionStat(STAT_NAME, PARTITION_NAME, STORED_STAT);
+    transmitReport();
+    _healthProvider.incrementPartitionStat(STAT_NAME, PARTITION_NAME);
+    transmitReport();
+    retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
+    AssertJUnit
+        .assertEquals(Double.parseDouble(retrievedStat), Double.parseDouble(STORED_STAT) + 1);
+  }
+
+  @Test()
+  public void testSetGetPartitionStat() throws Exception {
+    _healthProvider.submitPartitionStat(STAT_NAME, PARTITION_NAME, STORED_STAT);
+    transmitReport();
+    String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
+    // check on correct retrieval for real stat, real partition
+    AssertJUnit.assertEquals(STORED_STAT, retrievedStat);
+
+    // real stat, fake partition
+    retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, FAKE_PARTITION_NAME);
+    AssertJUnit.assertNull(retrievedStat);
+
+    // fake stat, real partition
+    retrievedStat = _healthProvider.getPartitionStat(FAKE_STAT_NAME, PARTITION_NAME);
+    AssertJUnit.assertNull(retrievedStat);
+
+    // fake stat, fake partition
+    retrievedStat = _healthProvider.getPartitionStat(FAKE_STAT_NAME, FAKE_PARTITION_NAME);
+    AssertJUnit.assertNull(retrievedStat);
+  }
+
+  @Test()
+  public void testGetPartitionHealthReport() throws Exception {
+    // test empty map case
+    Map<String, Map<String, String>> resultMap = _healthProvider.getRecentPartitionHealthReport();
+    AssertJUnit.assertEquals(resultMap.size(), 0);
+
+    // test non-empty case
+    testSetGetPartitionStat();
+    resultMap = _healthProvider.getRecentPartitionHealthReport();
+    // check contains 1 stat
+    AssertJUnit.assertEquals(1, resultMap.size());
+    // check contains STAT_NAME STAT
+    AssertJUnit.assertTrue(resultMap.keySet().contains(STAT_NAME));
+    Map<String, String> statMap = resultMap.get(STAT_NAME);
+    // check statMap has size 1
+    AssertJUnit.assertEquals(1, statMap.size());
+    // check contains PARTITION_NAME
+    AssertJUnit.assertTrue(statMap.keySet().contains(PARTITION_NAME));
+    // check stored val
+    String statVal = statMap.get(PARTITION_NAME);
+    AssertJUnit.assertEquals(statVal, STORED_STAT);
+  }
+
+  @Test()
+  public void testPartitionStatReset() throws Exception {
+    incrementPartitionStat();
+    // ensure stat appears
+    String retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
+    AssertJUnit.assertEquals(1.0, Double.parseDouble(retrievedStat));
+    // reset partition stats
+    _healthProvider.resetStats();
+    transmitReport();
+    retrievedStat = _healthProvider.getPartitionStat(STAT_NAME, PARTITION_NAME);
+    AssertJUnit.assertEquals(null, retrievedStat);
+  }
+
+  @Test()
+  public void testGetReportName() throws Exception {
+    _healthProvider.getReportName();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestPropertyPathConfig.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestPropertyPathConfig.java b/helix-core/src/test/java/org/apache/helix/TestPropertyPathConfig.java
index 8340e86..c25bd32 100644
--- a/helix-core/src/test/java/org/apache/helix/TestPropertyPathConfig.java
+++ b/helix-core/src/test/java/org/apache/helix/TestPropertyPathConfig.java
@@ -22,34 +22,32 @@ package org.apache.helix;
 import org.testng.AssertJUnit;
 import org.testng.annotations.Test;
 
-
-
 @Test
-public class TestPropertyPathConfig
-{
+public class TestPropertyPathConfig {
   @Test
-  public void testGetPath()
-  {
+  public void testGetPath() {
     String actual;
     actual = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, "test_cluster");
     AssertJUnit.assertEquals(actual, "/test_cluster/IDEALSTATES");
-    actual = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, "test_cluster","resource");
+    actual = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, "test_cluster", "resource");
     AssertJUnit.assertEquals(actual, "/test_cluster/IDEALSTATES/resource");
 
-    
-    actual = PropertyPathConfig.getPath(PropertyType.INSTANCES, "test_cluster","instanceName1");
+    actual = PropertyPathConfig.getPath(PropertyType.INSTANCES, "test_cluster", "instanceName1");
     AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1");
 
-    actual = PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, "test_cluster","instanceName1");
+    actual =
+        PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, "test_cluster", "instanceName1");
     AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1/CURRENTSTATES");
-    actual = PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, "test_cluster","instanceName1","sessionId");
-    AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1/CURRENTSTATES/sessionId");
-    
+    actual =
+        PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, "test_cluster", "instanceName1",
+            "sessionId");
+    AssertJUnit.assertEquals(actual,
+        "/test_cluster/INSTANCES/instanceName1/CURRENTSTATES/sessionId");
+
     actual = PropertyPathConfig.getPath(PropertyType.CONTROLLER, "test_cluster");
     AssertJUnit.assertEquals(actual, "/test_cluster/CONTROLLER");
     actual = PropertyPathConfig.getPath(PropertyType.MESSAGES_CONTROLLER, "test_cluster");
     AssertJUnit.assertEquals(actual, "/test_cluster/CONTROLLER/MESSAGES");
 
-    
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestRelayIdealStateCalculator.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestRelayIdealStateCalculator.java b/helix-core/src/test/java/org/apache/helix/TestRelayIdealStateCalculator.java
index 8ecfc69..ca58659 100644
--- a/helix-core/src/test/java/org/apache/helix/TestRelayIdealStateCalculator.java
+++ b/helix-core/src/test/java/org/apache/helix/TestRelayIdealStateCalculator.java
@@ -30,59 +30,53 @@ import org.apache.helix.tools.IdealStateCalculatorForEspressoRelay;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-
-public class TestRelayIdealStateCalculator
-{
-  @Test ()
-  public void testEspressoStorageClusterIdealState() throws Exception
-  {
+public class TestRelayIdealStateCalculator {
+  @Test()
+  public void testEspressoStorageClusterIdealState() throws Exception {
     testEspressoStorageClusterIdealState(15, 9, 3);
     testEspressoStorageClusterIdealState(15, 6, 3);
     testEspressoStorageClusterIdealState(15, 6, 2);
-    testEspressoStorageClusterIdealState(6,  4, 2);
+    testEspressoStorageClusterIdealState(6, 4, 2);
   }
-  public void testEspressoStorageClusterIdealState(int partitions, int nodes, int replica) throws Exception
-  {
+
+  public void testEspressoStorageClusterIdealState(int partitions, int nodes, int replica)
+      throws Exception {
     List<String> storageNodes = new ArrayList<String>();
-    for(int i = 0;i < partitions; i++)
-    {
+    for (int i = 0; i < partitions; i++) {
       storageNodes.add("localhost:123" + i);
     }
-    
+
     List<String> relays = new ArrayList<String>();
-    for(int i = 0;i < nodes; i++)
-    {
+    for (int i = 0; i < nodes; i++) {
       relays.add("relay:123" + i);
     }
-    
-    IdealState idealstate = IdealStateCalculatorForEspressoRelay.calculateRelayIdealState(storageNodes, relays, "TEST", replica, "Leader", "Standby", "LeaderStandby");
-    
-    Assert.assertEquals(idealstate.getRecord().getListFields().size(), idealstate.getRecord().getMapFields().size());
-    
+
+    IdealState idealstate =
+        IdealStateCalculatorForEspressoRelay.calculateRelayIdealState(storageNodes, relays, "TEST",
+            replica, "Leader", "Standby", "LeaderStandby");
+
+    Assert.assertEquals(idealstate.getRecord().getListFields().size(), idealstate.getRecord()
+        .getMapFields().size());
+
     Map<String, Integer> countMap = new TreeMap<String, Integer>();
-    for(String key  : idealstate.getRecord().getListFields().keySet())
-    {
-      Assert.assertEquals(idealstate.getRecord().getListFields().get(key).size(), idealstate.getRecord().getMapFields().get(key).size());
+    for (String key : idealstate.getRecord().getListFields().keySet()) {
+      Assert.assertEquals(idealstate.getRecord().getListFields().get(key).size(), idealstate
+          .getRecord().getMapFields().get(key).size());
       List<String> list = idealstate.getRecord().getListFields().get(key);
       Map<String, String> map = idealstate.getRecord().getMapFields().get(key);
       Assert.assertEquals(list.size(), replica);
-      for(String val : list)
-      {
-        if(!countMap.containsKey(val))
-        {
+      for (String val : list) {
+        if (!countMap.containsKey(val)) {
           countMap.put(val, 1);
-        }
-        else
-        {
+        } else {
           countMap.put(val, countMap.get(val) + 1);
         }
         Assert.assertTrue(map.containsKey(val));
       }
     }
-    for(String nodeName : countMap.keySet())
-    {
+    for (String nodeName : countMap.keySet()) {
       Assert.assertTrue(countMap.get(nodeName) <= partitions * replica / nodes + 1);
-      //System.out.println(nodeName + " " + countMap.get(nodeName));
+      // System.out.println(nodeName + " " + countMap.get(nodeName));
     }
     System.out.println();
   }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-core/src/test/java/org/apache/helix/TestRoutingTable.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestRoutingTable.java b/helix-core/src/test/java/org/apache/helix/TestRoutingTable.java
index cf1bc5c..73a30e7 100644
--- a/helix-core/src/test/java/org/apache/helix/TestRoutingTable.java
+++ b/helix-core/src/test/java/org/apache/helix/TestRoutingTable.java
@@ -40,39 +40,34 @@ import org.testng.AssertJUnit;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-
-public class TestRoutingTable
-{
+public class TestRoutingTable {
   NotificationContext changeContext = null;
 
   @BeforeClass()
-  public synchronized void setup()
-  {
+  public synchronized void setup() {
 
-    final String[] array = new String[] { "localhost_8900", "localhost_8901" };
+    final String[] array = new String[] {
+        "localhost_8900", "localhost_8901"
+    };
     HelixManager manager = new Mocks.MockManager() {
       private MockAccessor _mockAccessor;
 
       @Override
-//      public DataAccessor getDataAccessor()
-      public HelixDataAccessor getHelixDataAccessor()
-      {
-        if (_mockAccessor == null)
-        {
+      // public DataAccessor getDataAccessor()
+      public HelixDataAccessor getHelixDataAccessor() {
+        if (_mockAccessor == null) {
           _mockAccessor = new Mocks.MockAccessor() {
             @SuppressWarnings("unchecked")
             @Override
             public <T extends HelixProperty> List<T> getChildValues(PropertyKey key)
-//            public List<ZNRecord> getChildValues(PropertyType type, String... keys)
+            // public List<ZNRecord> getChildValues(PropertyType type, String... keys)
             {
               PropertyType type = key.getType();
               String[] keys = key.getParams();
               if (type == PropertyType.CONFIGS && keys != null && keys.length > 1
-                  && keys[1].equalsIgnoreCase(ConfigScopeProperty.PARTICIPANT.toString()))
-              {
+                  && keys[1].equalsIgnoreCase(ConfigScopeProperty.PARTICIPANT.toString())) {
                 List<InstanceConfig> configs = new ArrayList<InstanceConfig>();
-                for (String instanceName : array)
-                {
+                for (String instanceName : array) {
                   InstanceConfig config = new InstanceConfig(instanceName);
                   String[] splits = instanceName.split("_");
                   config.setHostName(splits[0]);
@@ -92,8 +87,7 @@ public class TestRoutingTable
   }
 
   @Test()
-  public void testNullAndEmpty()
-  {
+  public void testNullAndEmpty() {
 
     RoutingTableProvider routingTable = new RoutingTableProvider();
     routingTable.onExternalViewChange(null, changeContext);
@@ -103,8 +97,7 @@ public class TestRoutingTable
   }
 
   @Test()
-  public void testSimple()
-  {
+  public void testSimple() {
     List<InstanceConfig> instances;
     RoutingTableProvider routingTable = new RoutingTableProvider();
     ZNRecord record = new ZNRecord("TESTDB");
@@ -145,8 +138,7 @@ public class TestRoutingTable
   }
 
   @Test()
-  public void testStateUnitGroupDeletion()
-  {
+  public void testStateUnitGroupDeletion() {
     List<InstanceConfig> instances;
     RoutingTableProvider routingTable = new RoutingTableProvider();
 
@@ -169,8 +161,7 @@ public class TestRoutingTable
   }
 
   @Test()
-  public void testGetInstanceForAllStateUnits()
-  {
+  public void testGetInstanceForAllStateUnits() {
     List<InstanceConfig> instancesList;
     Set<InstanceConfig> instancesSet;
     InstanceConfig instancesArray[];
@@ -213,29 +204,24 @@ public class TestRoutingTable
   }
 
   @Test()
-  public void testMultiThread() throws Exception
-  {
+  public void testMultiThread() throws Exception {
     final RoutingTableProvider routingTable = new RoutingTableProvider();
     List<ExternalView> externalViewList = new ArrayList<ExternalView>();
     ZNRecord record = new ZNRecord("TESTDB");
-    for (int i = 0; i < 1000; i++)
-    {
+    for (int i = 0; i < 1000; i++) {
       add(record, "TESTDB_" + i, "localhost_8900", "MASTER");
     }
     externalViewList.add(new ExternalView(record));
     routingTable.onExternalViewChange(externalViewList, changeContext);
     Callable<Boolean> runnable = new Callable<Boolean>() {
       @Override
-      public Boolean call() throws Exception
-      {
+      public Boolean call() throws Exception {
 
-        try
-        {
+        try {
           int count = 0;
-          while (count < 100)
-          {
-            List<InstanceConfig> instancesList = routingTable.getInstances("TESTDB", "TESTDB_0",
-                "MASTER");
+          while (count < 100) {
+            List<InstanceConfig> instancesList =
+                routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
             AssertJUnit.assertEquals(instancesList.size(), 1);
             // System.out.println(System.currentTimeMillis() + "-->"
             // + instancesList.size());
@@ -244,8 +230,7 @@ public class TestRoutingTable
 
             count++;
           }
-        } catch (InterruptedException e)
-        {
+        } catch (InterruptedException e) {
           // e.printStackTrace();
         }
         return true;
@@ -254,13 +239,10 @@ public class TestRoutingTable
     ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
     Future<Boolean> submit = executor.submit(runnable);
     int count = 0;
-    while (count < 10)
-    {
-      try
-      {
+    while (count < 10) {
+      try {
         Thread.sleep(10);
-      } catch (InterruptedException e)
-      {
+      } catch (InterruptedException e) {
         e.printStackTrace();
       }
       routingTable.onExternalViewChange(externalViewList, changeContext);
@@ -272,11 +254,9 @@ public class TestRoutingTable
 
   }
 
-  private void add(ZNRecord record, String stateUnitKey, String instanceName, String state)
-  {
+  private void add(ZNRecord record, String stateUnitKey, String instanceName, String state) {
     Map<String, String> stateUnitKeyMap = record.getMapField(stateUnitKey);
-    if (stateUnitKeyMap == null)
-    {
+    if (stateUnitKeyMap == null) {
       stateUnitKeyMap = new HashMap<String, String>();
       record.setMapField(stateUnitKey, stateUnitKeyMap);
     }


Mime
View raw message