@Test public void alluxioCmdExecuted() throws IOException, AlluxioException, NoSuchFieldException, IllegalAccessException { CollectAlluxioInfoCommand cmd = new CollectAlluxioInfoCommand(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); CollectAlluxioInfoCommand.AlluxioCommand mockCommand = mock(CollectAlluxioInfoCommand.AlluxioCommand.class); when(mockCommand.runWithOutput()) .thenReturn(new CommandReturn(0, "nothing happens")); Map<String, ShellCommand> mockCommandMap = new HashMap<>(); mockCommandMap.put("mockCommand", mockCommand); f.set(cmd, mockCommandMap); int ret = cmd.run(mockCommandLine); assertEquals(0, ret); verify(mockCommand).runWithOutput(); File subDir = new File(Paths.get(targetDir.getAbsolutePath(), cmd.getCommandName()).toString()); assertEquals(new String[]{"collectAlluxioInfo.txt"}, subDir.list()); String fileContent = new String(Files.readAllBytes(subDir.listFiles()[0].toPath())); assertTrue(fileContent.contains("nothing happens")); }
@Override public String getCommandName() { return COMMAND_NAME; }
CollectAlluxioInfoCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } }
CollectAlluxioInfoCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectAlluxioInfoCommand(FileSystemContext fsContext); }
CollectAlluxioInfoCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectAlluxioInfoCommand(FileSystemContext fsContext); @Override String getCommandName(); @Override String getUsage(); @Override String getDescription(); }
CollectAlluxioInfoCommand extends ExecuteShellCollectInfoCommand { @Override public String getCommandName() { return COMMAND_NAME; } CollectAlluxioInfoCommand(FileSystemContext fsContext); @Override String getCommandName(); @Override String getUsage(); @Override String getDescription(); static final String COMMAND_NAME; }