use of org.apache.zookeeper.StatsTrack 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);
}
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testListQuota.
@Test
public void testListQuota() throws Exception {
final String path = "/c1";
zk.create(path, "12345".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
StatsTrack st = new StatsTrack();
long bytes = 5L;
int count = 10;
long byteHardLimit = 6L;
int countHardLimit = 12;
st.setBytes(bytes);
st.setCount(count);
st.setByteHardLimit(byteHardLimit);
st.setCountHardLimit(countHardLimit);
SetQuotaCommand.createQuota(zk, path, st);
List<StatsTrack> statsTracks = ListQuotaCommand.listQuota(zk, path);
for (int i = 0; i < statsTracks.size(); i++) {
st = statsTracks.get(i);
if (i == 0) {
assertEquals(count, st.getCount());
assertEquals(countHardLimit, st.getCountHardLimit());
assertEquals(bytes, st.getBytes());
assertEquals(byteHardLimit, st.getByteHardLimit());
} else {
assertEquals(1, st.getCount());
assertEquals(-1, st.getCountHardLimit());
assertEquals(5, st.getBytes());
assertEquals(-1, st.getByteHardLimit());
}
}
// delete the Byte Hard Quota
st = new StatsTrack();
st.setByteHardLimit(1);
st.setBytes(1);
st.setCountHardLimit(1);
st.setCount(1);
DelQuotaCommand.delQuota(zk, path, st);
statsTracks = ListQuotaCommand.listQuota(zk, path);
for (int i = 0; i < statsTracks.size(); i++) {
st = statsTracks.get(i);
if (i == 0) {
assertEquals(-1, st.getCount());
assertEquals(-1, st.getCountHardLimit());
assertEquals(-1, st.getBytes());
assertEquals(-1, st.getByteHardLimit());
} else {
assertEquals(1, st.getCount());
assertEquals(-1, st.getCountHardLimit());
assertEquals(5, st.getBytes());
assertEquals(-1, st.getByteHardLimit());
}
}
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ZooKeeperQuotaTest method testQuota.
@Test
public void testQuota() throws Exception {
final String path = "/a/b/v";
// making sure setdata works on /
zk.setData("/", "some".getBytes(), -1);
zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/a/b/v/d", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
StatsTrack quota = new StatsTrack();
quota.setCount(4);
quota.setCountHardLimit(4);
quota.setBytes(9L);
quota.setByteHardLimit(15L);
SetQuotaCommand.createQuota(zk, path, quota);
// see if its set
String absolutePath = Quotas.limitPath(path);
byte[] data = zk.getData(absolutePath, false, new Stat());
StatsTrack st = new StatsTrack(data);
assertTrue(st.getBytes() == 9L, "bytes are set");
assertTrue(st.getByteHardLimit() == 15L, "byte hard limit is set");
assertTrue(st.getCount() == 4, "num count is set");
assertTrue(st.getCountHardLimit() == 4, "count hard limit is set");
// check quota node readable by old servers
OldStatsTrack ost = new OldStatsTrack(new String(data));
assertTrue(ost.getBytes() == 9L, "bytes are set");
assertTrue(ost.getCount() == 4, "num count is set");
String statPath = Quotas.statPath(path);
byte[] qdata = zk.getData(statPath, false, new Stat());
StatsTrack qst = new StatsTrack(qdata);
assertTrue(qst.getBytes() == 8L, "bytes are set");
assertTrue(qst.getCount() == 2, "count is set");
// force server to restart and load from snapshot, not txn log
stopServer();
startServer();
stopServer();
startServer();
ZooKeeperServer server = serverFactory.getZooKeeperServer();
assertNotNull(server.getZKDatabase().getDataTree().getMaxPrefixWithQuota(path) != null, "Quota is still set");
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class QuorumQuotaTest method testQuotaWithQuorum.
@Test
public void testQuotaWithQuorum() throws Exception {
ZooKeeper zk = createClient();
zk.setData("/", "some".getBytes(), -1);
zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
int i = 0;
for (i = 0; i < 300; i++) {
zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
StatsTrack quota = new StatsTrack();
quota.setCount(1000);
quota.setBytes(5000);
SetQuotaCommand.createQuota(zk, "/a", quota);
String statPath = Quotas.statPath("/a");
byte[] data = zk.getData(statPath, false, new Stat());
StatsTrack st = new StatsTrack(data);
assertTrue(st.getBytes() == 1204L, "bytes are set");
assertTrue(st.getCount() == 301, "num count is set");
for (i = 300; i < 600; i++) {
zk.create("/a/" + i, "some".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
data = zk.getData(statPath, false, new Stat());
st = new StatsTrack(data);
assertTrue(st.getBytes() == 2404L, "bytes are set");
assertTrue(st.getCount() == 601, "num count is set");
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class StatsTrackTest method testUpwardCompatibility.
@Test
public void testUpwardCompatibility() {
OldStatsTrack ost = new OldStatsTrack(null);
ost.setCount(2);
ost.setBytes(5);
Assert.assertEquals("count=2,bytes=5", ost.toString());
StatsTrack st = new StatsTrack(ost.toString());
Assert.assertEquals("count=2,bytes=5", st.toString());
Assert.assertEquals(5, st.getBytes());
Assert.assertEquals(2, st.getCount());
Assert.assertEquals(-1, st.getByteHardLimit());
Assert.assertEquals(-1, st.getCountHardLimit());
}
Aggregations