diff options
author | 2016-12-08 16:11:07 +0000 | |
---|---|---|
committer | 2016-12-08 16:34:43 +0000 | |
commit | be2913aafa04f505b4293f4e081aaff0ab546c93 (patch) | |
tree | e2d257b2658a964a3ac40b16bd778df1dba05f2e /src/test/java/com/google/devtools/build/lib/analysis/actions | |
parent | 443faf1a56ff64a76c49127e821d13e652d02255 (diff) |
Transparently compress any FileWriteAction strings of > 256 length.
This should save on heap space for actions with long strings.
--
PiperOrigin-RevId: 141440705
MOS_MIGRATED_REVID=141440705
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis/actions')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java index 7d847c9c4c..74574c50bc 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java @@ -13,9 +13,13 @@ // limitations under the License. package com.google.devtools.build.lib.analysis.actions; +import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER; + import com.google.devtools.build.lib.actions.ActionOwner; import com.google.devtools.build.lib.actions.Artifact; - +import com.google.devtools.build.lib.util.LazyString; +import java.util.Random; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -53,4 +57,48 @@ public class FileWriteActionTest extends FileWriteActionTestCase { public void testComputesConsistentKeys() throws Exception { checkComputesConsistentKeys(); } + + @Test + public void testFileWriteActionWithShortString() throws Exception { + Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt"); + String contents = "Hello world"; + FileWriteAction action = + new FileWriteAction(NULL_ACTION_OWNER, outputArtifact, contents, false); + assertThat(action.getFileContents()).isEqualTo(contents); + } + + @Test + public void testFileWriteActionWithLazyString() throws Exception { + Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt"); + final String backingString = "Hello world"; + LazyString contents = + new LazyString() { + @Override + public String toString() { + return backingString; + } + }; + FileWriteAction action = + new FileWriteAction(NULL_ACTION_OWNER, outputArtifact, contents, false); + assertThat(action.getFileContents()).isEqualTo(backingString); + } + + /** Exercises the code path that compresses the string */ + @Test + public void testFileWriteActionWithLongString() throws Exception { + Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt"); + StringBuilder sb = new StringBuilder(); + + // Fill buffer with (deterministic) random characters to get a string that won't compress + // to a tiny size + Random random = new Random(0); + for (int i = 0; i < 16 * 1024; ++i) { + char c = (char) random.nextInt(128); + sb.append(c); + } + String contents = sb.toString(); + FileWriteAction action = + new FileWriteAction(NULL_ACTION_OWNER, outputArtifact, contents, false); + assertThat(action.getFileContents()).isEqualTo(contents); + } } |