Search in sources :

Example 21 with StatsTrack

use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.

the class ZooKeeperQuotaTest method testSetQuotaWhenSetQuotaOnParentOrChildPath.

@Test
public void testSetQuotaWhenSetQuotaOnParentOrChildPath() throws IOException, InterruptedException, KeeperException, MalformedPathException {
    zk.create("/c1", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/c1/c2", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/c1/c2/c3", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/c1/c2/c3/c4", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/c1/c2/c3/c4/c5", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    // set the quota on the path:/c1/c2/c3
    StatsTrack quota = new StatsTrack();
    quota.setCount(5);
    quota.setBytes(10);
    SetQuotaCommand.createQuota(zk, "/c1/c2/c3", quota);
    try {
        SetQuotaCommand.createQuota(zk, "/c1", quota);
        fail("should not set quota when child has a quota");
    } catch (IllegalArgumentException e) {
        assertEquals("/c1 has a child /c1/c2/c3 which has a quota", e.getMessage());
    }
    try {
        SetQuotaCommand.createQuota(zk, "/c1/c2/c3/c4/c5", quota);
        fail("should not set quota when parent has a quota");
    } catch (IllegalArgumentException e) {
        assertEquals("/c1/c2/c3/c4/c5 has a parent /c1/c2/c3 which has a quota", e.getMessage());
    }
}
Also used : OldStatsTrack(org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack) StatsTrack(org.apache.zookeeper.StatsTrack) Test(org.junit.jupiter.api.Test)

Example 22 with StatsTrack

use of org.apache.zookeeper.StatsTrack 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 23 with StatsTrack

use of org.apache.zookeeper.StatsTrack 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 24 with StatsTrack

use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.

the class ZooKeeperQuotaTest method testSetQuotaWhenExceedBytesSoftQuota.

@Test
public void testSetQuotaWhenExceedBytesSoftQuota() throws Exception {
    final String namespace = UUID.randomUUID().toString();
    final String path = "/" + namespace;
    zk.create(path, "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    StatsTrack st = new StatsTrack();
    st.setBytes(5L);
    SetQuotaCommand.createQuota(zk, path, st);
    zk.setData(path, "12345".getBytes(), -1);
    try {
        zk.setData(path, "123456".getBytes(), -1);
        validateNoQuotaExceededMetrics(namespace);
    } catch (Exception e) {
        fail("should set data which exceeds the soft byte quota");
    }
}
Also used : OldStatsTrack(org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack) StatsTrack(org.apache.zookeeper.StatsTrack) QuotaExceededException(org.apache.zookeeper.KeeperException.QuotaExceededException) KeeperException(org.apache.zookeeper.KeeperException) MalformedPathException(org.apache.zookeeper.cli.MalformedPathException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 25 with StatsTrack

use of org.apache.zookeeper.StatsTrack 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

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