Search in sources :

Example 6 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 7 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)

Example 8 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException in project zookeeper by apache.

the class ZooKeeperQuotaTest method testSetQuotaWhenExceedCountHardQuotaExtend.

@Test
public void testSetQuotaWhenExceedCountHardQuotaExtend() 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 = 100;
    StatsTrack st = new StatsTrack();
    st.setCountHardLimit(count);
    SetQuotaCommand.createQuota(zk, path, st);
    StringBuilder sb = new StringBuilder(path);
    for (int i = 1; i <= count; i++) {
        sb.append("/c" + i);
        if (i == count) {
            try {
                zk.create(sb.toString(), "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                fail("should not set quota when exceeds hard count quota");
            } catch (QuotaExceededException e) {
                // expected
                validateQuotaExceededMetrics(namespace);
            }
        } else {
            zk.create(sb.toString(), "data".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 9 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException in project zookeeper by apache.

the class ZooKeeperQuotaTest method testSetQuotaWhenExceedBytesHardQuota.

@Test
public void testSetQuotaWhenExceedBytesHardQuota() 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);
    }
}
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 10 with QuotaExceededException

use of org.apache.zookeeper.KeeperException.QuotaExceededException in project zookeeper by apache.

the class ZooKeeperQuotaTest method testSetQuotaWhenCreateNodeExceedBytesQuota.

@Test
public void testSetQuotaWhenCreateNodeExceedBytesQuota() throws Exception {
    final String namespace = UUID.randomUUID().toString();
    final String path = "/" + namespace + "/quota";
    zk.create("/" + namespace, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create(path, "01234".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    StatsTrack quota = new StatsTrack();
    quota.setByteHardLimit(10);
    SetQuotaCommand.createQuota(zk, path, quota);
    try {
        zk.create(path + "/data", "567891".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        fail("should not set data when exceed hard byte 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