use of org.apache.helix.manager.zk.ZkBaseDataAccessor in project helix by apache.
the class TestAutoFallbackPropertyStore method testSingleGetOnFallbackPath.
@Test
public void testSingleGetOnFallbackPath() {
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");
// test single exist
boolean exist = store.exists(path, 0);
Assert.assertTrue(exist);
// test single getStat
Stat stat = store.getStat(path, 0);
Assert.assertNotNull(stat);
// test single get
ZNRecord record = store.get(path, null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "0");
Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should not exist under new location after get");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkBaseDataAccessor in project helix by apache.
the class TestAutoFallbackPropertyStore method testMultiUpdateUsingFallbackPath.
@Test
public void testMultiUpdateUsingFallbackPath() {
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
for (int i = 0; i < 10; 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);
List<String> paths = new ArrayList<String>();
List<DataUpdater<ZNRecord>> updaters = new ArrayList<DataUpdater<ZNRecord>>();
for (int i = 0; i < 10; i++) {
String path = String.format("/%d", i);
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");
paths.add(path);
updaters.add(new MyDataUpdater("new" + i));
}
boolean[] succeed = store.updateChildren(paths, updaters, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
Assert.assertTrue(succeed[i]);
String path = paths.get(i);
// fallback path should remain unchanged
ZNRecord record = baseAccessor.get(String.format("%s%s", fallbackRoot, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "" + i);
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(), "" + i);
Assert.assertNotNull(record.getSimpleField("key"));
Assert.assertEquals(record.getSimpleField("key"), "value");
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkBaseDataAccessor in project helix by apache.
the class TestAutoFallbackPropertyStore method testMultiUpdateUsingNewath.
@Test
public void testMultiUpdateUsingNewath() {
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 both fallbackRoot and new root
for (int i = 0; i < 10; i++) {
String path = String.format("%s/%d", fallbackRoot, i);
baseAccessor.create(path, new ZNRecord(Integer.toString(i)), AccessOption.PERSISTENT);
path = String.format("%s/%d", root, i);
baseAccessor.create(path, new ZNRecord("new" + i), AccessOption.PERSISTENT);
}
AutoFallbackPropertyStore<ZNRecord> store = new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
List<String> paths = new ArrayList<String>();
List<DataUpdater<ZNRecord>> updaters = new ArrayList<DataUpdater<ZNRecord>>();
for (int i = 0; i < 20; i++) {
String path = String.format("/%d", i);
if (i < 10) {
Assert.assertTrue(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should exist under new location");
Assert.assertTrue(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should exist under fallback location");
} else {
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");
}
paths.add(path);
updaters.add(new MyDataUpdater("new" + i));
}
boolean[] succeed = store.updateChildren(paths, updaters, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
Assert.assertTrue(succeed[i]);
String path = paths.get(i);
// fallback path should remain unchanged
if (i < 10) {
ZNRecord record = baseAccessor.get(String.format("%s%s", fallbackRoot, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "" + i);
Assert.assertNull(record.getSimpleField("key"));
} else {
Assert.assertFalse(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0), "Should not exist under fallback location");
}
// new path should have simple field set
ZNRecord record = baseAccessor.get(String.format("%s%s", root, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "new" + i);
if (i < 10) {
Assert.assertNotNull(record.getSimpleField("key"));
Assert.assertEquals(record.getSimpleField("key"), "value");
} else {
Assert.assertNull(record.getSimpleField("key"));
}
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkBaseDataAccessor in project helix by apache.
the class TestAutoFallbackPropertyStore method testMultiGetOnFallbackPath.
@Test
void testMultiGetOnFallbackPath() {
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
for (int i = 0; i < 10; 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);
List<String> paths = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
String path = String.format("/%d", i);
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");
paths.add(path);
}
// test multi-exist
boolean[] exists = store.exists(paths, 0);
for (int i = 0; i < paths.size(); i++) {
Assert.assertTrue(exists[i]);
}
// test multi-getStat
Stat[] stats = store.getStats(paths, 0);
for (int i = 0; i < paths.size(); i++) {
Assert.assertNotNull(stats[i]);
}
// test multi-get
List<ZNRecord> records = store.get(paths, null, 0);
Assert.assertNotNull(records);
Assert.assertEquals(records.size(), 10);
for (int i = 0; i < 10; i++) {
ZNRecord record = records.get(i);
String path = paths.get(i);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), Integer.toString(i));
Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should not exist under new location after get");
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkBaseDataAccessor in project helix by apache.
the class TestAutoFallbackPropertyStore method testSingleUpdateUsingNewPath.
@Test
public void testSingleUpdateUsingNewPath() {
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 both fallbackRoot and root
for (int i = 0; i < 1; i++) {
String path = String.format("%s/%d", root, i);
baseAccessor.create(path, new ZNRecord("new" + i), AccessOption.PERSISTENT);
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.assertTrue(baseAccessor.exists(String.format("%s%s", root, path), 0), "Should 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("0"), AccessOption.PERSISTENT);
Assert.assertTrue(succeed);
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"));
record = baseAccessor.get(String.format("%s%s", root, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "new0");
Assert.assertNotNull(record.getSimpleField("key"));
Assert.assertEquals(record.getSimpleField("key"), "value");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations