Search in sources :

Example 1 with FileTime

use of java.nio.file.attribute.FileTime in project hadoop by apache.

the class RawLocalFileSystem method setTimes.

/**
   * Sets the {@link Path}'s last modified time and last access time to
   * the given valid times.
   *
   * @param mtime the modification time to set (only if no less than zero).
   * @param atime the access time to set (only if no less than zero).
   * @throws IOException if setting the times fails.
   */
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
    try {
        BasicFileAttributeView view = Files.getFileAttributeView(pathToFile(p).toPath(), BasicFileAttributeView.class);
        FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
        FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
        view.setTimes(fmtime, fatime, null);
    } catch (NoSuchFileException e) {
        throw new FileNotFoundException("File " + p + " does not exist");
    }
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) FileTime(java.nio.file.attribute.FileTime)

Example 2 with FileTime

use of java.nio.file.attribute.FileTime in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiAvoidsRebuild.

@Test
public void testFileChangeThatDoesNotModifyAbiAvoidsRebuild() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "rulekey_changed_while_abi_stable", tmp);
    workspace.setUp();
    // Run `buck build`.
    BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
    BuildTarget utilTarget = BuildTargetFactory.newInstance("//:util");
    ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    Path utilRuleKeyPath = BuildTargets.getScratchPath(filesystem, utilTarget, ".%s/metadata/RULE_KEY");
    String utilRuleKey = getContents(utilRuleKeyPath);
    Path utilAbiRuleKeyPath = BuildTargets.getScratchPath(filesystem, utilTarget, ".%s/metadata/INPUT_BASED_RULE_KEY");
    String utilAbiRuleKey = getContents(utilAbiRuleKeyPath);
    Path bizRuleKeyPath = BuildTargets.getScratchPath(filesystem, bizTarget, ".%s/metadata/RULE_KEY");
    String bizRuleKey = getContents(bizRuleKeyPath);
    Path bizAbiRuleKeyPath = BuildTargets.getScratchPath(filesystem, bizTarget, ".%s/metadata/INPUT_BASED_RULE_KEY");
    String bizAbiRuleKey = getContents(bizAbiRuleKeyPath);
    Path utilOutputPath = BuildTargets.getGenPath(filesystem, utilTarget, "lib__%s__output/" + utilTarget.getShortName() + ".jar");
    long utilJarSize = Files.size(workspace.getPath(utilOutputPath));
    Path bizOutputPath = BuildTargets.getGenPath(filesystem, bizTarget, "lib__%s__output/" + bizTarget.getShortName() + ".jar");
    FileTime bizJarLastModified = Files.getLastModifiedTime(workspace.getPath(bizOutputPath));
    // TODO(bolinfest): Run uber-biz.jar and verify it prints "Hello World!\n".
    // Edit Util.java in a way that does not affect its ABI.
    workspace.replaceFileContents("Util.java", "Hello World", "Hola Mundo");
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
    buildResult2.assertSuccess("Successful build should exit with 0.");
    assertThat(utilRuleKey, not(equalTo(getContents(utilRuleKeyPath))));
    assertThat(utilAbiRuleKey, not(equalTo(getContents(utilAbiRuleKeyPath))));
    workspace.getBuildLog().assertTargetBuiltLocally(utilTarget.toString());
    assertThat(bizRuleKey, not(equalTo(getContents(bizRuleKeyPath))));
    assertEquals(bizAbiRuleKey, getContents(bizAbiRuleKeyPath));
    workspace.getBuildLog().assertTargetHadMatchingInputRuleKey(bizTarget.toString());
    assertThat("util.jar should have been rewritten, so its file size should have changed.", utilJarSize, not(equalTo(Files.size(workspace.getPath(utilOutputPath)))));
    assertEquals("biz.jar should not have been rewritten, so its last-modified time should be the same.", bizJarLastModified, Files.getLastModifiedTime(workspace.getPath(bizOutputPath)));
    // TODO(bolinfest): Run uber-biz.jar and verify it prints "Hola Mundo!\n".
    // TODO(bolinfest): This last scenario that is being tested would be better as a unit test.
    // Run `buck build` one last time. This ensures that a dependency java_library() rule (:util)
    // that is built via BuildRuleSuccess.Type.MATCHING_INPUT_BASED_RULE_KEY does not
    // explode when its dependent rule (:biz) invokes the dependency's getAbiKey() method as part of
    // its own getAbiKeyForDeps().
    ProcessResult buildResult3 = workspace.runBuckCommand("build", "//:biz");
    buildResult3.assertSuccess("Successful build should exit with 0.");
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) FileTime(java.nio.file.attribute.FileTime) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with FileTime

