use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestHelper method startZkServer.
public static ZkServer startZkServer(final String zkAddress, final List<String> rootNamespaces, boolean overwrite) throws Exception {
System.out.println("Start zookeeper at " + zkAddress + " in thread " + Thread.currentThread().getName());
String zkDir = zkAddress.replace(':', '_');
final String logDir = "/tmp/" + zkDir + "/logs";
final String dataDir = "/tmp/" + zkDir + "/dataDir";
if (overwrite) {
FileUtils.deleteDirectory(new File(dataDir));
FileUtils.deleteDirectory(new File(logDir));
}
ZKClientPool.reset();
IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {
@Override
public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
if (rootNamespaces == null) {
return;
}
for (String rootNamespace : rootNamespaces) {
try {
zkClient.deleteRecursive(rootNamespace);
} catch (Exception e) {
LOG.error("fail to deleteRecursive path:" + rootNamespace, e);
}
}
}
};
int port = Integer.parseInt(zkAddress.substring(zkAddress.lastIndexOf(':') + 1));
ZkServer zkServer = new ZkServer(dataDir, logDir, defaultNameSpace, port);
zkServer.start();
return zkServer;
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestHierarchicalDataStore method testHierarchicalDataStore.
@Test(groups = { "unitTest" })
public void testHierarchicalDataStore() {
_zkClientString = new ZkClient(ZK_ADDR, 1000, 3000);
String path = "/tmp/testHierarchicalDataStore";
FileFilter filter = null;
// _zkClient.setZkSerializer(new ZNRecordSerializer());
_zkClientString.deleteRecursively(path);
HierarchicalDataHolder<ZNRecord> dataHolder = new HierarchicalDataHolder<ZNRecord>(_zkClientString, path, filter);
dataHolder.print();
AssertJUnit.assertFalse(dataHolder.refreshData());
// write data
add(path, "root data");
AssertJUnit.assertTrue(dataHolder.refreshData());
dataHolder.print();
// add some children
add(path + "/child1", "child 1 data");
add(path + "/child2", "child 2 data");
AssertJUnit.assertTrue(dataHolder.refreshData());
dataHolder.print();
// add some grandchildren
add(path + "/child1" + "/grandchild1", "grand child 1 data");
add(path + "/child1" + "/grandchild2", "grand child 2 data");
AssertJUnit.assertTrue(dataHolder.refreshData());
dataHolder.print();
AssertJUnit.assertFalse(dataHolder.refreshData());
set(path + "/child1", "new child 1 data");
AssertJUnit.assertTrue(dataHolder.refreshData());
dataHolder.print();
}
use of org.apache.helix.manager.zk.ZkClient 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());
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestPauseSignal method testPauseSignal.
@Test()
public void testPauseSignal() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
final String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[5];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
5, // replicas
3, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// pause the cluster and make sure pause is persistent
ZkClient zkClient = new ZkClient(ZK_ADDR);
zkClient.setZkSerializer(new ZNRecordSerializer());
final HelixDataAccessor tmpAccessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
String cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " false";
ClusterSetup.processCommandLineArgs(cmd.split(" "));
tmpAccessor.setProperty(tmpAccessor.keyBuilder().pause(), new PauseSignal("pause"));
zkClient.close();
// wait for controller to be signaled by pause
Thread.sleep(1000);
// add a new resource group
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
setupTool.addResourceToCluster(clusterName, "TestDB1", 10, "MasterSlave");
setupTool.rebalanceStorageCluster(clusterName, "TestDB1", 3);
// make sure TestDB1 external view is empty
TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 1000, clusterName, "TestDB1", TestHelper.<String>setOf("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922"), ZK_ADDR);
// resume controller
final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " true";
ClusterSetup.processCommandLineArgs(cmd.split(" "));
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// clean up
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ZkIntegrationTestBase method beforeSuite.
@BeforeSuite
public void beforeSuite() throws Exception {
// TODO: use logging.properties file to config java.util.logging.Logger levels
java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
topJavaLogger.setLevel(Level.WARNING);
// 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();
_gZkClient = new ZkClient(ZK_ADDR);
_gZkClient.setZkSerializer(new ZNRecordSerializer());
_gSetupTool = new ClusterSetup(_gZkClient);
_baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
}
Aggregations