use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.
the class DefaultFileHashCacheTest method whenJarMemberWithEmptyManifestIsQueriedThenThrow.
@Test(expected = NoSuchFileException.class)
public void whenJarMemberWithEmptyManifestIsQueriedThenThrow() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
Path abiJarPath = Paths.get("empty-manifest.jar");
Path memberPath = Paths.get("Empty.class");
try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
jar.writeUnhashedEntry(JarFile.MANIFEST_NAME, new ByteArrayInputStream(new byte[0])).writeUnhashedEntry(memberPath.toString(), new ByteArrayInputStream("Contents".getBytes(StandardCharsets.UTF_8)));
}
cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
}
use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.
the class DefaultFileHashCacheTest method whenJarMemberWithoutHashInManifestIsQueriedThenThrow.
@Test(expected = NoSuchFileException.class)
public void whenJarMemberWithoutHashInManifestIsQueriedThenThrow() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
Path abiJarPath = Paths.get("test-abi.jar");
Path memberPath = Paths.get("Unhashed.txt");
String memberContents = "Some contents";
try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
jar.writeEntry("SomeClass.class", new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8))).writeUnhashedEntry(memberPath.toString(), new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8)));
}
cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
}
use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.
the class DefaultFileHashCacheTest method whenJarMemberWithHashInManifestIsQueriedThenCacheCorrectlyObtainsIt.
@Test
public void whenJarMemberWithHashInManifestIsQueriedThenCacheCorrectlyObtainsIt() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
Path abiJarPath = Paths.get("test-abi.jar");
Path memberPath = Paths.get("SomeClass.class");
String memberContents = "Some contents";
try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
jar.writeEntry(memberPath.toString(), new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8)));
}
HashCode actual = cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
HashCode expected = Hashing.murmur3_128().hashString(memberContents, StandardCharsets.UTF_8);
assertEquals(expected, actual);
}
Aggregations