List of usage examples for org.apache.commons.io FileUtils deleteDirectory
public static void deleteDirectory(File directory) throws IOException
From source file:com.linkedin.pinot.core.segment.index.loader.LoaderUtilsTest.java
@Test public void testReloadFailureRecovery() throws IOException { String segmentName = "dummySegment"; String indexFileName = "dummyIndex"; File indexDir = new File(TEST_DIR, segmentName); File segmentBackupDir = new File(TEST_DIR, segmentName + CommonConstants.Segment.SEGMENT_BACKUP_DIR_SUFFIX); File segmentTempDir = new File(TEST_DIR, segmentName + CommonConstants.Segment.SEGMENT_TEMP_DIR_SUFFIX); // Only index directory exists (normal case, or failed before the first renaming) Assert.assertTrue(indexDir.mkdir()); FileUtils.touch(new File(indexDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Only segment backup directory exists (failed after the first renaming but before copying happened) Assert.assertTrue(segmentBackupDir.mkdir()); FileUtils.touch(new File(segmentBackupDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Index directory and segment backup directory exist (failed before second renaming) Assert.assertTrue(indexDir.mkdir()); Assert.assertTrue(segmentBackupDir.mkdir()); FileUtils.touch(new File(segmentBackupDir, indexFileName)); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); // Index directory and segment temporary directory exist (failed after second renaming) Assert.assertTrue(indexDir.mkdir()); FileUtils.touch(new File(indexDir, indexFileName)); Assert.assertTrue(segmentTempDir.mkdir()); LoaderUtils.reloadFailureRecovery(indexDir); Assert.assertTrue(indexDir.exists()); Assert.assertTrue(new File(indexDir, indexFileName).exists()); Assert.assertFalse(segmentBackupDir.exists()); Assert.assertFalse(segmentTempDir.exists()); FileUtils.deleteDirectory(indexDir); }
From source file:ms.dew.devops.kernel.plugin.appkind.frontend_node.FrontendNodePrepareFlow.java
protected void postPrepareBuild(FinalProjectConfig config, String flowBasePath) throws IOException { FileUtils.deleteDirectory(new File(flowBasePath + "dist")); Files.move(Paths.get(config.getDirectory() + "dist"), Paths.get(flowBasePath + "dist"), StandardCopyOption.REPLACE_EXISTING); }
From source file:com.indeed.lsmtree.core.TestImmutableBTreeIndex.java
@Override public void tearDown() throws Exception { FileUtils.deleteDirectory(tmpDir); }
From source file:dao.CheckIfFileExistsDaoTest.java
@After public void tearDown() { String fSeparator = File.separator; File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook"); try {//from w ww. ja v a2 s. com FileUtils.deleteDirectory(file); } catch (IOException ex) { Logger.getLogger(CheckIfFileExistsDaoTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.searchcode.app.jobs.DeleteRepositoryJob.java
public void execute(JobExecutionContext context) throws JobExecutionException { if (!Singleton.getSharedService().getBackgroundJobsEnabled()) { return;// w w w .ja v a2 s . c o m } List<String> persistentDelete = Singleton.getDataService().getPersistentDelete(); if (persistentDelete.isEmpty()) { return; } RepoResult rr = Singleton.getRepo().getRepoByName(persistentDelete.get(0)); if (rr == null) { Singleton.getDataService().removeFromPersistentDelete(persistentDelete.get(0)); return; } try { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); Singleton.getUniqueGitRepoQueue().delete(rr); if (Singleton.getRunningIndexRepoJobs().containsKey(rr.getName())) { return; } Singleton.getLogger().info("Deleting repository. " + rr.getName()); Singleton.getCodeIndexer().deleteByReponame(rr.getName()); // remove the directory String repoLocations = Properties.getProperties().getProperty(Values.REPOSITORYLOCATION, Values.DEFAULTREPOSITORYLOCATION); FileUtils.deleteDirectory(new File(repoLocations + rr.getName() + "/")); // Remove from the database Singleton.getRepo().deleteRepoByName(rr.getName()); // Remove from the persistent queue Singleton.getDataService().removeFromPersistentDelete(rr.getName()); } catch (Exception ignored) { } }
From source file:io.druid.indexing.common.tasklogs.HdfsTaskLogsTest.java
@Test public void testSimple() throws Exception { final File tmpDir = Files.createTempDir(); try {//from w w w. j av a 2s .co m final File logDir = new File(tmpDir, "logs"); final File logFile = new File(tmpDir, "log"); Files.write("blah", logFile, Charsets.UTF_8); final TaskLogs taskLogs = new HdfsTaskLogs(new HdfsTaskLogsConfig(logDir.toString()), new Configuration()); taskLogs.pushTaskLog("foo", logFile); final Map<Long, String> expected = ImmutableMap.of(0L, "blah", 1L, "lah", -2L, "ah", -5L, "blah"); for (Map.Entry<Long, String> entry : expected.entrySet()) { final byte[] bytes = ByteStreams .toByteArray(taskLogs.streamTaskLog("foo", entry.getKey()).get().getInput()); final String string = new String(bytes); Assert.assertEquals(String.format("Read with offset %,d", entry.getKey()), string, entry.getValue()); } } finally { FileUtils.deleteDirectory(tmpDir); } }
From source file:com.linkedin.pinot.tools.data.generator.DataGenerator.java
public void init(DataGeneratorSpec spec) throws IOException { genSpec = spec;//from w w w . j a v a 2 s . c o m outDir = new File(genSpec.getOutputDir()); if (outDir.exists() && !genSpec.isOverrideOutDir()) { LOGGER.error("output directory already exists, and override is set to false"); throw new RuntimeException("output directory exists"); } if (outDir.exists()) { FileUtils.deleteDirectory(outDir); } outDir.mkdir(); for (final String column : genSpec.getColumns()) { DataType dataType = genSpec.getDataTypesMap().get(column); if (genSpec.getCardinalityMap().containsKey(column)) { generators.put(column, GeneratorFactory.getGeneratorFor(dataType, genSpec.getCardinalityMap().get(column))); } else if (genSpec.getRangeMap().containsKey(column)) { IntRange range = genSpec.getRangeMap().get(column); generators.put(column, GeneratorFactory.getGeneratorFor(dataType, range.getMinimumInteger(), range.getMaximumInteger())); } else { LOGGER.error("cardinality for this column does not exist : " + column); throw new RuntimeException("cardinality for this column does not exist"); } generators.get(column).init(); } }
From source file:com.pivotal.hawq.mapreduce.SimpleTableClusterTester.java
@Override protected void testSimpleTable(HAWQTable table, Class<? extends Mapper> mapperClass) throws Exception { final String tableName = table.getTableName(); final String caseName = tableName.replaceAll("\\.", "_"); System.out.println("Executing test case: " + caseName); final File caseFolder = new File(FT_TEST_FOLDER, caseName); final File sqlFile = new File(caseFolder, caseName + ".sql"); final File answerFile = new File(caseFolder, caseName + ".ans"); final File outputFile = new File(caseFolder, caseName + ".out"); if (caseFolder.exists()) { FileUtils.deleteDirectory(caseFolder); }/*from w ww . j a v a 2s .c o m*/ caseFolder.mkdir(); Connection conn = null; List<String> answers; try { conn = MRFormatTestUtils.getTestDBConnection(); // 1. prepare test data String setupSQLs = table.generateDDL() + table.generateData(); Files.write(setupSQLs.getBytes(), sqlFile); MRFormatTestUtils.runSQLs(conn, setupSQLs); // 2. generate answer answers = MRFormatTestUtils.dumpTable(conn, tableName); Collections.sort(answers); Files.write(Joiner.on('\n').join(answers).getBytes(), answerFile); } finally { HAWQJdbcUtils.closeConnection(conn); } // 3. run input format driver int exitCode = MRFormatTestUtils.runMapReduceOnCluster(tableName, HDFS_OUTPUT_PATH, mapperClass); Assert.assertEquals(0, exitCode); // 4. copy hdfs output to local final Path hdfsOutputFile = new Path(HDFS_OUTPUT_PATH, "part-r-00000"); MRFormatTestUtils.runShellCommand( String.format("hadoop fs -copyToLocal %s %s", hdfsOutputFile.toString(), outputFile.getPath())); // 5. compare result List<String> outputs = Files.readLines(outputFile, Charsets.UTF_8); checkOutput(answers, outputs, table); System.out.println("Successfully finish test case: " + caseName); }
From source file:eulermind.TestMindDB.java
public void tearDown() { try {/*from ww w . ja v a 2 s .c o m*/ FileUtils.deleteDirectory(new File(m_dbPath)); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:com.ebay.jetstream.event.channel.kafka.TestKafkaServer.java
public void stop() { kafkaServer.shutdown();/*w ww .j av a 2 s . c o m*/ try { FileUtils.deleteDirectory(locate); } catch (IOException e) { e.printStackTrace(); } System.out.println("embedded kafka stop"); }