Skip to content

Commit

Permalink
Add unit tests for DiskCacheClient.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 621903694
Change-Id: I735a0404952a75b4dbaaedd443da1f446764387e
  • Loading branch information
tjgq authored and Kila2 committed May 13, 2024
1 parent d618972 commit 648bfd6
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,13 @@ private void saveFile(Digest digest, Store store, InputStream in) throws IOExcep
Path temp = getTempPath();

try {
try (FileOutputStream out = new FileOutputStream(temp.getPathFile())) {
try (OutputStream out = temp.getOutputStream()) {
ByteStreams.copy(in, out);
// Fsync temp before we rename it to avoid data loss in the case of machine
// crashes (the OS may reorder the writes and the rename).
out.getFD().sync();
if (out instanceof FileOutputStream fos) {
fos.getFD().sync();
}
}
path.getParentDirectory().createDirectoryAndParents();
temp.renameTo(path);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/google/devtools/build/lib/remote/disk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ java_test(
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/exec:spawn_runner",
"//src/main/java/com/google/devtools/build/lib/remote:store",
"//src/main/java/com/google/devtools/build/lib/remote/common",
"//src/main/java/com/google/devtools/build/lib/remote/common:cache_not_found_exception",
"//src/main/java/com/google/devtools/build/lib/remote/disk",
"//src/main/java/com/google/devtools/build/lib/remote/util",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs/bazel",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//src/test/java/com/google/devtools/build/lib:test_runner",
"//third_party:error_prone_annotations",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
"//third_party/protobuf:protobuf_java",
"@remoteapis//:build_bazel_remote_execution_v2_remote_execution_java_proto",
],
)
Loading

0 comments on commit 648bfd6

Please sign in to comment.