Search in sources :

Example 1 with ZnodeOpArg

use of org.apache.helix.tools.ZnodeOpArg in project helix by apache.

the class TestZnodeModify method testDataTriggerWithTimeout.

@Test()
public void testDataTriggerWithTimeout() throws Exception {
    logger.info("RUN: " + new Date(System.currentTimeMillis()));
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    // test case for data trigger with timeout
    final String pathChild1 = PREFIX + "/dataTriggerWithTimeout_child1";
    final ZNRecord record = getExampleZNRecord();
    ZNRecord recordNew = new ZNRecord(record);
    recordNew.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.SEMI_AUTO.toString());
    ZnodeOpArg arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.ZNODE, "+", recordNew);
    TestCommand command1 = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 8000, record), arg1);
    commandList.add(command1);
    arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.ZNODE, "==");
    command1 = new TestCommand(CommandType.VERIFY, new TestTrigger(9000, 500, recordNew), arg1);
    commandList.add(command1);
    // start a separate thread to change znode at pathChild1
    new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(3000);
                final ZkClient zkClient = new ZkClient(ZK_ADDR);
                zkClient.setZkSerializer(new ZNRecordSerializer());
                zkClient.createPersistent(pathChild1, true);
                zkClient.writeData(pathChild1, record);
            } catch (InterruptedException e) {
                logger.error("Interrupted sleep", e);
            }
        }
    }.start();
    Map<TestCommand, Boolean> results = TestExecutor.executeTest(commandList, ZK_ADDR);
    for (Map.Entry<TestCommand, Boolean> entry : results.entrySet()) {
        Assert.assertTrue(entry.getValue());
    // System.out.println(entry.getValue() + ":" + entry.getKey());
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) Date(java.util.Date) TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) HashMap(java.util.HashMap) Map(java.util.Map) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 2 with ZnodeOpArg

use of org.apache.helix.tools.ZnodeOpArg in project helix by apache.

the class TestZnodeModify method testBasic.

@Test()
public void testBasic() throws Exception {
    logger.info("RUN: " + new Date(System.currentTimeMillis()));
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    // test case for the basic flow, no timeout, no data trigger
    String pathChild1 = PREFIX + "/basic_child1";
    String pathChild2 = PREFIX + "/basic_child2";
    TestCommand command;
    ZnodeOpArg arg;
    arg = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "+", "key1", "simpleValue1");
    command = new TestCommand(CommandType.MODIFY, arg);
    commandList.add(command);
    List<String> list = new ArrayList<String>();
    list.add("listValue1");
    list.add("listValue2");
    arg = new ZnodeOpArg(pathChild1, ZnodePropertyType.LIST, "+", "key2", list);
    command = new TestCommand(CommandType.MODIFY, arg);
    commandList.add(command);
    ZNRecord record = getExampleZNRecord();
    arg = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "+", record);
    command = new TestCommand(CommandType.MODIFY, arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "==", "key1");
    command = new TestCommand(CommandType.VERIFY, new TestTrigger(1000, 0, "simpleValue1"), arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild1, ZnodePropertyType.LIST, "==", "key2");
    command = new TestCommand(CommandType.VERIFY, new TestTrigger(1000, 0, list), arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "==");
    command = new TestCommand(CommandType.VERIFY, new TestTrigger(1000, 0, record), arg);
    commandList.add(command);
    Map<TestCommand, Boolean> results = TestExecutor.executeTest(commandList, ZK_ADDR);
    for (Map.Entry<TestCommand, Boolean> entry : results.entrySet()) {
        Assert.assertTrue(entry.getValue());
    }
    logger.info("END: " + new Date(System.currentTimeMillis()));
}
Also used : ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) Date(java.util.Date) TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) HashMap(java.util.HashMap) Map(java.util.Map) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 3 with ZnodeOpArg

use of org.apache.helix.tools.ZnodeOpArg in project helix by apache.

the class TestZnodeModify method testDataTrigger.

@Test()
public void testDataTrigger() throws Exception {
    logger.info("RUN: " + new Date(System.currentTimeMillis()));
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    // test case for data trigger, no timeout
    String pathChild1 = PREFIX + "/data_trigger_child1";
    String pathChild2 = PREFIX + "/data_trigger_child2";
    ZnodeOpArg arg;
    TestCommand command;
    ZnodeOpArg arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "+", "key1", "simpleValue1-new");
    TestCommand command1 = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 0, "simpleValue1"), arg1);
    commandList.add(command1);
    ZNRecord record = getExampleZNRecord();
    ZNRecord recordNew = new ZNRecord(record);
    recordNew.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.SEMI_AUTO.toString());
    arg = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "+", recordNew);
    command = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 3000, record), arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "+", record);
    command = new TestCommand(CommandType.MODIFY, new TestTrigger(1000), arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "!=", "key1");
    command = new TestCommand(CommandType.VERIFY, new TestTrigger(3100, 0, "simpleValue1-new"), arg);
    commandList.add(command);
    arg = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "==");
    command = new TestCommand(CommandType.VERIFY, new TestTrigger(3100, 0, recordNew), arg);
    commandList.add(command);
    Map<TestCommand, Boolean> results = TestExecutor.executeTest(commandList, ZK_ADDR);
    boolean result = results.remove(command1).booleanValue();
    AssertJUnit.assertFalse(result);
    for (Map.Entry<TestCommand, Boolean> entry : results.entrySet()) {
        Assert.assertTrue(entry.getValue());
    }
    logger.info("END: " + new Date(System.currentTimeMillis()));
}
Also used : ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) Date(java.util.Date) TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) HashMap(java.util.HashMap) Map(java.util.Map) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 4 with ZnodeOpArg

