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);
}
}
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());
}
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;
}
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();
}
}
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();
}
}
Aggregations