From dd9f60e4d2721cdfd3044a8c8a1bdfd8e444009c Mon Sep 17 00:00:00 2001 From: ccalvarin Date: Mon, 23 Jul 2018 18:16:18 -0700 Subject: Remove redundancy in DigestHashFunction use in FileSystem. Each FileSystem instance has a digest function, but the getDigest and getHashDigest functions also accepted their own custom parameter functions. We only support 1 hash per filesystem instance, these parameters are redundant. RELNOTES: None. PiperOrigin-RevId: 205758571 --- .../devtools/build/lib/actions/DigestUtilsTest.java | 21 ++++++++------------- .../build/lib/exec/SingleBuildFileCacheTest.java | 6 +++--- .../build/lib/skyframe/ArtifactFunctionTest.java | 7 ++----- .../lib/skyframe/ArtifactFunctionTestCase.java | 5 ++--- .../build/lib/skyframe/FileArtifactValueTest.java | 6 ++---- .../build/lib/skyframe/FileFunctionTest.java | 11 +++++------ .../devtools/build/lib/vfs/FileSystemTest.java | 6 ++---- 7 files changed, 24 insertions(+), 38 deletions(-) (limited to 'src/test/java/com') 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 1013c1a02e..fc6376e46f 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 @@ -62,8 +62,7 @@ public class DigestUtilsTest { FileSystem myfs = new InMemoryFileSystem(BlazeClock.instance(), hf) { @Override - protected byte[] getDigest(Path path, DigestHashFunction hashFunction) - throws IOException { + protected byte[] getDigest(Path path) throws IOException { try { barrierLatch.countDown(); readyLatch.countDown(); @@ -73,13 +72,12 @@ public class DigestUtilsTest { } catch (Exception e) { throw new IOException(e); } - return super.getDigest(path, hashFunction); + return super.getDigest(path); } @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) - throws IOException { - return fastDigest ? super.getDigest(path, hashFunction) : null; + protected byte[] getFastDigest(Path path) throws IOException { + return fastDigest ? super.getDigest(path) : null; } }; @@ -139,8 +137,7 @@ public class DigestUtilsTest { FileSystem myFS = new InMemoryFileSystem(BlazeClock.instance(), hf) { @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) - throws IOException { + protected byte[] getFastDigest(Path path) throws IOException { // Digest functions have more than 3 bytes, usually at least 16. return malformed; } @@ -229,17 +226,15 @@ public class DigestUtilsTest { FileSystem tracingFileSystem = new InMemoryFileSystem(BlazeClock.instance()) { @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) - throws IOException { + protected byte[] getFastDigest(Path path) throws IOException { getFastDigestCounter.incrementAndGet(); return null; } @Override - protected byte[] getDigest(Path path, DigestHashFunction hashFunction) - throws IOException { + protected byte[] getDigest(Path path) throws IOException { getDigestCounter.incrementAndGet(); - return super.getDigest(path, hashFunction); + return super.getDigest(path); } }; 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 33f03865f6..e7b0937f95 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 @@ -67,10 +67,10 @@ public class SingleBuildFileCacheTest { } @Override - protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { - assertThat(hf).isEqualTo(DigestHashFunction.MD5); + protected byte[] getDigest(Path path) throws IOException { + assertThat(getDigestFunction()).isEqualTo(DigestHashFunction.MD5); byte[] override = md5Overrides.get(path.getPathString()); - return override != null ? override : super.getDigest(path, hf); + return override != null ? override : super.getDigest(path); } }; underTest = new SingleBuildFileCache("/", fs); 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 734038cb29..19443a536c 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,7 +43,6 @@ 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; @@ -108,10 +107,8 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { setupRoot( new CustomInMemoryFs() { @Override - public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { - return path.getBaseName().equals("unreadable") - ? expectedDigest - : super.getDigest(path, hf); + public byte[] getDigest(Path path) throws IOException { + return path.getBaseName().equals("unreadable") ? expectedDigest : super.getDigest(path); } }); 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 b0deb69d58..5a1ca443b1 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 @@ -31,7 +31,6 @@ 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; @@ -163,8 +162,8 @@ abstract class ArtifactFunctionTestCase { /** InMemoryFileSystem that can pretend to do a fast digest. */ protected class CustomInMemoryFs extends InMemoryFileSystem { @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException { - return fastDigest ? getDigest(path, hashFunction) : null; + protected byte[] getFastDigest(Path path) throws IOException { + return fastDigest ? getDigest(path) : 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 f09883adf7..1e85b6c8b3 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,7 +21,6 @@ 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; @@ -162,13 +161,12 @@ public class FileArtifactValueTest { FileSystem fs = new InMemoryFileSystem() { @Override - public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { + public byte[] getDigest(Path path) throws IOException { throw exception; } @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) - throws IOException { + protected byte[] getFastDigest(Path path) throws IOException { throw exception; } }; 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 65639f3f90..b76bbcd24d 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,7 +52,6 @@ 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; @@ -452,7 +451,7 @@ public class FileFunctionTest { createFsAndRoot( new CustomInMemoryFs(manualClock) { @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hf) throws IOException { + protected byte[] getFastDigest(Path path) throws IOException { return digest; } }); @@ -491,7 +490,7 @@ public class FileFunctionTest { createFsAndRoot( new CustomInMemoryFs(manualClock) { @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hf) { + protected byte[] getFastDigest(Path path) { return path.getBaseName().equals("unreadable") ? expectedDigest : null; } }); @@ -827,9 +826,9 @@ public class FileFunctionTest { fs = new CustomInMemoryFs(manualClock) { @Override - protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException { + protected byte[] getDigest(Path path) throws IOException { digestCalls.incrementAndGet(); - return super.getDigest(path, hf); + return super.getDigest(path); } }; pkgRoot = Root.fromPath(fs.getPath("/root")); @@ -1621,7 +1620,7 @@ public class FileFunctionTest { } @Override - protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException { + protected byte[] getFastDigest(Path path) throws IOException { if (stubbedFastDigestErrors.containsKey(path)) { throw stubbedFastDigestErrors.get(path); } 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 fdf94298d3..f279e84e3e 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 @@ -1304,8 +1304,7 @@ public abstract class FileSystemTest { Fingerprint fp = new Fingerprint(); fp.addBytes(new byte[0]); assertThat(fp.hexDigestAndReset()) - .isEqualTo( - BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5))); + .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest())); } @Test @@ -1318,8 +1317,7 @@ public abstract class FileSystemTest { Fingerprint fp = new Fingerprint(); fp.addBytes(buffer); assertThat(fp.hexDigestAndReset()) - .isEqualTo( - BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5))); + .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest())); } @Test -- cgit v1.2.3