Skip to content

Commit 794fa73

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Optimize @AndroidIncompatible annotations.
Largely, this is about enabling tests that were unlocked by our upgrade to the emulator we test under now that we are on a minSdkVersion of 24. That upgrade both fixed bugs and improved performance of some excessively slow methods. But I also took this opportunity to be more systematic about which tests we consider "too slow" to run under Android. I believe that what I did was (keeping in mind that test runtime can vary from run to run): - If a test takes ~30s+, add/keep `@AndroidIncompatible`. Otherwise, consider it "fast enough." - If a test takes ~15s+, add/keep/update a comment about its approximate runtime. - But make an unprincipled exception for `Utf8Test.testIsWellFormed_3Bytes`, which takes ~70s but felt some combination of "important" and "possible to imagine behavior differences from rogue optimizations." (Maybe vaguely compare b/262383185??) RELNOTES=n/a PiperOrigin-RevId: 984013883
1 parent d743396 commit 794fa73

71 files changed

Lines changed: 70 additions & 160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎android/guava-testlib/test/com/google/common/testing/FreshValueGeneratorTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
@NullUnmarked
119119
public class FreshValueGeneratorTest extends TestCase {
120120

121-
@AndroidIncompatible // problem with equality of Type objects?
122121
public void testFreshInstance() {
123122
assertFreshInstances(
124123
String.class,
@@ -429,7 +428,6 @@ public void testEnums() {
429428
assertFreshInstance(new TypeToken<List<TwoConstantEnum>>() {}, 2);
430429
}
431430

432-
@AndroidIncompatible // problem with equality of Type objects?
433431
public void testGoogleOptional() {
434432
FreshValueGenerator generator = new FreshValueGenerator();
435433
assertEquals(

‎android/guava-tests/test/com/google/common/base/FunctionsTest.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ public void testNulls() throws Exception {
421421

422422
@J2ktIncompatible
423423
@GwtIncompatible // reflection
424-
@AndroidIncompatible // TODO(cpovirk): ClassNotFoundException: com.google.common.base.Function
425-
// (I suspect that this and the other similar failures happen with ArbitraryInstances proxies.)
426424
public void testEqualsAndSerializable() throws Exception {
427425
new ClassSanityTester().forAllPublicStaticMethods(Functions.class).testEqualsAndSerializable();
428426
}

‎android/guava-tests/test/com/google/common/base/PredicatesTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ public void testNulls() throws Exception {
909909

910910
@J2ktIncompatible
911911
@GwtIncompatible // reflection
912-
@AndroidIncompatible // TODO(cpovirk): ClassNotFoundException: com.google.common.base.Function
913912
public void testEqualsAndSerializable() throws Exception {
914913
new ClassSanityTester().forAllPublicStaticMethods(Predicates.class).testEqualsAndSerializable();
915914
}

‎android/guava-tests/test/com/google/common/base/SplitterTest.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ public void testPatternSplitWithDoubleDelimiterOmitEmptyStrings() {
359359

360360
@J2ktIncompatible // Kotlin Native's regex is based on Apache Harmony, like old Android
361361
@GwtIncompatible // java.util.regex.Pattern
362-
@AndroidIncompatible // Bug in older versions of Android we test against, since fixed.
363362
public void testPatternSplitLookBehind() {
364363
if (!CommonPattern.isPcreLike()) {
365364
return;
@@ -373,7 +372,6 @@ public void testPatternSplitLookBehind() {
373372

374373
@J2ktIncompatible // Kotlin Native's regex is based on Apache Harmony, like old Android
375374
@GwtIncompatible // java.util.regex.Pattern
376-
@AndroidIncompatible // Bug in older versions of Android we test against, since fixed.
377375
public void testPatternSplitWordBoundary() {
378376
String string = "foo<bar>bletch";
379377
Iterable<String> words = Splitter.on(Pattern.compile("\\b")).split(string);
@@ -387,7 +385,6 @@ public void testPatternSplitWordBoundary_singleCharInput() {
387385
assertThat(words).containsExactly("f").inOrder();
388386
}
389387

390-
@AndroidIncompatible // Apparently Gingerbread's regex API is buggy.
391388
@J2ktIncompatible // Kotlin Native's regex is based on Apache Harmony, like old Android
392389
@GwtIncompatible // java.util.regex.Pattern
393390
public void testPatternSplitWordBoundary_singleWordInput() {

‎android/guava-tests/test/com/google/common/base/SuppliersTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ public void testSuppliersNullChecks() throws Exception {
471471

472472
@J2ktIncompatible
473473
@GwtIncompatible // reflection
474-
@AndroidIncompatible // TODO(cpovirk): ClassNotFoundException: com.google.common.base.Function
475474
public void testSuppliersSerializable() throws Exception {
476475
new ClassSanityTester()
477476
.setDefault(Duration.class, Duration.ofSeconds(1))

‎android/guava-tests/test/com/google/common/base/ThrowablesTest.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.google.common.base.TestExceptions.SomeOtherCheckedException;
4242
import com.google.common.base.TestExceptions.SomeUncheckedException;
4343
import com.google.common.base.TestExceptions.YetAnotherCheckedException;
44-
import com.google.common.primitives.Ints;
4544
import com.google.common.testing.NullPointerTester;
4645
import java.util.List;
4746
import junit.framework.TestCase;
@@ -350,17 +349,12 @@ public void testGetCauseAs() {
350349
assertThat(expected).hasCauseThat().isEqualTo(thrown);
351350
}
352351

353-
@AndroidIncompatible // No getJavaLangAccess in Android (at least not in the version we use).
354352
@J2ktIncompatible
355353
@GwtIncompatible // lazyStackTraceIsLazy()
356354
public void testLazyStackTraceWorksInProd() {
357-
// TODO(b/64442212): Remove this guard once lazyStackTrace() works in Java 9+.
358-
Integer javaVersion = Ints.tryParse(JAVA_SPECIFICATION_VERSION.value());
359-
if (javaVersion != null && javaVersion >= 9) {
360-
return;
361-
}
362-
// Obviously this isn't guaranteed in every environment, but it works well enough for now:
363-
assertTrue(lazyStackTraceIsLazy());
355+
String javaVersion = JAVA_SPECIFICATION_VERSION.value();
356+
assertThat(lazyStackTraceIsLazy()).isEqualTo(isJava8());
357+
// TODO(b/64442212): Someday make lazyStackTrace() works in Java 9+?
364358
}
365359

366360
@J2ktIncompatible
@@ -388,4 +382,9 @@ public void testLazyStackTrace() {
388382
public void testNullPointers() {
389383
new NullPointerTester().testAllPublicStaticMethods(Throwables.class);
390384
}
385+
386+
@GwtIncompatible
387+
private static boolean isJava8() {
388+
return JAVA_SPECIFICATION_VERSION.value().equals("1.8");
389+
}
391390
}

‎android/guava-tests/test/com/google/common/base/Utf8Test.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void testIsWellFormed_2Bytes() {
204204

205205
/** Tests that round tripping of all three byte permutations work. */
206206
@GwtIncompatible // java.nio.charset.Charset
207+
// Android: takes ~70s
207208
public void testIsWellFormed_3Bytes() {
208209
testBytes(3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
209210
}

‎android/guava-tests/test/com/google/common/collect/ImmutableRangeMapTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void testGetLargeRangeMap() {
172172
}
173173
}
174174

175-
@AndroidIncompatible // slow
175+
// Android: takes ~25s
176176
public void testAsMapOfRanges() {
177177
for (Range<Integer> range1 : RANGES) {
178178
for (Range<Integer> range2 : RANGES) {
@@ -200,7 +200,7 @@ public void testAsMapOfRanges() {
200200
}
201201
}
202202

203-
@AndroidIncompatible // ~40s; doable but probably not worth it. We could test on fewer ranges
203+
@AndroidIncompatible // ~30s; doable but probably not worth it. We could test on fewer ranges
204204

205205
public void testSubRangeMap() {
206206
for (Range<Integer> range1 : RANGES) {

‎android/guava-tests/test/com/google/common/collect/ImmutableRangeSetTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ public void testRemoveAllUnsupported() {
369369
() -> rangeSet.removeAll(ImmutableRangeSet.of(Range.closed(6, 8))));
370370
}
371371

372-
@AndroidIncompatible // slow
373372
public void testExhaustive() {
374373
ImmutableSet<Range<Integer>> ranges =
375374
ImmutableSet.of(

‎android/guava-tests/test/com/google/common/collect/ImmutableTableTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ private static <R, C, V> void validateReserialization(Table<R, C, V> original) {
441441

442442
@J2ktIncompatible
443443
@GwtIncompatible // Mind-bogglingly slow in GWT
444-
@AndroidIncompatible // slow
445444
public void testOverflowCondition() {
446445
// See https://github.com/google/guava/issues/1322 for details.
447446
ImmutableTable.Builder<Integer, Integer, String> builder = ImmutableTable.builder();

0 commit comments

Comments
 (0)