Search in sources :

Example 1 with ZKPathDataDumpTask

use of org.apache.helix.monitoring.ZKPathDataDumpTask in project helix by apache.

the class TestSchedulerMessage method testSchedulerMsg.

@Test(dependsOnMethods = "testSchedulerZeroMsg")
public void testSchedulerMsg() throws Exception {
    _factory._results.clear();
    HelixManager manager = null;
    for (int i = 0; i < NODE_NR; i++) {
        _participants[i].getMessagingService().registerMessageHandlerFactory(_factory.getMessageTypes(), _factory);
        // _startCMResultMap.get(hostDest)._manager;
        manager = _participants[i];
    }
    Message schedulerMessage = new Message(MessageType.SCHEDULER_MSG + "", UUID.randomUUID().toString());
    schedulerMessage.setTgtSessionId("*");
    schedulerMessage.setTgtName("CONTROLLER");
    // TODO: change it to "ADMIN" ?
    schedulerMessage.setSrcName("CONTROLLER");
    // schedulerMessage.getRecord().setSimpleField(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE,
    // "TestSchedulerMsg");
    // Template for the individual message sent to each participant
    Message msg = new Message(_factory.getMessageTypes().get(0), "Template");
    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    // Criteria to send individual messages
    Criteria cr = new Criteria();
    cr.setInstanceName("localhost_%");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setResource("%");
    cr.setPartition("%");
    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, cr);
    String crString = sw.toString();
    schedulerMessage.getRecord().setSimpleField("Criteria", crString);
    schedulerMessage.getRecord().setMapField("MessageTemplate", msg.getRecord().getSimpleFields());
    schedulerMessage.getRecord().setSimpleField("TIMEOUT", "-1");
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();
    helixDataAccessor.createControllerMessage(schedulerMessage);
    for (int i = 0; i < 30; i++) {
        Thread.sleep(2000);
        if (_PARTITIONS == _factory._results.size()) {
            break;
        }
    }
    Assert.assertEquals(_PARTITIONS, _factory._results.size());
    PropertyKey controllerTaskStatus = keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(), schedulerMessage.getMsgId());
    int messageResultCount = 0;
    for (int i = 0; i < 10; i++) {
        Thread.sleep(1000);
        ZNRecord statusUpdate = helixDataAccessor.getProperty(controllerTaskStatus).getRecord();
        Assert.assertTrue(statusUpdate.getMapField("SentMessageCount").get("MessageCount").equals("" + (_PARTITIONS * 3)));
        for (String key : statusUpdate.getMapFields().keySet()) {
            if (key.startsWith("MessageResult ")) {
                messageResultCount++;
                Assert.assertTrue(statusUpdate.getMapField(key).size() > 1);
            }
        }
        if (messageResultCount == _PARTITIONS * 3) {
            break;
        } else {
            Thread.sleep(2000);
        }
    }
    Assert.assertEquals(messageResultCount, _PARTITIONS * 3);
    int count = 0;
    for (Set<String> val : _factory._results.values()) {
        count += val.size();
    }
    Assert.assertEquals(count, _PARTITIONS * 3);
    // test the ZkPathDataDumpTask
    String controllerStatusPath = PropertyPathBuilder.controllerStatusUpdate(manager.getClusterName());
    List<String> subPaths = _gZkClient.getChildren(controllerStatusPath);
    Assert.assertTrue(subPaths.size() > 0);
    for (String subPath : subPaths) {
        String nextPath = controllerStatusPath + "/" + subPath;
        List<String> subsubPaths = _gZkClient.getChildren(nextPath);
        Assert.assertTrue(subsubPaths.size() > 0);
    }
    String instanceStatusPath = PropertyPathBuilder.instanceStatusUpdate(manager.getClusterName(), "localhost_" + (START_PORT));
    subPaths = _gZkClient.getChildren(instanceStatusPath);
    Assert.assertTrue(subPaths.size() == 0);
    for (String subPath : subPaths) {
        String nextPath = instanceStatusPath + "/" + subPath;
        List<String> subsubPaths = _gZkClient.getChildren(nextPath);
        Assert.assertTrue(subsubPaths.size() > 0);
        for (String subsubPath : subsubPaths) {
            String nextnextPath = nextPath + "/" + subsubPath;
            Assert.assertTrue(_gZkClient.getChildren(nextnextPath).size() > 0);
        }
    }
    Thread.sleep(3000);
    ZKPathDataDumpTask dumpTask = new ZKPathDataDumpTask(manager, 0L, 0L, Integer.MAX_VALUE);
    dumpTask.run();
    subPaths = _gZkClient.getChildren(controllerStatusPath);
    Assert.assertTrue(subPaths.size() > 0);
    for (String subPath : subPaths) {
        String nextPath = controllerStatusPath + "/" + subPath;
        List<String> subsubPaths = _gZkClient.getChildren(nextPath);
        Assert.assertTrue(subsubPaths.size() == 0);
    }
    subPaths = _gZkClient.getChildren(instanceStatusPath);
    Assert.assertTrue(subPaths.size() == 0);
    for (String subPath : subPaths) {
        String nextPath = instanceStatusPath + "/" + subPath;
        List<String> subsubPaths = _gZkClient.getChildren(nextPath);
        Assert.assertTrue(subsubPaths.size() > 0);
        for (String subsubPath : subsubPaths) {
            String nextnextPath = nextPath + "/" + subsubPath;
            Assert.assertTrue(_gZkClient.getChildren(nextnextPath).size() == 0);
        }
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) Message(org.apache.helix.model.Message) SerializationConfig(org.codehaus.jackson.map.SerializationConfig) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) Criteria(org.apache.helix.Criteria) ZKPathDataDumpTask(org.apache.helix.monitoring.ZKPathDataDumpTask) HelixDataAccessor(org.apache.helix.HelixDataAccessor) StringWriter(java.io.StringWriter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PropertyKey(org.apache.helix.PropertyKey) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Aggregations

StringWriter (java.io.StringWriter)1 Criteria (org.apache.helix.Criteria)1 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1 HelixManager (org.apache.helix.HelixManager)1 PropertyKey (org.apache.helix.PropertyKey)1 Builder (org.apache.helix.PropertyKey.Builder)1 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)1 ZNRecord (org.apache.helix.ZNRecord)1 Message (org.apache.helix.model.Message)1 ZKPathDataDumpTask (org.apache.helix.monitoring.ZKPathDataDumpTask)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)1 Test (org.testng.annotations.Test)1