Example usage for org.apache.hadoop.fs FileContext setTimes

List of usage examples for org.apache.hadoop.fs FileContext setTimes

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileContext setTimes.

Prototype

public void setTimes(final Path f, final long mtime, final long atime)
        throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException 

Source Link

Document

Set access time of a file.

Usage

From source file:com.ikanow.aleph2.core.shared.utils.TestJarCacheUtils.java

License:Apache License

@Test
public void test_localFilePresentButOld()
        throws InterruptedException, ExecutionException, AccessControlException, FileAlreadyExistsException,
        FileNotFoundException, ParentNotDirectoryException, IOException {

    final FileContext localfs = FileContext.getLocalFSFileContext(new Configuration());

    String java_name = _globals.local_cached_jar_dir() + File.separator + "testX.cache.jar";
    final String expected_cache_name = java_name.replace(File.separator, "/");
    final Path expected_cache_path = localfs.makeQualified(new Path(expected_cache_name));

    // Just make sure we've deleted the old file
    try {/*from w  w  w  .  j a  v a 2 s. com*/
        System.out.println("Deleted: " + new File(java_name).delete());
    } catch (Exception e) {
        fail("Misc Error: " + e);
    }

    assertTrue("Remote file exists", new File(_test_file_path).exists());
    assertFalse("Local file doesn't exist: " + java_name, new File(java_name).exists());

    // Now create the file

    localfs.create(expected_cache_path, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE));

    localfs.setTimes(expected_cache_path, 0L, 0L);

    // check something has happened:
    assertEquals(0L, localfs.getFileStatus(expected_cache_path).getModificationTime());
    assertNotEquals(0L, _test_file_time);

    // Now run the test routine

    final SharedLibraryBean library_bean = BeanTemplateUtils.build(SharedLibraryBean.class)
            .with(SharedLibraryBean::path_name, _test_file_path).with(SharedLibraryBean::_id, "testX").done()
            .get();

    final Validation<BasicMessageBean, String> ret_val_1 = JarCacheUtils.getCachedJar(
            _globals.local_cached_jar_dir(), library_bean, _mock_hdfs, "testX", new TestMessageBean()).get();

    assertEquals(expected_cache_path.toString(), ret_val_1.success());

    assertTrue("Local file still exists", new File(expected_cache_name).exists());

    assertTrue("File time should have been updated",
            localfs.getFileStatus(expected_cache_path).getModificationTime() >= _test_file_time);
}

From source file:com.ikanow.aleph2.core.shared.utils.TestJarCacheUtils.java

License:Apache License

@Test
public void test_localFilePresentAndNew()
        throws InterruptedException, ExecutionException, AccessControlException, FileAlreadyExistsException,
        FileNotFoundException, ParentNotDirectoryException, IOException {

    final FileContext localfs = FileContext.getLocalFSFileContext(new Configuration());

    final String expected_cache_name = _globals.local_cached_jar_dir().replace(File.separator, "/")
            + "test1.cache.jar";
    final Path expected_cache_path = localfs.makeQualified(new Path(expected_cache_name));

    // Just make sure we've deleted the old file
    try {//w w w  .  j  a v  a2s .  c o m
        new File(expected_cache_name).delete();
    } catch (Exception e) {
    }

    assertTrue("Remote file exists", new File(_test_file_path).exists());
    assertFalse("Local file doesn't exist", new File(expected_cache_name).exists());

    // Now create the file

    localfs.create(expected_cache_path, EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE));

    localfs.setTimes(expected_cache_path, _test_file_time + 10000, _test_file_time + 10000);

    // check something has happened:
    assertEquals(_test_file_time + 10000, localfs.getFileStatus(expected_cache_path).getModificationTime());

    // Now run the test routine

    final SharedLibraryBean library_bean = BeanTemplateUtils.build(SharedLibraryBean.class)
            .with(SharedLibraryBean::path_name, _test_file_path).with(SharedLibraryBean::_id, "test1").done()
            .get();

    final Validation<BasicMessageBean, String> ret_val_1 = JarCacheUtils.getCachedJar(
            _globals.local_cached_jar_dir(), library_bean, _mock_hdfs, "test1", new TestMessageBean()).get();

    assertEquals(expected_cache_path.toString(), ret_val_1.success());

    assertTrue("Local file still exists", new File(expected_cache_name).exists());

    assertEquals(localfs.getFileStatus(expected_cache_path).getModificationTime(), _test_file_time + 10000);
}