/** * Get address list for a given type of address. Command expected to * fail if {@code success} is false. * @return returns the success or error output from the tool. */ private String getAddressListFromTool(TestType type, HdfsConfiguration conf, boolean success) throws Exception { String[] args = new String[1]; switch (type) { case NAMENODE: args[0] = Command.NAMENODE.getName(); break; case BACKUP: args[0] = Command.BACKUP.getName(); break; case SECONDARY: args[0] = Command.SECONDARY.getName(); break; case NNRPCADDRESSES: args[0] = Command.NNRPCADDRESSES.getName(); break; } return runTool(conf, args, success); }
/** * Test empty configuration */ @Test(timeout=10000) public void testEmptyConf() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(false); // Verify getting addresses fails getAddressListFromTool(TestType.NAMENODE, conf, false); System.out.println(getAddressListFromTool(TestType.BACKUP, conf, false)); getAddressListFromTool(TestType.SECONDARY, conf, false); getAddressListFromTool(TestType.NNRPCADDRESSES, conf, false); for (Command cmd : Command.values()) { String arg = cmd.getName(); CommandHandler handler = Command.getHandler(arg); assertNotNull("missing handler: " + cmd, handler); if (handler.key != null) { // First test with configuration missing the required key String[] args = {handler.key}; runTool(conf, args, false); } } }
/** * Test empty configuration */ @Test public void testEmptyConf() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(false); // Verify getting addresses fails getAddressListFromTool(TestType.NAMENODE, conf, false); getAddressListFromTool(TestType.NNRPCADDRESSES, conf, false); for (Command cmd : Command.values()) { String arg = cmd.getName(); CommandHandler handler = Command.getHandler(arg); assertNotNull("missing handler: " + cmd, handler); if (handler.key != null) { // First test with configuration missing the required key String[] args = {handler.key}; runTool(conf, args, false); } } }
/** * Tests commands other than {@link Command#NAMENODE}, {@link Command#BACKUP}, * {@link Command#SECONDARY} and {@link Command#NNRPCADDRESSES} */ @Test(timeout=10000) public void testTool() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(false); for (Command cmd : Command.values()) { CommandHandler handler = Command.getHandler(cmd.getName()); if (handler.key != null && !"-confKey".equals(cmd.getName())) { // Add the key to the conf and ensure tool returns the right value String[] args = {cmd.getName()}; conf.set(handler.key, "value"); assertTrue(runTool(conf, args, true).contains("value")); } } }
/** * Get address list for a given type of address. Command expected to * fail if {@code success} is false. * * @return returns the success or error output from the tool. */ private String getAddressListFromTool(TestType type, HdfsConfiguration conf, boolean success) throws Exception { String[] args = new String[1]; switch (type) { case NAMENODE: args[0] = Command.NAMENODE.getName(); break; case NNRPCADDRESSES: args[0] = Command.NNRPCADDRESSES.getName(); break; } return runTool(conf, args, success); }
/** * Tests commands other than {@link Command#NAMENODE}, {@link * Command#BACKUP}, * {@link Command#SECONDARY} and {@link Command#NNRPCADDRESSES} */ @Test public void testTool() throws Exception { HdfsConfiguration conf = new HdfsConfiguration(false); for (Command cmd : Command.values()) { CommandHandler handler = Command.getHandler(cmd.getName()); if (handler.key != null && !"-confKey".equals(cmd.getName())) { // Add the key to the conf and ensure tool returns the right value String[] args = {cmd.getName()}; conf.set(handler.key, "value"); assertTrue(runTool(conf, args, true).contains("value")); } } }