Java Code Examples for org.apache.commons.io.FileUtils#forceDeleteOnExit()

The following examples show how to use org.apache.commons.io.FileUtils#forceDeleteOnExit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLog.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  transactionID = 0;
  checkpointDir = Files.createTempDir();
  FileUtils.forceDeleteOnExit(checkpointDir);
  Assert.assertTrue(checkpointDir.isDirectory());
  dataDirs = new File[3];
  for (int i = 0; i < dataDirs.length; i++) {
    dataDirs[i] = Files.createTempDir();
    Assert.assertTrue(dataDirs[i].isDirectory());
  }
  log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
      MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
          checkpointDir).setLogDirs(dataDirs)
          .setChannelName("testlog").build();
  log.replay();
}
 
Example 2
Source File: KnoxCLI.java    From knox with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param t - Topology to use for config
 * @return - path of shiro.ini config file.
 */
protected String getConfig(Topology t){
  File tmpDir = new File(System.getProperty("java.io.tmpdir"));
  DeploymentFactory.setGatewayServices(services);
  EnterpriseArchive archive = DeploymentFactory.createDeployment(getGatewayConfig(), t);
  File war = archive.as(ExplodedExporter.class).exportExploded(tmpDir, t.getName() + "_deploy.tmp");
  war.deleteOnExit();
  String config = war.getAbsolutePath() + "/%2F/WEB-INF/shiro.ini";
  try{
    FileUtils.forceDeleteOnExit(war);
  } catch (IOException e) {
    out.println(e.toString());
    war.deleteOnExit();
  }
  return config;
}
 
Example 3
Source File: AbstractSecurityTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.AfterClass
public static void cleanup() throws IOException {
    String tmpDir = System.getProperty("java.io.tmpdir");
    if (tmpDir != null) {
        File[] tmpFiles = new File(tmpDir).listFiles();
        if (tmpFiles != null) {
            for (File tmpFile : tmpFiles) {
                if (tmpFile.exists() && (tmpFile.getName().startsWith("ws-security.nonce.cache.instance")
                        || tmpFile.getName().startsWith("ws-security.timestamp.cache.instance")
                        || tmpFile.getName().startsWith("ws-security.saml.cache.instance")
                        || tmpFile.getName().startsWith("wss4j-nonce-cache")
                        || tmpFile.getName().startsWith("wss4j-timestamp-cache"))) {
                    FileUtils.forceDeleteOnExit(tmpFile);
                }
            }
        }
    }
}
 
Example 4
Source File: ShellCommand.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void operationsLoaded(ArtifactDescriptor artifact, ResolvedDependency operations,
        RugResolver resolver) {
    if (artifact != null && operations != null) {
        FileArtifact file = MetadataWriter.createWithoutExcludes(operations.rugs(),
                artifact, source, null, Constants.cliClient());

        try {
            FileUtils.write(ShellUtils.SHELL_OPERATIONS, file.content(),
                    StandardCharsets.ISO_8859_1);
            FileUtils.forceDeleteOnExit(ShellUtils.SHELL_OPERATIONS);
        }
        catch (IOException e) {
            // We can't write the operations out to a file, so what?
        }
    }
}
 
Example 5
Source File: DistributedLogCluster.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public void stop() throws Exception {
    if (null != dlServer) {
        this.dlServer.shutdown();
    }
    this.dlmEmulator.teardown();
    if (null != this.zks) {
        this.zks.stop();
    }
    for (File dir : tmpDirs) {
        FileUtils.forceDeleteOnExit(dir);
    }
}
 
Example 6
Source File: ObservingFSFlowEdgeTemplateCatalogTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
  URI flowTemplateCatalogUri = this.getClass().getClassLoader().getResource("template_catalog").toURI();
  this.templateDir = Files.createTempDir();
  FileUtils.forceDeleteOnExit(templateDir);
  FileUtils.copyDirectory(new File(flowTemplateCatalogUri.getPath()), templateDir);
  Properties properties = new Properties();
  properties.put(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY, templateDir.toURI().toString());
  properties.put(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, "1000");
  Config config = ConfigFactory.parseProperties(properties);
  this.templateCatalogCfg = config.withValue(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY,
      config.getValue(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY));
}
 
Example 7
Source File: MongoDbInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
  // Create a fake 'mongo'
  final File mongoFile = new File(MONGO_SHELL);
  try {
    FileUtils.write(mongoFile, (IS_WINDOWS ? "@echo off\ntype \"%3%\"" : "cat \"$3\""));
    FileUtils.forceDeleteOnExit(mongoFile);
  }
  catch (IOException ex) {
    System.out.println(ex.getMessage());
  }
}
 
Example 8
Source File: Groovy2PluginTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setup() throws Exception {
    //Module.setModuleLogger(new StreamModuleLogger(System.err));
    uncompilableArchiveDir = Files.createTempDirectory(Groovy2PluginTest.class.getSimpleName()+"_");
    FileUtils.forceDeleteOnExit(uncompilableArchiveDir.toFile());
    uncompilableScriptRelativePath = Paths.get("Uncompilable.groovy");
    byte[] randomBytes = new byte[1024];
    RANDOM.nextBytes(randomBytes);
    Files.write(uncompilableArchiveDir.resolve(uncompilableScriptRelativePath), randomBytes);
}
 
Example 9
Source File: TestDistributedLogBase.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void teardownCluster() throws Exception {
    bkutil.teardown();
    zks.stop();
    for (File dir : tmpDirs) {
        FileUtils.forceDeleteOnExit(dir);
    }
}
 
Example 10
Source File: ZooKeeperClusterTestCase.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void shutdownZooKeeper() throws Exception {
    zks.stop();
    if (null != zkDir) {
        FileUtils.forceDeleteOnExit(zkDir);
    }
}
 
Example 11
Source File: JarArchiveRepositoryTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeClass
public void setup() throws Exception {
    rootArchiveDirectory = Files.createTempDirectory(JarArchiveRepositoryTest.class.getSimpleName()+"_");
    FileUtils.forceDeleteOnExit(rootArchiveDirectory.toFile());
    super.setup();
}
 
Example 12
Source File: DetectGenderAgeFromFileExample.java    From cognitivej with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"), System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(IMAGE_LOCATION), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    CognitiveJColourPalette colourPalette = CognitiveJColourPalette.STRAWBERRY;
    List<Face> faces = faceScenarios.findFaces(imageFile);
    faces.forEach(face -> imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL,
            ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, colourPalette).writeAge(face, colourPalette, RectangleTextPosition.TOP_OF));
    imageOverlayBuilder.launchViewer();

}
 
Example 13
Source File: DetectSingleFaceFromFileExample.java    From cognitivej with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL).launchViewer();
}
 
Example 14
Source File: MongoDbInterpreterTest.java    From zeppelin-mongodb-interpreter with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
  // Create a fake 'mongo'
  final File mongoFile = new File(MONGO_SHELL);
  try {
    FileUtils.write(mongoFile, (IS_WINDOWS ? "@echo off\ntype \"%2%\"" : "cat \"$2\""));
    FileUtils.forceDeleteOnExit(mongoFile);
  }
  catch (IOException e) {
  }
}
 
Example 15
Source File: TestUtilities.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public static void initializePluginDirectories() throws Exception {
	File pluginDir = getPluginsDirectory();
	if (pluginDir.exists()) {
		FileUtils.forceDelete(pluginDir);
	}
	FileUtils.forceMkdir(pluginDir);
	FileUtils.forceDeleteOnExit(pluginDir);
}
 
Example 16
Source File: PathArchiveRepositoryTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeClass
public void setup() throws Exception {
    rootArchiveDirectory = Files.createTempDirectory(PathRepositoryPollerTest.class.getSimpleName()+"_");
    FileUtils.forceDeleteOnExit(rootArchiveDirectory.toFile());
    super.setup();
}
 
Example 17
Source File: ArchiveRepositoryPollerTest.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void classSetup() throws Exception {
    Path rootArchiveDirectory = Files.createTempDirectory(ArchiveRepositoryPollerTest.class.getSimpleName()+"_");
    logger.info("rootArchiveDirectory: {}", rootArchiveDirectory);
    FileUtils.forceDeleteOnExit(rootArchiveDirectory.toFile());

    archiveRepository = createArchiveRepository(rootArchiveDirectory);
    long now = System.currentTimeMillis();
    deployJarArchive(TEST_TEXT_JAR, now);
    deployJarArchive(TEST_MODULE_SPEC_JAR, now);
}
 
Example 18
Source File: MergeCuboidJobTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    // String input =
    // "src/test/resources/data/base_cuboid,src/test/resources/data/6d_cuboid";
    String output = "target/test-output/merged_cuboid";
    String cubeName = "test_kylin_cube_with_slr_ready";
    String jobname = "merge_cuboid";

    File baseFolder = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "base");
    FileUtils.forceDelete(baseFolder);
    baseFolder.mkdir();
    FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), baseFolder);
    FileUtils.forceDeleteOnExit(baseFolder);

    File eightFoler = File.createTempFile("kylin-f24668f6-dcff-4cb6-a89b-77f1119df8fa-", "8d");
    FileUtils.forceDelete(eightFoler);
    eightFoler.mkdir();
    FileUtils.copyDirectory(new File("src/test/resources/data/base_cuboid"), eightFoler);
    FileUtils.forceDeleteOnExit(eightFoler);

    FileUtil.fullyDelete(new File(output));

    // CubeManager cubeManager =
    // CubeManager.getInstanceFromEnv(getTestConfig());

    String[] args = { "-input", baseFolder.getAbsolutePath() + "," + eightFoler.getAbsolutePath(), "-cubename", cubeName, "-segmentname", "20130331080000_20131212080000", "-output", output, "-jobname", jobname };
    assertEquals("Job failed", 0, ToolRunner.run(conf, new MergeCuboidJob(), args));

}
 
