use of org.apache.helix.model.BuiltInStateModelDefinitions in project helix by apache.
the class TestAddBuiltInStateModelDef method test.
@Test
public void test() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.addCluster(clusterName);
admin.addStateModelDef(clusterName, BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition().getId(), BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition());
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
controller.syncStart();
// controller shall create all built-in state model definitions
final BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
final PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
boolean ret = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
String path = keyBuilder.stateModelDef(def.getStateModelDefinition().getId()).getPath();
boolean exist = baseAccessor.exists(path, 0);
if (!exist) {
return false;
}
// make sure MasterSlave is not over-written
if (def == BuiltInStateModelDefinitions.MasterSlave) {
Stat stat = new Stat();
baseAccessor.get(path, stat, 0);
if (stat.getVersion() != 0) {
return false;
}
}
}
return true;
}
}, 10 * 1000);
Assert.assertTrue(ret);
controller.syncStop();
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations