BackupNode extends NameNode { @Override public void stop() { stop(true); } BackupNode(Configuration conf, NamenodeRole role); @Override // NameNode void stop(); boolean setSafeMode(SafeModeAction action);  }
@Test public void startBackupNodeWithIncorrectAuthentication() throws IOException { Configuration c = new HdfsConfiguration(); StartupOption startupOpt = StartupOption.CHECKPOINT; String dirs = getBackupNodeDir(startupOpt, 1); c.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs: c.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:0"); c.set(DFSConfigKeys.DFS_BLOCKREPORT_INITIAL_DELAY_KEY, "0"); c.setInt(DFSConfigKeys.DFS_DATANODE_SCAN_PERIOD_HOURS_KEY, -1); c.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 1); c.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, dirs); c.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, "${" + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY + "}"); c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY, "127.0.0.1:0"); c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_HTTP_ADDRESS_KEY, "127.0.0.1:0"); NameNode nn; try { Configuration nnconf = new HdfsConfiguration(c); DFSTestUtil.formatNameNode(nnconf); nn = NameNode.createNameNode(new String[] {}, nnconf); } catch (IOException e) { LOG.info("IOException is thrown creating name node"); throw e; } c.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); c.set(DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY, ""); BackupNode bn = null; try { bn = (BackupNode)NameNode.createNameNode( new String[] {startupOpt.getName()}, c); assertTrue("Namesystem in BackupNode should be null", bn.getNamesystem() == null); fail("Incorrect authentication setting should throw IOException"); } catch (IOException e) { LOG.info("IOException thrown.", e); assertTrue(e.getMessage().contains("Running in secure mode")); } finally { if (nn != null) { nn.stop(); } if (bn != null) { bn.stop(); } SecurityUtil.setAuthenticationMethod( UserGroupInformation.AuthenticationMethod.SIMPLE, c); UserGroupInformation.setConfiguration(c); } }
@Test public void testCanReadData() throws IOException { Path file1 = new Path("/fileToRead.dat"); Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; FileSystem fileSys = null; BackupNode backup = null; try { cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0).format(true).build(); fileSys = cluster.getFileSystem(); long txid = cluster.getNameNodeRpc().getTransactionID(); backup = startBackupNode(conf, StartupOption.BACKUP, 1); waitCheckpointDone(cluster, txid); String rpcAddrKeyPreffix = DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY + ".bnCluster"; String nnAddr = cluster.getNameNode().getNameNodeAddressHostPortString(); conf.get(DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY); String bnAddr = backup.getNameNodeAddressHostPortString(); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "bnCluster"); conf.set(DFSConfigKeys.DFS_NAMESERVICE_ID, "bnCluster"); conf.set(DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX + ".bnCluster", "nnActive, nnBackup"); conf.set(rpcAddrKeyPreffix + ".nnActive", nnAddr); conf.set(rpcAddrKeyPreffix + ".nnBackup", bnAddr); cluster.startDataNodes(conf, 3, true, StartupOption.REGULAR, null); DFSTestUtil.createFile( fileSys, file1, fileSize, fileSize, blockSize, (short)3, seed); FileSystem bnFS = FileSystem.get( new Path("hdfs: String nnData = DFSTestUtil.readFile(fileSys, file1); String bnData = DFSTestUtil.readFile(bnFS, file1); assertEquals("Data read from BackupNode and NameNode is not the same.", nnData, bnData); } catch(IOException e) { LOG.error("Error in TestBackupNode: ", e); assertTrue(e.getLocalizedMessage(), false); } finally { if(fileSys != null) fileSys.close(); if(backup != null) backup.stop(); if(cluster != null) cluster.shutdown(); } }