Search in sources :

Example 1 with QuotaExceededException

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);
    }
}
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 2 with QuotaExceededException

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);
        }
    }
}
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 3 with QuotaExceededException

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);
    }
}
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 4 with QuotaExceededException

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);
    }
}
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 5 with QuotaExceededException

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);
    }
}
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