Search in sources :

Example 11 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException 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));
}
Also used : Op(org.apache.zookeeper.Op) QuotaExceededException(org.apache.zookeeper.KeeperException.QuotaExceededException) OldStatsTrack(org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 12 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException 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");
    }
}
Also used : QuotaExceededException(org.apache.zookeeper.KeeperException.QuotaExceededException) OldStatsTrack(org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 13 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException 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);
}
Also used : QuotaExceededException(org.apache.zookeeper.KeeperException.QuotaExceededException) OldStatsTrack(org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Aggregations

QuotaExceededException (org.apache.zookeeper.KeeperException.QuotaExceededException)13 StatsTrack (org.apache.zookeeper.StatsTrack)13 OldStatsTrack (org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack)13 Test (org.junit.jupiter.api.Test)13 Op (org.apache.zookeeper.Op)1