/** * Test if standby pick up the correct inode id after failover * @throws Exception */ @Test public void testFailOverInodeId() throws Exception { FileSystem fs = cluster.getFileSystem(); long expectedLastINodeId = INodeId.ROOT_INODE_ID; GSet<INode, INode> expectedINodeMap = null; DFSTestUtil.createFile(fs, new Path("/testone/file"), 1024, (short) 1, 0); FSNamesystem primaryNS = cluster.getPrimaryAvatar(0).avatar.namesystem; INode primaryINode = primaryNS.dir.getINode("/testone/file"); long expectedprimaryINodeId = primaryINode.getId(); expectedLastINodeId += 2; expectedINodeMap = primaryNS.dir.getInodeMap(); cluster.killPrimary(); cluster.failOver(); // standby become primary after fail over primaryNS = cluster.getPrimaryAvatar(0).avatar.namesystem; assertNull(cluster.getStandbyAvatar(0)); assertEquals(expectedLastINodeId, primaryNS.dir.getLastInodeId()); assertEquals(expectedprimaryINodeId, primaryNS.dir.getINode("/testone/file").getId()); DFSTestUtil.assertInodemapEquals(expectedINodeMap, primaryNS.dir.getInodeMap()); }
/** Make sure two inode map are the equal */ public static void assertInodemapEquals(GSet<INode, INode> o1, GSet<INode, INode> o2) { Iterator<INode> itr1 = o1.iterator(); Iterator<INode> itr2 = o2.iterator(); while (itr1.hasNext()) { assertTrue(itr2.hasNext()); assertEquals(itr1.next(), itr2.next()); } assertFalse(itr2.hasNext()); }
/** Helper function while debugging the test */ private void printINodeMap(GSet<INode, INode> inodeMap) { Iterator<INode> itr = inodeMap.iterator(); while(itr.hasNext()) { INode inode = itr.next(); System.out.println("Id is " + inode.getId() + " " + inode); } }
/** For testing */ public GSet<INode, INode> getInodeMap() { return inodeMap; }