@@ -0,0 +1,2897 @@
+package org.apache.helix.integration.controller;%0A%0A/*%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Set;%0Aimport org.apache.helix.controller.GenericHelixController;%0Aimport org.apache.helix.ZkUnitTestBase;%0Aimport org.testng.Assert;%0Aimport org.testng.annotations.Test;%0A%0Apublic class TestGenericHelixControllerThreading extends ZkUnitTestBase %7B%0A%0A  private static final String EVENT_PROCESS_THREAD_NAME_PREFIX =%0A      %22GerenricHelixController-event_process%22;%0A%0A  //    Temporarily disabling the test as it's not stable when running under the entire mvn test suite.%0A  //    Some other crashed tests might cause this one to fail as controllers might not be gracefully%0A  //    shutdown%0A  @Test(enabled = false)%0A  public void testGenericHelixControllerThreadCount() throws Exception %7B%0A    System.out.println(%22testGenericHelixControllerThreadCount STARTs%22);%0A    final int numControllers = 100;%0A    ArrayList%3CGenericHelixController%3E controllers = createHelixControllers(numControllers);%0A    Assert.assertEquals(getThreadCountByNamePrefix(EVENT_PROCESS_THREAD_NAME_PREFIX), numControllers * 2);%0A%0A    int remainingExpectedEventProcessThreadsCount = numControllers * 2;%0A    for (GenericHelixController ctrl : controllers) %7B%0A      ctrl.shutdown();%0A      remainingExpectedEventProcessThreadsCount -= 2;%0A      Assert.assertEquals(getThreadCountByNamePrefix(EVENT_PROCESS_THREAD_NAME_PREFIX),%0A          remainingExpectedEventProcessThreadsCount);%0A    %7D%0A    System.out.println(%22testGenericHelixControllerThreadCount ENDs%22);%0A  %7D%0A%0A  private ArrayList%3CGenericHelixController%3E createHelixControllers(int count) %7B%0A    ArrayList%3CGenericHelixController%3E ret = new ArrayList%3C%3E();%0A    for (int i = 0; i %3C count; i++) %7B%0A      ret.add(new GenericHelixController());%0A    %7D%0A    return ret;%0A  %7D%0A%0A  private int getThreadCountByNamePrefix(String threadNamePrefix) %7B%0A    Set%3CThread%3E threadSet = Thread.getAllStackTraces().keySet();%0A    int eventThreadCount = 0;%0A    for (Thread t : threadSet) %7B%0A      if (t.getName().startsWith(threadNamePrefix)) %7B%0A        eventThreadCount += 1;%0A      %7D%0A    %7D%0A    return eventThreadCount;%0A  %7D%0A%0A%7D%0A

Add test for GenericHelixController thread leak