use of org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack 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");
}
Aggregations