use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenSetQuotaOnParentOrChildPath.
@Test
public void testSetQuotaWhenSetQuotaOnParentOrChildPath() throws IOException, InterruptedException, KeeperException, MalformedPathException {
zk.create("/c1", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/c1/c2", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/c1/c2/c3", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/c1/c2/c3/c4", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/c1/c2/c3/c4/c5", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// set the quota on the path:/c1/c2/c3
StatsTrack quota = new StatsTrack();
quota.setCount(5);
quota.setBytes(10);
SetQuotaCommand.createQuota(zk, "/c1/c2/c3", quota);
try {
SetQuotaCommand.createQuota(zk, "/c1", quota);
fail("should not set quota when child has a quota");
} catch (IllegalArgumentException e) {
assertEquals("/c1 has a child /c1/c2/c3 which has a quota", e.getMessage());
}
try {
SetQuotaCommand.createQuota(zk, "/c1/c2/c3/c4/c5", quota);
fail("should not set quota when parent has a quota");
} catch (IllegalArgumentException e) {
assertEquals("/c1/c2/c3/c4/c5 has a parent /c1/c2/c3 which has a quota", e.getMessage());
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testMultiCreateThenSetDataShouldFail.
@Test
public void testMultiCreateThenSetDataShouldFail() throws Exception {
final String path = "/a";
final String subPath = "/a/b";
zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final byte[] data13b = "Hello, World!".getBytes(StandardCharsets.UTF_8);
final StatsTrack st = new StatsTrack();
st.setByteHardLimit(data13b.length - 1);
SetQuotaCommand.createQuota(zk, path, st);
final List<Op> ops = Arrays.asList(Op.create(subPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.setData(subPath, data13b, -1));
try {
zk.multi(ops);
fail("should fail transaction when hard quota is exceeded");
} catch (QuotaExceededException e) {
// expected
}
assertNull(zk.exists(subPath, null));
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenExceedCountSoftQuota.
@Test
public void testSetQuotaWhenExceedCountSoftQuota() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
int count = 2;
StatsTrack st = new StatsTrack();
st.setCount(count);
SetQuotaCommand.createQuota(zk, path, st);
zk.create(path + "/c2", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
try {
zk.create(path + "/c2" + "/c3", "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
validateNoQuotaExceededMetrics(namespace);
} catch (QuotaExceededException e) {
fail("should set quota when exceeds soft count quota");
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenExceedBytesSoftQuota.
@Test
public void testSetQuotaWhenExceedBytesSoftQuota() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
StatsTrack st = new StatsTrack();
st.setBytes(5L);
SetQuotaCommand.createQuota(zk, path, st);
zk.setData(path, "12345".getBytes(), -1);
try {
zk.setData(path, "123456".getBytes(), -1);
validateNoQuotaExceededMetrics(namespace);
} catch (Exception e) {
fail("should set data which exceeds the soft byte quota");
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testDeleteBytesQuota.
@Test
public void testDeleteBytesQuota() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "12345".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
StatsTrack st = new StatsTrack();
st.setByteHardLimit(5L);
SetQuotaCommand.createQuota(zk, path, st);
try {
zk.setData(path, "123456".getBytes(), -1);
fail("should not set data which exceeds the hard byte quota");
} catch (QuotaExceededException e) {
// expected
validateQuotaExceededMetrics(namespace);
}
// delete the Byte Hard Quota
st = new StatsTrack();
st.setByteHardLimit(1);
DelQuotaCommand.delQuota(zk, path, st);
zk.setData(path, "123456".getBytes(), -1);
validateQuotaExceededMetrics(namespace);
}
Aggregations