use of org.apache.helix.tools.ZnodeOpArg in project helix by apache.

the class TestZnodeModify method testTimeout.

@Test()
public void testTimeout() throws Exception {
    logger.info("RUN: " + new Date(System.currentTimeMillis()));
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    // test case for timeout, no data trigger
    String pathChild1 = PREFIX + "/timeout_child1";
    String pathChild2 = PREFIX + "/timeout_child2";
    ZnodeOpArg arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "+", "key1", "simpleValue1-new");
    TestCommand command1 = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 1000, "simpleValue1"), arg1);
    commandList.add(command1);
    ZNRecord record = getExampleZNRecord();
    ZNRecord recordNew = new ZNRecord(record);
    recordNew.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.SEMI_AUTO.toString());
    arg1 = new ZnodeOpArg(pathChild2, ZnodePropertyType.ZNODE, "+", recordNew);
    command1 = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 500, record), arg1);
    commandList.add(command1);
    arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.SIMPLE, "==", "key1");
    command1 = new TestCommand(CommandType.VERIFY, new TestTrigger(1000, 500, "simpleValue1-new"), arg1);
    commandList.add(command1);
    arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.ZNODE, "==");
    command1 = new TestCommand(CommandType.VERIFY, new TestTrigger(1000, 500, recordNew), arg1);
    commandList.add(command1);
    Map<TestCommand, Boolean> results = TestExecutor.executeTest(commandList, ZK_ADDR);
    for (Map.Entry<TestCommand, Boolean> entry : results.entrySet()) {
        Assert.assertFalse(entry.getValue());
    }
    logger.info("END: " + new Date(System.currentTimeMillis()));
}
Also used : TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 5 with ZnodeOpArg

use of org.apache.helix.tools.ZnodeOpArg in project helix by apache.

the class TestDriver method setIdealState.

public static void setIdealState(String uniqClusterName, long beginTime, int percentage) throws Exception {
    if (!_testInfoMap.containsKey(uniqClusterName)) {
        String errMsg = "test cluster hasn't been setup:" + uniqClusterName;
        throw new IllegalArgumentException(errMsg);
    }
    TestInfo testInfo = _testInfoMap.get(uniqClusterName);
    String clusterName = testInfo._clusterName;
    List<String> instanceNames = new ArrayList<String>();
    for (int i = 0; i < testInfo._numNode; i++) {
        int port = START_PORT + i;
        instanceNames.add(PARTICIPANT_PREFIX + "_" + port);
    }
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    for (int i = 0; i < testInfo._numDb; i++) {
        String dbName = TEST_DB_PREFIX + i;
        ZNRecord destIS = DefaultIdealStateCalculator.calculateIdealState(instanceNames, testInfo._numPartitionsPerDb, testInfo._replica - 1, dbName, "MASTER", "SLAVE");
        // destIS.setId(dbName);
        destIS.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.CUSTOMIZED.toString());
        destIS.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), Integer.toString(testInfo._numPartitionsPerDb));
        destIS.setSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString(), STATE_MODEL);
        destIS.setSimpleField(IdealStateProperty.REPLICAS.toString(), "" + testInfo._replica);
        // String idealStatePath = "/" + clusterName + "/" +
        // PropertyType.IDEALSTATES.toString() + "/"
        // + TEST_DB_PREFIX + i;
        // _zkClient.<ZNRecord>
        ZNRecord initIS = new ZNRecord(dbName);
        // readData(idealStatePath);
        initIS.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.CUSTOMIZED.toString());
        initIS.setSimpleField(IdealStateProperty.NUM_PARTITIONS.toString(), Integer.toString(testInfo._numPartitionsPerDb));
        initIS.setSimpleField(IdealStateProperty.STATE_MODEL_DEF_REF.toString(), STATE_MODEL);
        initIS.setSimpleField(IdealStateProperty.REPLICAS.toString(), "" + testInfo._replica);
        int totalStep = calcuateNumTransitions(initIS, destIS);
        // LOG.info("initIS:" + initIS);
        // LOG.info("destIS:" + destIS);
        // LOG.info("totalSteps from initIS to destIS:" + totalStep);
        // System.out.println("initIS:" + initIS);
        // System.out.println("destIS:" + destIS);
        ZNRecord nextIS;
        int step = totalStep * percentage / 100;
        System.out.println("Resource:" + dbName + ", totalSteps from initIS to destIS:" + totalStep + ", walk " + step + " steps(" + percentage + "%)");
        nextIS = nextIdealState(initIS, destIS, step);
        // testInfo._idealStateMap.put(dbName, nextIS);
        String idealStatePath = PropertyPathBuilder.idealState(clusterName, TEST_DB_PREFIX + i);
        ZnodeOpArg arg = new ZnodeOpArg(idealStatePath, ZnodePropertyType.ZNODE, "+", nextIS);
        TestCommand command = new TestCommand(CommandType.MODIFY, new TestTrigger(beginTime), arg);
        commandList.add(command);
    }
    TestExecutor.executeTestAsync(commandList, ZK_ADDR);
}
Also used : TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

ArrayList (java.util.ArrayList)5 ZNRecord (org.apache.helix.ZNRecord)5 TestCommand (org.apache.helix.tools.TestCommand)5 TestTrigger (org.apache.helix.tools.TestTrigger)5 ZnodeOpArg (org.apache.helix.tools.ZnodeOpArg)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1