/** @return the ids of the children */ public synchronized Set<Long> getChildrenIds() { Set<Long> ret = new HashSet<Long>(mChildren.size()); for (Inode child : mChildren) { ret.add(child.getId()); } return ret; }
@Test public void addInodeFromJournalTest() throws Exception { mTree.createPath(NESTED_FILE_URI, sNestedFileOptions); mTree.createPath(new TachyonURI("/nested/test1/file1"), sNestedFileOptions); InodeDirectory root = mTree.getRoot(); InodeDirectory nested = (InodeDirectory) root.getChild("nested"); InodeDirectory test = (InodeDirectory) nested.getChild("test"); Inode file = test.getChild("file"); InodeDirectory test1 = (InodeDirectory) nested.getChild("test1"); Inode file1 = test1.getChild("file1"); // reset the tree mTree.addInodeFromJournal(root.toJournalEntry()); // re-init the root since the tree was reset above root = mTree.getRoot(); Assert.assertEquals(0, mTree.getInodeChildrenRecursive(root).size()); mTree.addInodeFromJournal(nested.toJournalEntry()); verifyChildrenNames(mTree, root, Sets.newHashSet("nested")); mTree.addInodeFromJournal(test.toJournalEntry()); verifyChildrenNames(mTree, root, Sets.newHashSet("nested", "test")); mTree.addInodeFromJournal(test1.toJournalEntry()); verifyChildrenNames(mTree, root, Sets.newHashSet("nested", "test", "test1")); mTree.addInodeFromJournal(file.toJournalEntry()); verifyChildrenNames(mTree, root, Sets.newHashSet("nested", "test", "test1", "file")); mTree.addInodeFromJournal(file1.toJournalEntry()); verifyChildrenNames(mTree, root, Sets.newHashSet("nested", "test", "test1", "file", "file1")); }
// verify that the tree has the given children private static void verifyChildrenNames( InodeTree tree, InodeDirectory root, Set<String> childNames) throws Exception { List<Inode> children = tree.getInodeChildrenRecursive(root); Assert.assertEquals(childNames.size(), children.size()); for (Inode child : children) { Assert.assertTrue(childNames.contains(child.getName())); } }
// helper for verifying that correct objects were journaled to the output stream private static void verifyJournal(InodeTree root, List<Inode> journaled) throws Exception { JournalOutputStream mockOutputStream = Mockito.mock(JournalOutputStream.class); root.streamToJournalCheckpoint(mockOutputStream); for (Inode node : journaled) { Mockito.verify(mockOutputStream).writeEntry(node.toJournalEntry()); } Mockito.verifyNoMoreInteractions(mockOutputStream); }
@Test public void createFileTest() throws Exception { // created nested file mTree.createPath(NESTED_FILE_URI, sNestedFileOptions); Inode nestedFile = mTree.getInodeByPath(NESTED_FILE_URI); Assert.assertEquals("file", nestedFile.getName()); Assert.assertEquals(2, nestedFile.getParentId()); Assert.assertTrue(nestedFile.isFile()); Assert.assertEquals("user1", nestedFile.getUserName()); Assert.assertTrue(nestedFile.getGroupName().isEmpty()); Assert.assertEquals((short) 0644, nestedFile.getPermission()); }
@Override public Object getFieldValue(Inode o) { return o.getName(); }
@Test public void createDirectoryTest() throws Exception { // create directory mTree.createPath(TEST_URI, sDirectoryOptions); Inode test = mTree.getInodeByPath(TEST_URI); Assert.assertEquals(TEST_PATH, test.getName()); Assert.assertTrue(test.isDirectory()); Assert.assertEquals("user1", test.getUserName()); Assert.assertTrue(test.getGroupName().isEmpty()); Assert.assertEquals((short) 0755, test.getPermission()); // create nested directory mTree.createPath(NESTED_URI, sNestedDirectoryOptions); Inode nested = mTree.getInodeByPath(NESTED_URI); Assert.assertEquals(TEST_PATH, nested.getName()); Assert.assertEquals(2, nested.getParentId()); Assert.assertTrue(test.isDirectory()); Assert.assertEquals("user1", test.getUserName()); Assert.assertTrue(test.getGroupName().isEmpty()); Assert.assertEquals((short) 0755, test.getPermission()); }