@Test
public void newFilesInheritPinness() throws Exception {
// Children should inherit the isPinned value of their parents on creation.
// Pin root
int rootId = mTfs.getFileId(new TachyonURI("/"));
mTfs.pinFile(rootId);
// Child file should be pinned
int file0Id = mTfs.createFile(new TachyonURI("/file0"));
assertTrue(mMasterInfo.getClientFileInfo(file0Id).isPinned);
assertEquals(Sets.newHashSet(mMasterInfo.getPinIdList()), Sets.newHashSet(file0Id));
// Child folder should be pinned
mTfs.mkdir(new TachyonURI("/folder"));
int folderId = mTfs.getFileId(new TachyonURI("/folder"));
assertTrue(mMasterInfo.getClientFileInfo(folderId).isPinned);
// Granchild file also pinned
int file1Id = mTfs.createFile(new TachyonURI("/folder/file1"));
assertTrue(mMasterInfo.getClientFileInfo(file1Id).isPinned);
assertEquals(Sets.newHashSet(mMasterInfo.getPinIdList()), Sets.newHashSet(file0Id, file1Id));
// Unpinning child folder should cause its children to be unpinned as well
mTfs.unpinFile(folderId);
assertFalse(mMasterInfo.getClientFileInfo(folderId).isPinned);
assertFalse(mMasterInfo.getClientFileInfo(file1Id).isPinned);
assertEquals(Sets.newHashSet(mMasterInfo.getPinIdList()), Sets.newHashSet(file0Id));
// And new grandchildren should be unpinned too.
int file2Id = mTfs.createFile(new TachyonURI("/folder/file2"));
assertFalse(mMasterInfo.getClientFileInfo(file2Id).isPinned);
assertEquals(Sets.newHashSet(mMasterInfo.getPinIdList()), Sets.newHashSet(file0Id));
// But toplevel children still should be pinned!
int file3Id = mTfs.createFile(new TachyonURI("/file3"));
assertTrue(mMasterInfo.getClientFileInfo(file3Id).isPinned);
assertEquals(Sets.newHashSet(mMasterInfo.getPinIdList()), Sets.newHashSet(file0Id, file3Id));
}