use of java.nio.file.attribute.FileTime in project jna by java-native-access.

the class Kernel32Test method testFileTimeFromLargeInteger.

/**
     * Test FILETIME's LARGE_INTEGER constructor
     * @throws IOException
     */
public final void testFileTimeFromLargeInteger() throws IOException {
    File tmp = File.createTempFile("testGetFileInformationByHandleEx", "jna");
    tmp.deleteOnExit();
    HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
    assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
    try {
        Memory p = new Memory(FILE_BASIC_INFO.sizeOf());
        if (false == Kernel32.INSTANCE.GetFileInformationByHandleEx(hFile, WinBase.FileBasicInfo, p, new DWORD(p.size()))) {
            fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
        }
        FILE_BASIC_INFO fbi = new FILE_BASIC_INFO(p);
        FILETIME ft = new FILETIME(fbi.LastWriteTime);
        SYSTEMTIME stUTC = new SYSTEMTIME();
        SYSTEMTIME stLocal = new SYSTEMTIME();
        Kernel32.INSTANCE.FileTimeToSystemTime(ft, stUTC);
        // Covert to local
        Kernel32.INSTANCE.SystemTimeToTzSpecificLocalTime(null, stUTC, stLocal);
        FileTime calculatedCreateTime = FileTime.fromMillis(stLocal.toCalendar().getTimeInMillis());
        // Actual file's createTime
        FileTime createTime = Files.getLastModifiedTime(Paths.get(tmp.getAbsolutePath()));
        assertEquals(createTime.toMillis(), calculatedCreateTime.toMillis());
    } finally {
        Kernel32.INSTANCE.CloseHandle(hFile);
    }
}
Also used : FILETIME(com.sun.jna.platform.win32.WinBase.FILETIME) Memory(com.sun.jna.Memory) SYSTEMTIME(com.sun.jna.platform.win32.WinBase.SYSTEMTIME) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) FileTime(java.nio.file.attribute.FileTime) File(java.io.File) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) FILE_BASIC_INFO(com.sun.jna.platform.win32.WinBase.FILE_BASIC_INFO)

Example 4 with FileTime

use of java.nio.file.attribute.FileTime in project pinot by linkedin.

the class HllIndexCreationTest method testConvert.

@Test
public void testConvert() throws Exception {
    SegmentWithHllIndexCreateHelper helper = null;
    try {
        helper = new SegmentWithHllIndexCreateHelper("testConvert", getClass().getClassLoader().getResource(AVRO_DATA), timeColumnName, timeUnit, "starTreeSegment");
        SegmentIndexCreationDriver driver = helper.build(true, hllConfig);
        File segmentDirectory = new File(helper.getIndexDir(), driver.getSegmentName());
        LOGGER.debug("Segment Directory: " + segmentDirectory.getAbsolutePath());
        SegmentV1V2ToV3FormatConverter converter = new SegmentV1V2ToV3FormatConverter();
        converter.convert(segmentDirectory);
        File v3Location = SegmentDirectoryPaths.segmentDirectoryFor(segmentDirectory, SegmentVersion.v3);
        LOGGER.debug("v3Location: " + v3Location.getAbsolutePath());
        Assert.assertTrue(v3Location.exists());
        Assert.assertTrue(v3Location.isDirectory());
        Assert.assertTrue(new File(v3Location, V1Constants.STAR_TREE_INDEX_FILE).exists());
        SegmentMetadataImpl metadata = new SegmentMetadataImpl(v3Location);
        LOGGER.debug("metadata all columns: " + metadata.getAllColumns());
        Assert.assertEquals(metadata.getVersion(), SegmentVersion.v3.toString());
        Assert.assertTrue(new File(v3Location, V1Constants.SEGMENT_CREATION_META).exists());
        // Drop the star tree index file because it has invalid data
        // new File(v3Location, V1Constants.STAR_TREE_INDEX_FILE).delete();
        // new File(segmentDirectory, V1Constants.STAR_TREE_INDEX_FILE).delete();
        FileTime afterConversionTime = Files.getLastModifiedTime(v3Location.toPath());
        // verify that the segment loads correctly. This is necessary and sufficient
        // full proof way to ensure that segment is correctly translated
        IndexSegment indexSegment = Loaders.IndexSegment.load(segmentDirectory, ReadMode.mmap, v3LoadingConfig);
        Assert.assertNotNull(indexSegment);
        Assert.assertEquals(indexSegment.getSegmentName(), metadata.getName());
        Assert.assertEquals(SegmentVersion.v3, SegmentVersion.valueOf(indexSegment.getSegmentMetadata().getVersion()));
    } finally {
        if (helper != null) {
            helper.cleanTempDir();
        }
    }
}
Also used : SegmentIndexCreationDriver(com.linkedin.pinot.core.segment.creator.SegmentIndexCreationDriver) IndexSegment(com.linkedin.pinot.core.indexsegment.IndexSegment) SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) FileTime(java.nio.file.attribute.FileTime) File(java.io.File) SegmentV1V2ToV3FormatConverter(com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter) Test(org.testng.annotations.Test)

