ConvertDocumentCommand extends HystrixCommand<File> { public File convert() { logger.debug("Converting file {} to {}", inputFile.getAbsolutePath(), documentType.getFileExtension()); long convertStartTime = System.currentTimeMillis(), convertEndTime; Process process = null; File userProfileDir = createUniqueUserProfileDir(); try { String execStr = String.format(CONVERT_CMD_FORMAT, officeHome, userProfileDir.getAbsolutePath(), documentType.getConversionParam(), inputFile.getAbsolutePath(), outputDir.getAbsolutePath()); process = getRuntime().exec(execStr); process.waitFor(); File outFile = retrieveConvertedFile(); convertEndTime = System.currentTimeMillis(); logger.debug("Converted file: {};Document conversion process took {} ms.", outFile.getAbsolutePath(), convertEndTime-convertStartTime); if (!outFile.exists()) { logger.debug("converted file does not exist on filesystem: {}", outFile.getAbsolutePath()); throw new ConvertDocumentException(String.format("Output file not created: %s", outFile)); } return outFile; } catch (Exception e) { throw new ConvertDocumentException(e); } finally { if (process != null) { process.destroy(); } if (userProfileDir != null) { try { FileUtils.deleteDirectory(userProfileDir); } catch (IOException e) { throw new ConvertDocumentException(e); } } } } ConvertDocumentCommand(DocumentType documentType, String officeHome,
                                  File inputFile, File outputDir, Integer maxThreads, Integer timeoutMS);  ConvertDocumentCommand(DocumentType documentType, String officeHome,
                                  File inputFile, File outputDir, Integer maxThreads, Integer timeoutMS, int numRetries); File convert(); @Override File getFallback(); static final HystrixCommandGroupKey GROUP_KEY; static final HystrixCommandKey COMMAND_KEY; static final HystrixThreadPoolKey THREAD_KEY; }
@Test public void testConvert() { File output = testConvertCmdHtml.convert(); assertThat(output.getAbsolutePath(), is(mockOutputFileHtml.getAbsolutePath())); }