Search in sources :

Example 26 with FileTime

use of java.nio.file.attribute.FileTime in project jimfs by google.

the class AttributeServiceTest method testReadAttributes_asMap.

@Test
public void testReadAttributes_asMap() {
    File file = Directory.create(0);
    service.setInitialAttributes(file);
    ImmutableMap<String, Object> map = service.readAttributes(file, "test:foo,bar,baz");
    assertThat(map).isEqualTo(ImmutableMap.of("foo", "hello", "bar", 0L, "baz", 1));
    FileTime time = (FileTime) service.getAttribute(file, "basic:creationTime");
    map = service.readAttributes(file, "test:*");
    assertThat(map).isEqualTo(ImmutableMap.<String, Object>builder().put("foo", "hello").put("bar", 0L).put("baz", 1).put("fileKey", 0).put("isDirectory", true).put("isRegularFile", false).put("isSymbolicLink", false).put("isOther", false).put("size", 0L).put("lastModifiedTime", time).put("lastAccessTime", time).put("creationTime", time).build());
    map = service.readAttributes(file, "basic:*");
    assertThat(map).isEqualTo(ImmutableMap.<String, Object>builder().put("fileKey", 0).put("isDirectory", true).put("isRegularFile", false).put("isSymbolicLink", false).put("isOther", false).put("size", 0L).put("lastModifiedTime", time).put("lastAccessTime", time).put("creationTime", time).build());
}
Also used : FileTime(java.nio.file.attribute.FileTime) Test(org.junit.Test)

Example 27 with FileTime

use of java.nio.file.attribute.FileTime in project jimfs by google.

the class BasicAttributeProviderTest method testView.

@Test
public void testView() throws IOException {
    BasicFileAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);
    assertThat(view).isNotNull();
    assertThat(view.name()).isEqualTo("basic");
    BasicFileAttributes attrs = view.readAttributes();
    assertThat(attrs.fileKey()).isEqualTo(0);
    FileTime time = attrs.creationTime();
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);
    view.setTimes(null, null, null);
    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);
    view.setTimes(FileTime.fromMillis(0L), null, null);
    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileTime(java.nio.file.attribute.FileTime) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 28 with FileTime

use of java.nio.file.attribute.FileTime in project jimfs by google.

the class BasicAttributeProviderTest method testSet.

@Test
public void testSet() {
    FileTime time = FileTime.fromMillis(0L);
    // settable
    assertSetAndGetSucceeds("creationTime", time);
    assertSetAndGetSucceeds("lastModifiedTime", time);
    assertSetAndGetSucceeds("lastAccessTime", time);
    // unsettable
    assertSetFails("fileKey", 3L);
    assertSetFails("size", 1L);
    assertSetFails("isRegularFile", true);
    assertSetFails("isDirectory", true);
    assertSetFails("isSymbolicLink", true);
    assertSetFails("isOther", true);
    // invalid type
    assertSetFails("creationTime", "foo");
}
Also used : FileTime(java.nio.file.attribute.FileTime) Test(org.junit.Test)

Example 29 with FileTime

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

