use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenExceedBytesHardQuotaExtend.
@Test
public void testSetQuotaWhenExceedBytesHardQuotaExtend() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
int bytes = 100;
StatsTrack st = new StatsTrack();
st.setByteHardLimit(bytes);
SetQuotaCommand.createQuota(zk, path, st);
StringBuilder sb = new StringBuilder(path);
for (int i = 1; i <= bytes; i++) {
sb.append("/c" + i);
if (i == bytes) {
try {
zk.create(sb.toString(), "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
fail("should not set quota when exceeds hard bytes quota");
} catch (QuotaExceededException e) {
// expected
validateQuotaExceededMetrics(namespace);
}
} else {
zk.create(sb.toString(), "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenExceedBothBytesAndCountHardQuota.
@Test
public void testSetQuotaWhenExceedBothBytesAndCountHardQuota() 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);
st.setCountHardLimit(1);
SetQuotaCommand.createQuota(zk, path, st);
try {
zk.create(path + "/c2", "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
fail("should give priority to CountQuotaExceededException when both meets the count and bytes quota");
} catch (QuotaExceededException e) {
// expected
validateQuotaExceededMetrics(namespace);
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenExceedCountHardQuota.
@Test
public void testSetQuotaWhenExceedCountHardQuota() 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.setCountHardLimit(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);
fail("should not set quota when exceeds hard count quota");
} catch (QuotaExceededException e) {
// expected
validateQuotaExceededMetrics(namespace);
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenSetQuotaLessThanExistBytes.
@Test
public void testSetQuotaWhenSetQuotaLessThanExistBytes() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "123456789".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
int bytes = 5;
StatsTrack st = new StatsTrack();
st.setByteHardLimit(bytes);
SetQuotaCommand.createQuota(zk, path, st);
try {
zk.setData(path, "123456".getBytes(), -1);
fail("should not set quota when exceeds hard bytes quota");
} catch (QuotaExceededException e) {
// expected
validateQuotaExceededMetrics(namespace);
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testMultiCreateThenSetDataShouldWork.
@Test
public void testMultiCreateThenSetDataShouldWork() 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);
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));
zk.multi(ops);
}
Aggregations