diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build')
18 files changed, 164 insertions, 80 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java b/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java index 259e0f2088..e4609416bd 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java @@ -22,8 +22,8 @@ import com.google.devtools.build.lib.actions.cache.DigestUtils; import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.testutil.TestThread; import com.google.devtools.build.lib.testutil.TestUtils; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -49,16 +49,21 @@ public class DigestUtilsTest { DigestUtils.configureCache(0); } - private static void assertDigestCalculationConcurrency(boolean expectConcurrent, - final boolean fastDigest, final int fileSize1, final int fileSize2, - HashFunction hf) throws Exception { + private static void assertDigestCalculationConcurrency( + boolean expectConcurrent, + final boolean fastDigest, + final int fileSize1, + final int fileSize2, + DigestHashFunction hf) + throws Exception { final CountDownLatch barrierLatch = new CountDownLatch(2); // Used to block test threads. final CountDownLatch readyLatch = new CountDownLatch(1); // Used to block main thread. FileSystem myfs = new InMemoryFileSystem(BlazeClock.instance(), hf) { @Override - protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getDigest(Path path, DigestHashFunction hashFunction) + throws IOException { try { barrierLatch.countDown(); readyLatch.countDown(); @@ -72,7 +77,8 @@ public class DigestUtilsTest { } @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) + throws IOException { return fastDigest ? super.getDigest(path, hashFunction) : null; } }; @@ -115,7 +121,7 @@ public class DigestUtilsTest { */ @Test public void testCalculationConcurrency() throws Exception { - for (HashFunction hf : Arrays.asList(HashFunction.MD5, HashFunction.SHA1)) { + for (DigestHashFunction hf : Arrays.asList(DigestHashFunction.MD5, DigestHashFunction.SHA1)) { assertDigestCalculationConcurrency(true, true, 4096, 4096, hf); assertDigestCalculationConcurrency(true, true, 4097, 4097, hf); assertDigestCalculationConcurrency(true, false, 4096, 4096, hf); @@ -125,13 +131,14 @@ public class DigestUtilsTest { } } - public void assertRecoverFromMalformedDigest(HashFunction... hashFunctions) throws Exception { - for (HashFunction hf : hashFunctions) { + public void assertRecoverFromMalformedDigest(DigestHashFunction... hashFunctions) + throws Exception { + for (DigestHashFunction hf : hashFunctions) { final byte[] malformed = {0, 0, 0}; FileSystem myFS = new InMemoryFileSystem(BlazeClock.instance(), hf) { @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException { // Digest functions have more than 3 bytes, usually at least 16. return malformed; @@ -153,7 +160,7 @@ public class DigestUtilsTest { fail("Digests cache should remain disabled until configureCache is called"); } catch (NullPointerException expected) { } - assertRecoverFromMalformedDigest(HashFunction.MD5, HashFunction.SHA1); + assertRecoverFromMalformedDigest(DigestHashFunction.MD5, DigestHashFunction.SHA1); try { DigestUtils.getCacheStats(); fail("Digests cache was unexpectedly enabled through the test"); @@ -170,7 +177,7 @@ public class DigestUtilsTest { // hash function is not part of the cache key. This is intentional: the hash function is // essentially final and can only be changed for tests. Therefore, just test the same hash // function twice to further exercise the cache code. - assertRecoverFromMalformedDigest(HashFunction.MD5, HashFunction.MD5); + assertRecoverFromMalformedDigest(DigestHashFunction.MD5, DigestHashFunction.MD5); assertThat(DigestUtils.getCacheStats()).isNotNull(); // Ensure the cache remains enabled. } @@ -221,13 +228,15 @@ public class DigestUtilsTest { FileSystem tracingFileSystem = new InMemoryFileSystem(BlazeClock.instance()) { @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) + throws IOException { getFastDigestCounter.incrementAndGet(); return null; } @Override - protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getDigest(Path path, DigestHashFunction hashFunction) + throws IOException { getDigestCounter.incrementAndGet(); return super.getDigest(path, hashFunction); } diff --git a/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java b/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java index 7a94c795f4..9386bcd137 100644 --- a/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.actions.ActionInputHelper; import com.google.devtools.build.lib.actions.DigestOfDirectoryException; import com.google.devtools.build.lib.testutil.Suite; import com.google.devtools.build.lib.testutil.TestSpec; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -54,23 +55,23 @@ public class SingleBuildFileCacheTest { public final void setUp() throws Exception { calls = new HashMap<>(); md5Overrides = new HashMap<>(); - fs = new InMemoryFileSystem() { - @Override - protected InputStream getInputStream(Path path) throws IOException { - int c = calls.containsKey(path.toString()) - ? calls.get(path.toString()) : 0; - c++; - calls.put(path.toString(), c); - return super.getInputStream(path); - } + fs = + new InMemoryFileSystem() { + @Override + protected InputStream getInputStream(Path path) throws IOException { + int c = calls.containsKey(path.toString()) ? calls.get(path.toString()) : 0; + c++; + calls.put(path.toString(), c); + return super.getInputStream(path); + } - @Override - protected byte[] getDigest(Path path, HashFunction hf) throws IOException { - assertThat(hf).isEqualTo(HashFunction.MD5); - byte[] override = md5Overrides.get(path.getPathString()); - return override != null ? override : super.getDigest(path, hf); - } - }; + @Override + protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { + assertThat(hf).isEqualTo(DigestHashFunction.MD5); + byte[] override = md5Overrides.get(path.getPathString()); + return override != null ? override : super.getDigest(path, hf); + } + }; underTest = new SingleBuildFileCache("/", fs); Path file = fs.getPath("/empty"); file.getOutputStream().close(); diff --git a/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java b/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java index 821bb17a94..fe4881c474 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java +++ b/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java @@ -21,8 +21,8 @@ import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.clock.JavaClock; import com.google.devtools.build.lib.remote.AbstractRemoteActionCache.UploadManifest; import com.google.devtools.build.lib.remote.util.DigestUtil; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -38,11 +38,11 @@ public class AbstractRemoteActionCacheTests { private FileSystem fs; private Path execRoot; - private final DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256); + private final DigestUtil digestUtil = new DigestUtil(DigestHashFunction.SHA256); @Before public void setUp() throws Exception { - fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); + fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/execroot"); execRoot.createDirectory(); } diff --git a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java index 8e543c4361..d48f2981b2 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java @@ -29,7 +29,7 @@ import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.remote.Retrier.RetryException; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.remoteexecution.v1test.Digest; import com.google.devtools.remoteexecution.v1test.RequestMetadata; import com.google.protobuf.ByteString; @@ -82,7 +82,7 @@ import org.mockito.MockitoAnnotations; @RunWith(JUnit4.class) public class ByteStreamUploaderTest { - private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256); + private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256); private static final int CHUNK_SIZE = 10; private static final String INSTANCE_NAME = "foo"; diff --git a/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java b/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java index 21a5bb39a2..5c6dcf2627 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java @@ -17,8 +17,8 @@ import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.remote.RemoteModule.CasPathConverter; import com.google.devtools.build.lib.remote.util.DigestUtil; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -36,7 +36,7 @@ public class CasPathConverterTest { @Test public void noOptionsShouldntCrash() { - converter.digestUtil = new DigestUtil(HashFunction.SHA256); + converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256); assertThat(converter.apply(fs.getPath("/foo"))).isEqualTo("file:///foo"); } @@ -49,7 +49,7 @@ public class CasPathConverterTest { @Test public void disabledRemote() { converter.options = Options.getDefaults(RemoteOptions.class); - converter.digestUtil = new DigestUtil(HashFunction.SHA256); + converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256); assertThat(converter.apply(fs.getPath("/foo"))).isEqualTo("file:///foo"); } @@ -58,7 +58,7 @@ public class CasPathConverterTest { OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class); parser.parse("--remote_cache=machine"); converter.options = parser.getOptions(RemoteOptions.class); - converter.digestUtil = new DigestUtil(HashFunction.SHA256); + converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256); Path path = fs.getPath("/foo"); FileSystemUtils.writeContentAsLatin1(path, "foobar"); assertThat(converter.apply(fs.getPath("/foo"))) @@ -70,7 +70,7 @@ public class CasPathConverterTest { OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class); parser.parse("--remote_cache=machine", "--remote_instance_name=projects/bazel"); converter.options = parser.getOptions(RemoteOptions.class); - converter.digestUtil = new DigestUtil(HashFunction.SHA256); + converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256); Path path = fs.getPath("/foo"); FileSystemUtils.writeContentAsLatin1(path, "foobar"); assertThat(converter.apply(fs.getPath("/foo"))) diff --git a/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java b/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java index 2634cc93a2..8857abbd85 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java @@ -18,7 +18,7 @@ import static junit.framework.TestCase.fail; import com.google.devtools.build.lib.remote.Chunker.Chunk; import com.google.devtools.build.lib.remote.util.DigestUtil; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.remoteexecution.v1test.Digest; import com.google.protobuf.ByteString; import java.io.ByteArrayInputStream; @@ -38,7 +38,7 @@ import org.mockito.Mockito; @RunWith(JUnit4.class) public class ChunkerTest { - private final DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256); + private final DigestUtil digestUtil = new DigestUtil(DigestHashFunction.SHA256); @Test public void chunkingShouldWork() throws IOException { diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java index 25228a5124..29bfeb24fb 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java @@ -39,8 +39,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.util.io.FileOutErr; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -90,7 +90,7 @@ import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) public class GrpcRemoteCacheTest { - private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256); + private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256); private FileSystem fs; private Path execRoot; @@ -118,7 +118,7 @@ public class GrpcRemoteCacheTest { .build() .start(); Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk. - fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); + fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/exec/root"); FileSystemUtils.createDirectoryAndParents(execRoot); fakeFileCache = new FakeActionInputFileCache(execRoot); diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java index 89962f173b..e10d8c35dd 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java @@ -50,8 +50,8 @@ import com.google.devtools.build.lib.exec.util.FakeOwner; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; import com.google.devtools.build.lib.util.io.FileOutErr; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -113,7 +113,7 @@ import org.mockito.stubbing.Answer; @RunWith(JUnit4.class) public class GrpcRemoteExecutionClientTest { - private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256); + private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256); private static final ArtifactExpander SIMPLE_ARTIFACT_EXPANDER = new ArtifactExpander() { @@ -206,7 +206,7 @@ public class GrpcRemoteExecutionClientTest { .start(); Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk. - fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); + fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/exec/root"); logDir = fs.getPath("/server-logs"); FileSystemUtils.createDirectoryAndParents(execRoot); diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java index 4273792319..f432ffddf6 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java @@ -50,8 +50,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.io.FileOutErr; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -157,8 +157,8 @@ public class RemoteSpawnCacheTest { @Before public final void setUp() throws Exception { MockitoAnnotations.initMocks(this); - fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); - digestUtil = new DigestUtil(HashFunction.SHA256); + fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); + digestUtil = new DigestUtil(DigestHashFunction.SHA256); execRoot = fs.getPath("/exec/root"); FileSystemUtils.createDirectoryAndParents(execRoot); fakeFileCache = new FakeActionInputFileCache(execRoot); diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java index 9eead3059d..283cc956bd 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java @@ -59,8 +59,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.util.io.FileOutErr; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -116,8 +116,8 @@ public class RemoteSpawnRunnerTest { @Before public final void setUp() throws Exception { MockitoAnnotations.initMocks(this); - digestUtil = new DigestUtil(HashFunction.SHA256); - FileSystem fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); + digestUtil = new DigestUtil(DigestHashFunction.SHA256); + FileSystem fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/exec/root"); logDir = fs.getPath("/server-logs"); FileSystemUtils.createDirectoryAndParents(execRoot); diff --git a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java index 83d5bc307a..81c7f7adc6 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java @@ -27,8 +27,8 @@ import com.google.devtools.build.lib.remote.Retrier.Backoff; import com.google.devtools.build.lib.remote.blobstore.ConcurrentMapBlobStore; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -54,7 +54,7 @@ import org.junit.runners.JUnit4; /** Tests for {@link SimpleBlobStoreActionCache}. */ @RunWith(JUnit4.class) public class SimpleBlobStoreActionCacheTest { - private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256); + private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256); private FileSystem fs; private Path execRoot; @@ -73,7 +73,7 @@ public class SimpleBlobStoreActionCacheTest { @Before public final void setUp() throws Exception { Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk. - fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256); + fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256); execRoot = fs.getPath("/exec/root"); FileSystemUtils.createDirectoryAndParents(execRoot); fakeFileCache = new FakeActionInputFileCache(execRoot); diff --git a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java index 0effbf86a6..2f19f4669a 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java @@ -26,7 +26,7 @@ import com.google.devtools.build.lib.exec.SingleBuildFileCache; import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode; import com.google.devtools.build.lib.remote.util.DigestUtil; import com.google.devtools.build.lib.testutil.Scratch; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.Root; @@ -52,8 +52,8 @@ public class TreeNodeRepositoryTest { @Before public final void setRootDir() throws Exception { - digestUtil = new DigestUtil(HashFunction.SHA256); - scratch = new Scratch(new InMemoryFileSystem(BlazeClock.instance(), HashFunction.SHA256)); + digestUtil = new DigestUtil(DigestHashFunction.SHA256); + scratch = new Scratch(new InMemoryFileSystem(BlazeClock.instance(), DigestHashFunction.SHA256)); execRoot = scratch.getFileSystem().getPath("/exec/root"); rootDir = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/exec/root"))); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java index 8dc33e22a7..21020148c0 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java @@ -43,6 +43,7 @@ import com.google.devtools.build.lib.actions.util.ActionsTestUtil; import com.google.devtools.build.lib.actions.util.TestAction.DummyAction; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.util.Pair; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -107,7 +108,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { setupRoot( new CustomInMemoryFs() { @Override - public byte[] getDigest(Path path, HashFunction hf) throws IOException { + public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { return path.getBaseName().equals("unreadable") ? expectedDigest : super.getDigest(path, hf); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java index 436cdb5cdc..5a03f3efbf 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.Root; @@ -168,7 +169,7 @@ abstract class ArtifactFunctionTestCase { /** InMemoryFileSystem that can pretend to do a fast digest. */ protected class CustomInMemoryFs extends InMemoryFileSystem { @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException { return fastDigest ? getDigest(path, hashFunction) : null; } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java index 92ed59611f..f09883adf7 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java @@ -21,6 +21,7 @@ import com.google.common.io.BaseEncoding; import com.google.common.testing.EqualsTester; import com.google.devtools.build.lib.actions.FileArtifactValue; import com.google.devtools.build.lib.testutil.ManualClock; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; @@ -158,17 +159,19 @@ public class FileArtifactValueTest { @Test public void testIOException() throws Exception { final IOException exception = new IOException("beep"); - FileSystem fs = new InMemoryFileSystem() { - @Override - public byte[] getDigest(Path path, HashFunction hf) throws IOException { - throw exception; - } - - @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException { - throw exception; - } - }; + FileSystem fs = + new InMemoryFileSystem() { + @Override + public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { + throw exception; + } + + @Override + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) + throws IOException { + throw exception; + } + }; Path path = fs.getPath("/some/path"); path.getParentDirectory().createDirectoryAndParents(); FileSystemUtils.writeContentAsLatin1(path, "content"); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java index 390436b0c7..f583465cda 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java @@ -52,6 +52,7 @@ import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; +import com.google.devtools.build.lib.vfs.DigestHashFunction; import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -451,7 +452,7 @@ public class FileFunctionTest { createFsAndRoot( new CustomInMemoryFs(manualClock) { @Override - protected byte[] getFastDigest(Path path, HashFunction hf) throws IOException { + protected byte[] getFastDigest(Path path, DigestHashFunction hf) throws IOException { return digest; } }); @@ -490,7 +491,7 @@ public class FileFunctionTest { createFsAndRoot( new CustomInMemoryFs(manualClock) { @Override - protected byte[] getFastDigest(Path path, HashFunction hf) { + protected byte[] getFastDigest(Path path, DigestHashFunction hf) { return path.getBaseName().equals("unreadable") ? expectedDigest : null; } }); @@ -826,7 +827,7 @@ public class FileFunctionTest { fs = new CustomInMemoryFs(manualClock) { @Override - protected byte[] getDigest(Path path, HashFunction hf) throws IOException { + protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { digestCalls.incrementAndGet(); return super.getDigest(path, hf); } @@ -1686,7 +1687,7 @@ public class FileFunctionTest { } @Override - protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException { + protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException { if (stubbedFastDigestErrors.containsKey(path)) { throw stubbedFastDigestErrors.get(path); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java b/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java new file mode 100644 index 0000000000..e39b3c0a54 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java @@ -0,0 +1,67 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.vfs; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.hash.Hashing; +import com.google.devtools.build.lib.vfs.DigestHashFunction.DigestFunctionConverter; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Tests for DigestHashFunction, notably that the static instances can be compared with reference + * equality. + */ +@RunWith(JUnit4.class) +public class DigestHashFunctionTest { + private final DigestFunctionConverter converter = new DigestFunctionConverter(); + + @Test + public void convertReturnsTheSameValueAsTheConstant() throws Exception { + assertThat(converter.convert("sha-256")).isSameAs(DigestHashFunction.SHA256); + assertThat(converter.convert("SHA-256")).isSameAs(DigestHashFunction.SHA256); + assertThat(converter.convert("SHA256")).isSameAs(DigestHashFunction.SHA256); + assertThat(converter.convert("sha256")).isSameAs(DigestHashFunction.SHA256); + + assertThat(converter.convert("SHA-1")).isSameAs(DigestHashFunction.SHA1); + assertThat(converter.convert("sha-1")).isSameAs(DigestHashFunction.SHA1); + assertThat(converter.convert("SHA1")).isSameAs(DigestHashFunction.SHA1); + assertThat(converter.convert("sha1")).isSameAs(DigestHashFunction.SHA1); + + assertThat(converter.convert("MD5")).isSameAs(DigestHashFunction.MD5); + assertThat(converter.convert("md5")).isSameAs(DigestHashFunction.MD5); + } + + @Test + public void lateRegistrationGetsPickedUpByConverter() throws Exception { + DigestHashFunction.register(Hashing.goodFastHash(32), "goodFastHash32"); + + assertThat(converter.convert("goodFastHash32")).isSameAs(converter.convert("GOODFASTHASH32")); + } + + @Test + public void lateRegistrationWithAlternativeNamesGetsPickedUpByConverter() throws Exception { + DigestHashFunction.register( + Hashing.goodFastHash(64), "goodFastHash64", "goodFastHash-64", "good-fast-hash-64"); + + assertThat(converter.convert("goodFastHash64")).isSameAs(converter.convert("GOODFASTHASH64")); + assertThat(converter.convert("goodFastHash64")).isSameAs(converter.convert("goodFastHash-64")); + assertThat(converter.convert("goodFastHash64")) + .isSameAs(converter.convert("good-fast-hash-64")); + assertThat(converter.convert("goodFastHash64")) + .isSameAs(converter.convert("GOOD-fast-HASH-64")); + } +} diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java index 39c75eaeaa..fdf94298d3 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java @@ -23,7 +23,6 @@ import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.unix.NativePosixFiles; import com.google.devtools.build.lib.util.Fingerprint; -import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -1305,7 +1304,8 @@ public abstract class FileSystemTest { Fingerprint fp = new Fingerprint(); fp.addBytes(new byte[0]); assertThat(fp.hexDigestAndReset()) - .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest(HashFunction.MD5))); + .isEqualTo( + BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5))); } @Test @@ -1318,7 +1318,8 @@ public abstract class FileSystemTest { Fingerprint fp = new Fingerprint(); fp.addBytes(buffer); assertThat(fp.hexDigestAndReset()) - .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest(HashFunction.MD5))); + .isEqualTo( + BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5))); } @Test |