the class SegmentV1V2ToV3FormatConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    SegmentMetadataImpl beforeConversionMeta = new SegmentMetadataImpl(segmentDirectory);
    SegmentV1V2ToV3FormatConverter converter = new SegmentV1V2ToV3FormatConverter();
    converter.convert(segmentDirectory);
    File v3Location = SegmentDirectoryPaths.segmentDirectoryFor(segmentDirectory, SegmentVersion.v3);
    Assert.assertTrue(v3Location.exists());
    Assert.assertTrue(v3Location.isDirectory());
    Assert.assertTrue(new File(v3Location, V1Constants.STAR_TREE_INDEX_FILE).exists());
    SegmentMetadataImpl metadata = new SegmentMetadataImpl(v3Location);
    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()));
    FileTime afterLoadTime = Files.getLastModifiedTime(v3Location.toPath());
    Assert.assertEquals(afterConversionTime, afterLoadTime);
    // verify that SegmentMetadataImpl loaded from segmentDirectory correctly sets
    // metadata information after conversion. This has impacted us while loading
    // segments by triggering download. That's costly. That's also difficult to test
    Assert.assertFalse(new File(segmentDirectory, V1Constants.MetadataKeys.METADATA_FILE_NAME).exists());
    SegmentMetadataImpl metaAfterConversion = new SegmentMetadataImpl(segmentDirectory);
    Assert.assertNotNull(metaAfterConversion);
    Assert.assertFalse(metaAfterConversion.getCrc().equalsIgnoreCase(String.valueOf(Long.MIN_VALUE)));
    Assert.assertEquals(metaAfterConversion.getCrc(), beforeConversionMeta.getCrc());
    Assert.assertTrue(metaAfterConversion.getIndexCreationTime() != Long.MIN_VALUE);
    Assert.assertEquals(metaAfterConversion.getIndexCreationTime(), beforeConversionMeta.getIndexCreationTime());
}
Also used : 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) Test(org.testng.annotations.Test)

Example 30 with FileTime

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

the class SegmentPreProcessorTest method testV3CreateInvertedIndices.

@Test
public void testV3CreateInvertedIndices() throws Exception {
    constructSegment();
    // Convert segment format to v3.
    SegmentV1V2ToV3FormatConverter converter = new SegmentV1V2ToV3FormatConverter();
    converter.convert(_segmentDirectoryFile);
    File v3SegmentDirectoryFile = new File(_segmentDirectoryFile, V3_SEGMENT_NAME);
    SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(v3SegmentDirectoryFile);
    String segmentVersion = segmentMetadata.getVersion();
    Assert.assertEquals(SegmentVersion.valueOf(segmentVersion), SegmentVersion.v3);
    File singleFileIndex = new File(v3SegmentDirectoryFile, "columns.psf");
    FileTime lastModifiedTime = Files.getLastModifiedTime(singleFileIndex.toPath());
    long fileSize = singleFileIndex.length();
    // Sleep 2 seconds to prevent the same last modified time when modifying the file.
    Thread.sleep(2000);
    // Create inverted index the first time.
    checkInvertedIndexCreation(v3SegmentDirectoryFile, segmentMetadata, false);
    long addedLength = 0L;
    try (SegmentDirectory segmentDirectory = SegmentDirectory.createFromLocalFS(v3SegmentDirectoryFile, segmentMetadata, ReadMode.mmap);
        SegmentDirectory.Reader reader = segmentDirectory.createReader()) {
        // 8 bytes overhead is for checking integrity of the segment.
        try (PinotDataBuffer col1Buffer = reader.getIndexFor(COLUMN1_NAME, ColumnIndexType.INVERTED_INDEX)) {
            addedLength += col1Buffer.size() + 8;
        }
        try (PinotDataBuffer col13Buffer = reader.getIndexFor(COLUMN13_NAME, ColumnIndexType.INVERTED_INDEX)) {
            addedLength += col13Buffer.size() + 8;
        }
    }
    FileTime newLastModifiedTime = Files.getLastModifiedTime(singleFileIndex.toPath());
    Assert.assertTrue(newLastModifiedTime.compareTo(lastModifiedTime) > 0);
    long newFileSize = singleFileIndex.length();
    Assert.assertEquals(fileSize + addedLength, newFileSize);
    // Sleep 2 seconds to prevent the same last modified time when modifying the file.
    Thread.sleep(2000);
    // Create inverted index the second time.
    checkInvertedIndexCreation(v3SegmentDirectoryFile, segmentMetadata, true);
    Assert.assertEquals(Files.getLastModifiedTime(singleFileIndex.toPath()), newLastModifiedTime);
    Assert.assertEquals(singleFileIndex.length(), newFileSize);
}
Also used : PinotDataBuffer(com.linkedin.pinot.core.segment.memory.PinotDataBuffer) SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) FileTime(java.nio.file.attribute.FileTime) SegmentDirectory(com.linkedin.pinot.core.segment.store.SegmentDirectory) SegmentV1V2ToV3FormatConverter(com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter) 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