diff options
author | 2017-04-07 09:40:11 +0000 | |
---|---|---|
committer | 2017-04-07 16:44:26 +0200 | |
commit | 184faf617c4c90adfc33b7217aac53aab98354b2 (patch) | |
tree | f15dfd52ff3b398d8e3c547c179a7b1789ae49b6 /src/test | |
parent | 300d7573c3162f814e75131f8fd9782de3cb6297 (diff) |
Do not trample the PersistentMap journal
This fixes https://github.com/bazelbuild/bazel/issues/2660. Basically,
if we elect to keep the journal during PersistentMap.save(), we
shouldn't stomp over it the next time save() is called.
In writeJournal(), we now check if the journal file exists, and open
it in append mode if it does. Alternatively, we could simply not close
(and thus forget about) the journal in save(), but that would leak the
journal file handle if save() was never called with keepJournal()
returning false.
Change-Id: Id00732f161c8b5a082a6c109aee115591ace2ea7
PiperOrigin-RevId: 152480978
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java index b380529f77..473f855781 100644 --- a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java @@ -20,17 +20,15 @@ import static org.junit.Assert.assertTrue; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.Path; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Unit tests for the {@link PersistentMap}. @@ -201,6 +199,26 @@ public class PersistentMapTest { } @Test + public void keepJournalWithMultipleSaves() throws Exception { + createMap(); + map.put("foo", "bar"); + map.put("baz", "bang"); + map.save(); + map.updateJournal = false; + map.keepJournal = true; + map.remove("foo"); + assertThat(map).hasSize(1); + map.save(); + map.remove("baz"); + map.save(); + assertThat(map).hasSize(0); + // Ensure recreating the map loads the correct state. + createMap(); + assertThat(map).hasSize(0); + assertFalse(journalFile.exists()); + } + + @Test public void multipleJournalUpdates() throws Exception { createMap(); map.put("foo", "bar"); |