aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android/dexer
diff options
context:
space:
mode:
authorGravatar kmb <kmb@google.com>2018-01-19 12:19:48 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-19 12:22:01 -0800
commitb0c6fcf735fab34aad6db8400648bb57766f0a3b (patch)
treeabdb968012afbd9f8f91ebc0000dfd0456dbe7c7 /src/test/java/com/google/devtools/build/android/dexer
parentb8aabe3fc5de6c1c655ea2821251c3d554de7e5b (diff)
Multi-thread zip file writing in DexFileSplitter. Since we push content into output files one by one this mostly means that we can start writing the next file while the previous one is still finishing up, and can read and write in parallel.
RELNOTES: None. PiperOrigin-RevId: 182570961
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/dexer')
-rw-r--r--src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java b/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java
index 3ef07f39aa..300a3c5343 100644
--- a/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java
+++ b/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java
@@ -23,7 +23,6 @@ import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Iterators;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
@@ -94,6 +93,41 @@ public class DexFileSplitterTest {
assertExpectedEntries(outputArchives, expectedEntries);
}
+ /**
+ * Tests that the same input creates identical output in 2 runs. Flakiness here would indicate
+ * race conditions or other concurrency issues.
+ */
+ @Test
+ public void testDeterminism() throws Exception {
+ Path dexArchive = buildDexArchive();
+ Path dexArchive2 = buildDexArchive(INPUT_JAR2, "jar2.dex.zip");
+ ImmutableList<Path> outputArchives = runDexSplitter(200, "det1", dexArchive, dexArchive2);
+ assertThat(outputArchives.size()).isGreaterThan(1); // test sanity
+ ImmutableList<Path> outputArchives2 = runDexSplitter(200, "det2", dexArchive, dexArchive2);
+ assertThat(outputArchives2).hasSize(outputArchives.size()); // paths differ though
+
+ Path outputRoot2 = outputArchives2.get(0).getParent();
+ for (Path outputArchive : outputArchives) {
+ ImmutableList<ZipEntry> expectedEntries;
+ try (ZipFile zip = new ZipFile(outputArchive.toFile())) {
+ expectedEntries = zip.stream().collect(ImmutableList.toImmutableList());
+ }
+ ImmutableList<ZipEntry> actualEntries;
+ try (ZipFile zip2 = new ZipFile(outputRoot2.resolve(outputArchive.getFileName()).toFile())) {
+ actualEntries = zip2.stream().collect(ImmutableList.toImmutableList());
+ }
+ int len = expectedEntries.size();
+ assertThat(actualEntries).hasSize(len);
+ for (int i = 0; i < len; ++i) {
+ ZipEntry expected = expectedEntries.get(i);
+ ZipEntry actual = actualEntries.get(i);
+ assertThat(actual.getName()).named(actual.getName()).isEqualTo(expected.getName());
+ assertThat(actual.getSize()).named(actual.getName()).isEqualTo(expected.getSize());
+ assertThat(actual.getCrc()).named(actual.getName()).isEqualTo(expected.getCrc());
+ }
+ }
+ }
+
@Test
public void testMainDexList() throws Exception {
Path dexArchive = buildDexArchive();
@@ -193,9 +227,12 @@ public class DexFileSplitterTest {
private ImmutableSet<String> dexEntries(Path dexArchive) throws IOException {
try (ZipFile input = new ZipFile(dexArchive.toFile())) {
- ImmutableSet<String> result = ImmutableSet.copyOf(Iterators.filter(
- Iterators.transform(Iterators.forEnumeration(input.entries()), ZipEntryName.INSTANCE),
- Predicates.containsPattern(".*\\.class.dex$")));
+ ImmutableSet<String> result =
+ input
+ .stream()
+ .map(ZipEntryName.INSTANCE)
+ .filter(Predicates.containsPattern(".*\\.class.dex$"))
+ .collect(ImmutableSet.toImmutableSet());
assertThat(result).isNotEmpty(); // test sanity
return result;
}