Search in sources :

Example 41 with ZkBaseDataAccessor

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

the class TestAutoFallbackPropertyStore method testFailOnSingleGet.

@Test
public void testFailOnSingleGet() {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
    String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    AutoFallbackPropertyStore<ZNRecord> store = new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
    String path = String.format("/%d", 0);
    Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should not exist under new location");
    Assert.assertFalse(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should not exist under fallback location");
    // test single exist
    boolean exist = store.exists(path, 0);
    Assert.assertFalse(exist);
    // test single getStat
    Stat stat = store.getStat(path, 0);
    Assert.assertNull(stat);
    // test single get
    ZNRecord record = store.get(path, null, 0);
    Assert.assertNull(record);
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) Stat(org.apache.zookeeper.data.Stat) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 42 with ZkBaseDataAccessor

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

the class TestAutoFallbackPropertyStore method testSingleUpdateUsingFallbackPath.

@Test
public void testSingleUpdateUsingFallbackPath() {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
    String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    // create 0 under fallbackRoot
    for (int i = 0; i < 1; i++) {
        String path = String.format("%s/%d", fallbackRoot, i);
        baseAccessor.create(path, new ZNRecord(Integer.toString(i)), AccessOption.PERSISTENT);
    }
    AutoFallbackPropertyStore<ZNRecord> store = new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
    String path = String.format("/%d", 0);
    Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should not exist under new location");
    Assert.assertTrue(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should exist under fallback location");
    boolean succeed = store.update(path, new MyDataUpdater("new0"), AccessOption.PERSISTENT);
    Assert.assertTrue(succeed);
    // fallback path should remain unchanged
    ZNRecord record = baseAccessor.get(String.format("%s%s", fallbackRoot, path), null, 0);
    Assert.assertNotNull(record);
    Assert.assertEquals(record.getId(), "0");
    Assert.assertNull(record.getSimpleField("key"));
    // new path should have simple field set
    record = baseAccessor.get(String.format("%s%s", root, path), null, 0);
    Assert.assertNotNull(record);
    Assert.assertEquals(record.getId(), "0");
    Assert.assertNotNull(record.getSimpleField("key"));
    Assert.assertEquals(record.getSimpleField("key"), "value");
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 43 with ZkBaseDataAccessor

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

the class TestAutoFallbackPropertyStore method testGetChildren.

@Test
public void testGetChildren() {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
    String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    // create 0-9 under fallbackRoot and 10-19 under root
    for (int i = 0; i < 20; i++) {
        if (i < 10) {
            String path = String.format("%s/%d", fallbackRoot, i);
            baseAccessor.create(path, new ZNRecord(Integer.toString(i)), AccessOption.PERSISTENT);
        } else {
            String path = String.format("%s/%d", root, i);
            baseAccessor.create(path, new ZNRecord(Integer.toString(i)), AccessOption.PERSISTENT);
        }
    }
    AutoFallbackPropertyStore<ZNRecord> store = new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
    List<String> paths = new ArrayList<String>();
    for (int i = 0; i < 20; i++) {
        String path = String.format("/%d", i);
        if (i < 10) {
            Assert.assertTrue(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should exist under fallback location");
            Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should not exist under new location");
        } else {
            Assert.assertFalse(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should not exist under fallback location");
            Assert.assertTrue(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should exist under new location");
        }
        paths.add(path);
    }
    List<String> childs = store.getChildNames("/", 0);
    Assert.assertNotNull(childs);
    Assert.assertEquals(childs.size(), 20);
    for (int i = 0; i < 20; i++) {
        String child = childs.get(i);
        Assert.assertTrue(childs.contains(child));
    }
    List<ZNRecord> records = store.getChildren("/", null, 0);
    Assert.assertNotNull(records);
    Assert.assertEquals(records.size(), 20);
    for (int i = 0; i < 20; i++) {
        ZNRecord record = records.get(i);
        Assert.assertNotNull(record);
        String id = record.getId();
        Assert.assertTrue(childs.contains(id));
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) ArrayList(java.util.ArrayList) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 44 with ZkBaseDataAccessor

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

the class MockController method createExternalView.

public void createExternalView(List<String> instanceNames, int partitions, int replicas, String dbName, long randomSeed) {
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(client));
    Builder keyBuilder = accessor.keyBuilder();
    ExternalView externalView = new ExternalView(computeRoutingTable(instanceNames, partitions, replicas, dbName, randomSeed));
    accessor.setProperty(keyBuilder.externalView(dbName), externalView);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ZkBaseDataAccessor(org.apache.helix.manager.zk.ZkBaseDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor)

Aggregations

ZkBaseDataAccessor (org.apache.helix.manager.zk.ZkBaseDataAccessor)44 ZNRecord (org.apache.helix.ZNRecord)40 Date (java.util.Date)37 Test (org.testng.annotations.Test)37 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)30 Builder (org.apache.helix.PropertyKey.Builder)18 HelixDataAccessor (org.apache.helix.HelixDataAccessor)15 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)15 IdealState (org.apache.helix.model.IdealState)12 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)10 ArrayList (java.util.ArrayList)8 PropertyKey (org.apache.helix.PropertyKey)8 ExternalView (org.apache.helix.model.ExternalView)8 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)8 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)6 LiveInstance (org.apache.helix.model.LiveInstance)6 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)6 Stat (org.apache.zookeeper.data.Stat)6 HashMap (java.util.HashMap)5 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)5