Example 5 with FileTime

use of java.nio.file.attribute.FileTime in project pinot by linkedin.

the class SegmentPreProcessorTest method testV1CreateInvertedIndices.

@Test
public void testV1CreateInvertedIndices() throws Exception {
    constructSegment();
    SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(_segmentDirectoryFile);
    String segmentVersion = segmentMetadata.getVersion();
    Assert.assertEquals(SegmentVersion.valueOf(segmentVersion), SegmentVersion.v1);
    String col1FileName = segmentMetadata.getBitmapInvertedIndexFileName(COLUMN1_NAME, segmentVersion);
    String col7FileName = segmentMetadata.getBitmapInvertedIndexFileName(COLUMN7_NAME, segmentVersion);
    String col13FileName = segmentMetadata.getBitmapInvertedIndexFileName(COLUMN13_NAME, segmentVersion);
    String badColFileName = segmentMetadata.getBitmapInvertedIndexFileName(NO_SUCH_COLUMN_NAME, segmentVersion);
    File col1File = new File(_segmentDirectoryFile, col1FileName);
    File col7File = new File(_segmentDirectoryFile, col7FileName);
    File col13File = new File(_segmentDirectoryFile, col13FileName);
    File badColFile = new File(_segmentDirectoryFile, badColFileName);
    Assert.assertFalse(col1File.exists());
    Assert.assertTrue(col7File.exists());
    Assert.assertFalse(col13File.exists());
    Assert.assertFalse(badColFile.exists());
    FileTime col7LastModifiedTime = Files.getLastModifiedTime(col7File.toPath());
    // Sleep 2 seconds to prevent the same last modified time when modifying the file.
    Thread.sleep(2000);
    // Create inverted index the first time.
    checkInvertedIndexCreation(_segmentDirectoryFile, segmentMetadata, false);
    Assert.assertTrue(col1File.exists());
    Assert.assertTrue(col7File.exists());
    Assert.assertTrue(col13File.exists());
    Assert.assertFalse(badColFile.exists());
    Assert.assertEquals(Files.getLastModifiedTime(col7File.toPath()), col7LastModifiedTime);
    // Update inverted index file last modified time.
    FileTime col1LastModifiedTime = Files.getLastModifiedTime(col1File.toPath());
    FileTime col13LastModifiedTime = Files.getLastModifiedTime(col13File.toPath());
    // Sleep 2 seconds to prevent the same last modified time when modifying the file.
    Thread.sleep(2000);
    // Create inverted index the second time.
    checkInvertedIndexCreation(_segmentDirectoryFile, segmentMetadata, true);
    Assert.assertTrue(col1File.exists());
    Assert.assertTrue(col7File.exists());
    Assert.assertTrue(col13File.exists());
    Assert.assertFalse(badColFile.exists());
    Assert.assertEquals(Files.getLastModifiedTime(col1File.toPath()), col1LastModifiedTime);
    Assert.assertEquals(Files.getLastModifiedTime(col7File.toPath()), col7LastModifiedTime);
    Assert.assertEquals(Files.getLastModifiedTime(col13File.toPath()), col13LastModifiedTime);
}
Also used : SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) FileTime(java.nio.file.attribute.FileTime) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

FileTime (java.nio.file.attribute.FileTime)40 Path (java.nio.file.Path)11 File (java.io.File)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)6 IOException (java.io.IOException)5 SegmentMetadataImpl (com.linkedin.pinot.core.segment.index.SegmentMetadataImpl)4 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)3 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)2 IndexSegment (com.linkedin.pinot.core.indexsegment.IndexSegment)2 SegmentV1V2ToV3FormatConverter (com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter)2 FileNotFoundException (java.io.FileNotFoundException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 Date (java.util.Date)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1