use of org.apache.zookeeper.KeeperException.QuotaExceededException in project zookeeper by apache.
the class ZooKeeperQuotaTest method testSetQuotaWhenSetQuotaLessThanExistCount.
@Test
public void testSetQuotaWhenSetQuotaLessThanExistCount() throws Exception {
final String namespace = UUID.randomUUID().toString();
final String path = "/" + namespace;
zk.create(path, "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create(path + "/c1", "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create(path + "/c2", "1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
int count = 2;
StatsTrack st = new StatsTrack();
st.setCountHardLimit(count);
SetQuotaCommand.createQuota(zk, path, st);
try {
zk.create(path + "/c3", "1".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.KeeperException.QuotaExceededException 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.KeeperException.QuotaExceededException 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.KeeperException.QuotaExceededException 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.KeeperException.QuotaExceededException 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);
}
}
Aggregations