Search in sources :

Example 36 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestZnodeModify method beforeClass.

@BeforeClass()
public void beforeClass() {
    System.out.println("START " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
    _zkClient = new ZkClient(ZK_ADDR);
    _zkClient.setZkSerializer(new ZNRecordSerializer());
    if (_zkClient.exists(PREFIX)) {
        _zkClient.deleteRecursively(PREFIX);
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) Date(java.util.Date) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeClass(org.testng.annotations.BeforeClass)

Example 37 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class ZkUnitTestBase method beforeSuite.

@BeforeSuite(alwaysRun = true)
public void beforeSuite() throws Exception {
    // Due to ZOOKEEPER-2693 fix, we need to specify whitelist for execute zk commends
    System.setProperty("zookeeper.4lw.commands.whitelist", "*");
    _zkServer = TestHelper.startZkServer(ZK_ADDR);
    AssertJUnit.assertTrue(_zkServer != null);
    ZKClientPool.reset();
    // System.out.println("Number of open zkClient before ZkUnitTests: "
    // + ZkClient.getNumberOfConnections());
    _gZkClient = new ZkClient(ZK_ADDR);
    _gZkClient.setZkSerializer(new ZNRecordSerializer());
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 38 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestExecutor method executeTestHelper.

private static Map<TestCommand, Boolean> executeTestHelper(List<TestCommand> commandList, String zkAddr, CountDownLatch countDown) {
    final Map<TestCommand, Boolean> testResults = new ConcurrentHashMap<TestCommand, Boolean>();
    ZkClient zkClient = null;
    zkClient = new ZkClient(zkAddr, ZkClient.DEFAULT_CONNECTION_TIMEOUT);
    zkClient.setZkSerializer(new ZNRecordSerializer());
    // sort on trigger's start time, stable sort
    Collections.sort(commandList, new Comparator<TestCommand>() {

        @Override
        public int compare(TestCommand o1, TestCommand o2) {
            return (int) (o1._trigger._startTime - o2._trigger._startTime);
        }
    });
    for (TestCommand command : commandList) {
        testResults.put(command, new Boolean(false));
        TestTrigger trigger = command._trigger;
        command._startTimestamp = System.currentTimeMillis() + trigger._startTime;
        new Thread(new ExecuteCommand(command._startTimestamp, command, countDown, zkClient, testResults)).start();
    }
    return testResults;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 39 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestHelper method verifyState.

/**
 * @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) {
    ZkClient zkClient = new ZkClient(zkAddr);
    zkClient.setZkSerializer(new ZNRecordSerializer());
    try {
        ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
        Builder keyBuilder = accessor.keyBuilder();
        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)) {
                String actualState = extView.getStateMap(partitionKey).get(instance);
                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 + ")");
            }
        }
    } finally {
        zkClient.close();
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ExternalView(org.apache.helix.model.ExternalView) Builder(org.apache.helix.PropertyKey.Builder) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Example 40 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestHelper method verifyEmptyCurStateAndExtView.

public static boolean verifyEmptyCurStateAndExtView(String clusterName, String resourceName, Set<String> instanceNames, String zkAddr) {
    ZkClient zkClient = new ZkClient(zkAddr);
    zkClient.setZkSerializer(new ZNRecordSerializer());
    try {
        ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
        Builder keyBuilder = accessor.keyBuilder();
        for (String instanceName : instanceNames) {
            List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(instanceName));
            for (String sessionId : sessionIds) {
                CurrentState curState = accessor.getProperty(keyBuilder.currentState(instanceName, sessionId, resourceName));
                if (curState != null && curState.getRecord().getMapFields().size() != 0) {
                    return false;
                }
            }
            ExternalView extView = accessor.getProperty(keyBuilder.externalView(resourceName));
            if (extView != null && extView.getRecord().getMapFields().size() != 0) {
                return false;
            }
        }
        return true;
    } finally {
        zkClient.close();
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ExternalView(org.apache.helix.model.ExternalView) Builder(org.apache.helix.PropertyKey.Builder) CurrentState(org.apache.helix.model.CurrentState) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Aggregations

ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)59 ZkClient (org.apache.helix.manager.zk.ZkClient)39 ZNRecord (org.apache.helix.ZNRecord)23 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)12 Test (org.testng.annotations.Test)11 IdealState (org.apache.helix.model.IdealState)10 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)9 Date (java.util.Date)7 InstanceConfig (org.apache.helix.model.InstanceConfig)7 ClusterSetup (org.apache.helix.tools.ClusterSetup)7 Builder (org.apache.helix.PropertyKey.Builder)6 StateModelDefinition (org.apache.helix.model.StateModelDefinition)6 HelixDataAccessor (org.apache.helix.HelixDataAccessor)5 ExternalView (org.apache.helix.model.ExternalView)5 PropertyKey (org.apache.helix.PropertyKey)4 BeforeClass (org.testng.annotations.BeforeClass)4 BeforeSuite (org.testng.annotations.BeforeSuite)4 File (java.io.File)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3