Search in sources :

Example 1 with BuiltInStateModelDefinitions

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()));
}
Also used : BuiltInStateModelDefinitions(org.apache.helix.model.BuiltInStateModelDefinitions) HelixAdmin(org.apache.helix.HelixAdmin) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) TestHelper(org.apache.helix.TestHelper) Stat(org.apache.zookeeper.data.Stat) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Aggregations

Date (java.util.Date)1 HelixAdmin (org.apache.helix.HelixAdmin)1 PropertyKey (org.apache.helix.PropertyKey)1 TestHelper (org.apache.helix.TestHelper)1 ZNRecord (org.apache.helix.ZNRecord)1 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)1 BuiltInStateModelDefinitions (org.apache.helix.model.BuiltInStateModelDefinitions)1 Stat (org.apache.zookeeper.data.Stat)1 Test (org.testng.annotations.Test)1