Refactor and cleanup the sandboxing code.
- Remove Optional<> where it's not needed. It's nice for return values, but IMHO it was overused in this code (e.g. Optional<List<X>> is an anti-pattern, as the list itself can already signal that it is empty).
- Use Bazel's own Path class when dealing with paths, not String or java.io.File.
- Move LinuxSandboxUtil into the "sandbox" package.
- Remove dead code and unused fields.
- Migrate deprecated VFS method calls to their replacements.
- Fix a bug in ExecutionStatistics where a FileInputStream was not closed.
Closes #4868.
PiperOrigin-RevId: 190217476
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
index 7dc1bff..ff1fdd5 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/ProcessWrapperUtilTest.java
@@ -17,8 +17,12 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
+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;
import java.time.Duration;
import java.util.List;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -26,7 +30,12 @@
/** Unit tests for {@link ProcessWrapperUtil}. */
@RunWith(JUnit4.class)
public final class ProcessWrapperUtilTest {
+ private FileSystem testFS;
+ @Before
+ public final void createFileSystem() {
+ testFS = new InMemoryFileSystem();
+ }
@Test
public void testProcessWrapperCommandLineBuilder_BuildsWithoutOptionalArguments() {
@@ -51,9 +60,9 @@
Duration timeout = Duration.ofSeconds(10);
Duration killDelay = Duration.ofSeconds(2);
- String stdoutPath = "stdout.txt";
- String stderrPath = "stderr.txt";
- String statisticsPath = "stats.out";
+ Path stdoutPath = testFS.getPath("/stdout.txt");
+ Path stderrPath = testFS.getPath("/stderr.txt");
+ Path statisticsPath = testFS.getPath("/stats.out");
ImmutableList<String> expectedCommandLine =
ImmutableList.<String>builder()