@Test public void backupCmdExecuted() throws IOException, AlluxioException, NoSuchFieldException, IllegalAccessException { CollectEnvCommand cmd = new CollectEnvCommand(FileSystemContext.create(sConf)); File targetDir = InfoCollectorTestUtils.createTemporaryDirectory(); CommandLine mockCommandLine = mock(CommandLine.class); String[] mockArgs = new String[]{cmd.getCommandName(), targetDir.getAbsolutePath()}; when(mockCommandLine.getArgs()).thenReturn(mockArgs); Field f = cmd.getClass().getSuperclass().getDeclaredField("mCommands"); f.setAccessible(true); ShellCommand mockCommandFail = mock(ShellCommand.class); when(mockCommandFail.runWithOutput()).thenReturn( new CommandReturn(255, "command failed")); Map<String, ShellCommand> mockCommandMap = new HashMap<>(); mockCommandMap.put("mockCommand", mockCommandFail); f.set(cmd, mockCommandMap); Field cb = cmd.getClass().getSuperclass().getDeclaredField("mCommandsAlt"); cb.setAccessible(true); ShellCommand mockCommandBackup = mock(ShellCommand.class); when(mockCommandBackup.runWithOutput()).thenReturn( new CommandReturn(0, "backup command executed")); Map<String, ShellCommand> mockBetterMap = new HashMap<>(); mockBetterMap.put("mockCommand", mockCommandBackup); cb.set(cmd, mockBetterMap); int ret = cmd.run(mockCommandLine); assertEquals(0, ret); verify(mockCommandFail).runWithOutput(); verify(mockCommandBackup).runWithOutput(); File subDir = new File(Paths.get(targetDir.getAbsolutePath(), cmd.getCommandName()).toString()); assertEquals(new String[]{"collectEnv.txt"}, subDir.list()); String fileContent = new String(Files.readAllBytes(subDir.listFiles()[0].toPath())); assertTrue(fileContent.contains("backup command executed")); }
@Override public String getCommandName() { return COMMAND_NAME; }
CollectEnvCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } }
CollectEnvCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectEnvCommand(FileSystemContext fsContext); }
CollectEnvCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectEnvCommand(FileSystemContext fsContext); @Override String getCommandName(); @Override boolean hasSubCommand(); @Override String getUsage(); @Override String getDescription(); }
CollectEnvCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectEnvCommand(FileSystemContext fsContext); @Override String getCommandName(); @Override boolean hasSubCommand(); @Override String getUsage(); @Override String getDescription(); static final String COMMAND_NAME; }