Search in sources :

Example 6 with StatsTrack

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

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

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

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

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

Aggregations

StatsTrack (org.apache.zookeeper.StatsTrack)43 Test (org.junit.jupiter.api.Test)25 OldStatsTrack (org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack)19 QuotaExceededException (org.apache.zookeeper.KeeperException.QuotaExceededException)14 KeeperException (org.apache.zookeeper.KeeperException)9 Stat (org.apache.zookeeper.data.Stat)6 DataTree (org.apache.zookeeper.server.DataTree)3 Op (org.apache.zookeeper.Op)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 MalformedPathException (org.apache.zookeeper.cli.MalformedPathException)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1