Example 19
Source File: SchedulerUtilsTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setUp()
    throws IOException {
  this.jobConfigDir = java.nio.file.Files.createTempDirectory(
      String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
  FileUtils.forceDeleteOnExit(this.jobConfigDir);
  this.subDir1 = new File(this.jobConfigDir, "test1");
  this.subDir11 = new File(this.subDir1, "test11");
  this.subDir2 = new File(this.jobConfigDir, "test2");

  this.subDir1.mkdirs();
  this.subDir11.mkdirs();
  this.subDir2.mkdirs();

  Properties rootProps = new Properties();
  rootProps.setProperty("k1", "a1");
  rootProps.setProperty("k2", "a2");
  // test-job-conf-dir/root.properties
  rootProps.store(new FileWriter(new File(this.jobConfigDir, "root.properties")), "");

  Properties props1 = new Properties();
  props1.setProperty("k1", "b1");
  props1.setProperty("k3", "a3");
  // test-job-conf-dir/test1/test.properties
  props1.store(new FileWriter(new File(this.subDir1, "test.properties")), "");

  Properties jobProps1 = new Properties();
  jobProps1.setProperty("k1", "c1");
  jobProps1.setProperty("k3", "b3");
  jobProps1.setProperty("k6", "a6");
  // test-job-conf-dir/test1/test11.pull
  jobProps1.store(new FileWriter(new File(this.subDir1, "test11.pull")), "");

  Properties jobProps2 = new Properties();
  jobProps2.setProperty("k7", "a7");
  // test-job-conf-dir/test1/test12.PULL
  jobProps2.store(new FileWriter(new File(this.subDir1, "test12.PULL")), "");

  Properties jobProps3 = new Properties();
  jobProps3.setProperty("k1", "d1");
  jobProps3.setProperty("k8", "a8");
  jobProps3.setProperty("k9", "${k8}");
  // test-job-conf-dir/test1/test11/test111.pull
  jobProps3.store(new FileWriter(new File(this.subDir11, "test111.pull")), "");

  Properties props2 = new Properties();
  props2.setProperty("k2", "b2");
  props2.setProperty("k5", "a5");
  // test-job-conf-dir/test2/test.properties
  props2.store(new FileWriter(new File(this.subDir2, "test.PROPERTIES")), "");

  Properties jobProps4 = new Properties();
  jobProps4.setProperty("k5", "b5");
  // test-job-conf-dir/test2/test21.PULL
  jobProps4.store(new FileWriter(new File(this.subDir2, "test21.PULL")), "");
}
 
Example 20
Source File: FileLoadTest.java    From hugegraph-loader with Apache License 2.0 4 votes vote down vote up
@Test
public void testReloadJsonFailureFiles() throws IOException,
                                                InterruptedException {
    ioUtil.write("vertex_person.csv",
                 "name,age,city",
                 "marko,29,Beijing",
                 "vadas,27,Hongkong",
                 "tom,28,Wuhan");
    ioUtil.write("edge_knows.json",
                 "{\"source_name\": \"marko\", \"target_name\": " +
                 "\"vadas\", \"date\": \"2016-01-10 12:00:00\"," +
                 "\"weight\": 0.5}",
                 // unexisted source and target vertex
                 "{\"source_name\": \"marko1\", \"target_name\": " +
                 "\"vadas1\", \"date\": \"2013-02-20 13:00:00\"," +
                 "\"weight\": 1.0}");

    String[] args = new String[]{
            "-f", structPath("reload_json_failure_files/struct.json"),
            "-s", configPath("reload_json_failure_files/schema.groovy"),
            "-g", GRAPH,
            "-h", SERVER,
            "--check-vertex", "true",
            "--batch-insert-threads", "2",
            "--test-mode", "false"
    };
    HugeGraphLoader loader = new HugeGraphLoader(args);
    loader.load();
    LoadContext context = Whitebox.getInternalState(loader, "context");

    List<Edge> edges = CLIENT.graph().listEdges();
    Assert.assertEquals(1, edges.size());

    Map<String, InputProgress> inputProgressMap = context.newProgress()
                                                         .inputProgress();
    Assert.assertEquals(2, inputProgressMap.size());
    Assert.assertEquals(ImmutableSet.of("1", "2"),
                        inputProgressMap.keySet());
    inputProgressMap.forEach((id, value) -> {
        if (id.equals("2")) {
            // The error line is exactly last line
            Set<InputItemProgress> loadedItems = value.loadedItems();
            Assert.assertEquals(1, loadedItems.size());

            InputItemProgress loadedItem = loadedItems.iterator().next();
            FileItemProgress fileItem = (FileItemProgress) loadedItem;
            Assert.assertEquals("edge_knows.json", fileItem.name());
            Assert.assertEquals(2, fileItem.offset());
        }
    });

    // Load failure data without modification
    args = new String[]{
            "-f", structPath("reload_json_failure_files/struct.json"),
            "-g", GRAPH,
            "-h", SERVER,
            "--failure-mode", "true",
            "--check-vertex", "true",
            "--batch-insert-threads", "2",
            "--test-mode", "false"
    };
    // No exception throw, but error line still exist
    HugeGraphLoader.main(args);
    Thread.sleep(1000);

    // Reload with modification
    File structDir = FileUtils.getFile(structPath(
                     "reload_json_failure_files/struct"));
    File failureDir = FileUtils.getFile(structPath(
                      "reload_json_failure_files/struct/failure-data/"));
    File[] files = failureDir.listFiles();
    Arrays.sort(files, Comparator.comparing(File::getName));
    Assert.assertNotNull(files);
    Assert.assertEquals(1, files.length);

    File knowsFailureFile = files[0];
    List<String> failureLines = FileUtils.readLines(knowsFailureFile,
                                                    Constants.CHARSET);
    Assert.assertEquals(2, failureLines.size());
    Assert.assertEquals("{\"source_name\": \"marko1\", \"target_name\": " +
                        "\"vadas1\", \"date\": \"2013-02-20 13:00:00\"," +
                        "\"weight\": 1.0}",
                        failureLines.get(1));

    failureLines.remove(1);
    failureLines.add("{\"source_name\": \"marko\", \"target_name\": " +
                     "\"tom\", \"date\": \"2013-02-20 13:00:00\"," +
                     "\"weight\": 1.0}");
    FileUtils.writeLines(knowsFailureFile, failureLines, false);

    // No exception throw, and error line doesn't exist
    HugeGraphLoader.main(args);

    edges = CLIENT.graph().listEdges();
    Assert.assertEquals(2, edges.size());

    FileUtils.forceDeleteOnExit(structDir);
}