Search in sources :

Example 1 with GenericHelixController

use of org.apache.helix.controller.GenericHelixController in project helix by apache.

the class TestDistControllerElection method testControllerParticipant.

@Test()
public void testControllerParticipant() throws Exception {
    String className = getShortClassName();
    LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
    final String clusterName = CONTROLLER_CLUSTER_PREFIX + "_" + className + "_" + "testControllerParticipant";
    String path = "/" + clusterName;
    if (_gZkClient.exists(path)) {
        _gZkClient.deleteRecursively(path);
    }
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    final String controllerName = "controller_0";
    HelixManager manager = new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT, _gZkClient);
    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 = _gZkClient.<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, _gZkClient);
    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 = _gZkClient.<ZNRecord> readData(path);
    // AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
    // AssertJUnit.assertNull(election.getController());
    // AssertJUnit.assertNull(election.getLeader());
    LOG.info("END " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) HelixManager(org.apache.helix.HelixManager) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) DistributedLeaderElection(org.apache.helix.manager.zk.DistributedLeaderElection) Date(java.util.Date) NotificationContext(org.apache.helix.NotificationContext) HelixTimerTask(org.apache.helix.HelixTimerTask) LiveInstance(org.apache.helix.model.LiveInstance) GenericHelixController(org.apache.helix.controller.GenericHelixController) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 2 with GenericHelixController

use of org.apache.helix.controller.GenericHelixController in project helix by apache.

the class TestDistControllerElection method testParticipant.

@Test()
public void testParticipant() throws Exception {
    String className = getShortClassName();
    LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
    final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testParticipant";
    String path = "/" + clusterName;
    if (_gZkClient.exists(path)) {
        _gZkClient.deleteRecursively(path);
    }
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    final String controllerName = "participant_0";
    HelixManager manager = new MockZKHelixManager(clusterName, controllerName, InstanceType.PARTICIPANT, _gZkClient);
    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 = PropertyPathBuilder.controllerLeader(clusterName);
    ZNRecord leaderRecord = _gZkClient.<ZNRecord>readData(path, true);
    AssertJUnit.assertNull(leaderRecord);
// AssertJUnit.assertNull(election.getController());
// AssertJUnit.assertNull(election.getLeader());
}
Also used : NotificationContext(org.apache.helix.NotificationContext) HelixTimerTask(org.apache.helix.HelixTimerTask) HelixManager(org.apache.helix.HelixManager) GenericHelixController(org.apache.helix.controller.GenericHelixController) DistributedLeaderElection(org.apache.helix.manager.zk.DistributedLeaderElection) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 3 with GenericHelixController

use of org.apache.helix.controller.GenericHelixController in project helix by apache.

the class TestDistControllerElection method testController.

@Test()
public void testController() throws Exception {
    System.out.println("START TestDistControllerElection at " + new Date(System.currentTimeMillis()));
    String className = getShortClassName();
    final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testController";
    String path = "/" + clusterName;
    if (_gZkClient.exists(path)) {
        _gZkClient.deleteRecursively(path);
    }
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();
    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
    final String controllerName = "controller_0";
    HelixManager manager = new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER, _gZkClient);
    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 = _gZkClient.<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, _gZkClient);
    GenericHelixController controller1 = new GenericHelixController();
    election = new DistributedLeaderElection(manager, controller1, timerTasks);
    context = new NotificationContext(manager);
    context.setType(NotificationContext.Type.INIT);
    election.onControllerChange(context);
    // leaderRecord = _gZkClient.<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()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) HelixManager(org.apache.helix.HelixManager) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) DistributedLeaderElection(org.apache.helix.manager.zk.DistributedLeaderElection) Date(java.util.Date) NotificationContext(org.apache.helix.NotificationContext) HelixTimerTask(org.apache.helix.HelixTimerTask) LiveInstance(org.apache.helix.model.LiveInstance) GenericHelixController(org.apache.helix.controller.GenericHelixController) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 4 with GenericHelixController

use of org.apache.helix.controller.GenericHelixController in project helix by apache.

the class ZKHelixManager method connect.

@Override
public void connect() throws Exception {
    LOG.info("ClusterManager.connect()");
    if (isConnected()) {
        LOG.warn("Cluster manager: " + _instanceName + " for cluster: " + _clusterName + " already connected. skip connect");
        return;
    }
    switch(_instanceType) {
        case CONTROLLER:
        case CONTROLLER_PARTICIPANT:
            if (_controller == null) {
                _controller = new GenericHelixController(_clusterName);
                _messagingService.getExecutor().setController(_controller);
            }
            break;
        default:
            break;
    }
    try {
        createClient();
        _messagingService.onConnected();
    } catch (Exception e) {
        LOG.error("fail to connect " + _instanceName, e);
        disconnect();
        throw e;
    }
}
Also used : GenericHelixController(org.apache.helix.controller.GenericHelixController) UnknownHostException(java.net.UnknownHostException) JMException(javax.management.JMException)

Example 5 with GenericHelixController

use of org.apache.helix.controller.GenericHelixController in project helix by apache.

the class TestGenericHelixControllerThreading method testGenericHelixControllerThreadCount.

// Temporarily disabling the test as it's not stable when running under the entire mvn test suite.
// Some other crashed tests might cause this one to fail as controllers might not be gracefully
// shutdown
@Test(enabled = false)
public void testGenericHelixControllerThreadCount() throws Exception {
    System.out.println("testGenericHelixControllerThreadCount STARTs");
    final int numControllers = 100;
    ArrayList<GenericHelixController> controllers = createHelixControllers(numControllers);
    Assert.assertEquals(getThreadCountByNamePrefix(EVENT_PROCESS_THREAD_NAME_PREFIX), numControllers * 2);
    int remainingExpectedEventProcessThreadsCount = numControllers * 2;
    for (GenericHelixController ctrl : controllers) {
        ctrl.shutdown();
        remainingExpectedEventProcessThreadsCount -= 2;
        Assert.assertEquals(getThreadCountByNamePrefix(EVENT_PROCESS_THREAD_NAME_PREFIX), remainingExpectedEventProcessThreadsCount);
    }
    System.out.println("testGenericHelixControllerThreadCount ENDs");
}
Also used : GenericHelixController(org.apache.helix.controller.GenericHelixController) Test(org.testng.annotations.Test)

Aggregations

GenericHelixController (org.apache.helix.controller.GenericHelixController)5 Test (org.testng.annotations.Test)4 Date (java.util.Date)3 HelixManager (org.apache.helix.HelixManager)3 HelixTimerTask (org.apache.helix.HelixTimerTask)3 NotificationContext (org.apache.helix.NotificationContext)3 DistributedLeaderElection (org.apache.helix.manager.zk.DistributedLeaderElection)3 Builder (org.apache.helix.PropertyKey.Builder)2 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)2 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)2 ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)2 LiveInstance (org.apache.helix.model.LiveInstance)2 UnknownHostException (java.net.UnknownHostException)1 JMException (javax.management.JMException)1 ZNRecord (org.apache.helix.ZNRecord)1