Search in sources :

Example 6 with HashFunction

use of com.google.devtools.build.lib.vfs.FileSystem.HashFunction in project bazel by bazelbuild.

the class FileFunctionTest method testEmptyFile.

@Test
public void testEmptyFile() throws Exception {
    final byte[] digest = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    createFsAndRoot(new CustomInMemoryFs(manualClock) {

        @Override
        protected byte[] getFastDigest(Path path, HashFunction hf) throws IOException {
            return digest;
        }
    });
    Path p = file("file");
    p.setLastModifiedTime(0L);
    FileValue a = valueForPath(p);
    p.setLastModifiedTime(1L);
    assertThat(valueForPath(p)).isNotEqualTo(a);
    p.setLastModifiedTime(0L);
    assertEquals(a, valueForPath(p));
    FileSystemUtils.writeContentAsLatin1(p, "content");
    // Same digest, but now non-empty.
    assertThat(valueForPath(p)).isNotEqualTo(a);
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) HashFunction(com.google.devtools.build.lib.vfs.FileSystem.HashFunction) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HashFunction (com.google.devtools.build.lib.vfs.FileSystem.HashFunction)6 Path (com.google.devtools.build.lib.vfs.Path)5 Test (org.junit.Test)4 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)3 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)3 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)2 IOException (java.io.IOException)2 TestThread (com.google.devtools.build.lib.testutil.TestThread)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1