From 8aa93a575e896c609b97ddab58853b1eb95f0dee Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Tue, 31 Jul 2018 11:32:40 -0700 Subject: [PATCH] YARN-8605. TestDominantResourceFairnessPolicy.testModWhileSorting is flaky. (Wilfred Spiegelenburg via Haibo Chen) --- .../TestDominantResourceFairnessPolicy.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/TestDominantResourceFairnessPolicy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/TestDominantResourceFairnessPolicy.java index 55b7163b4ac..c963e0dab63 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/TestDominantResourceFairnessPolicy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/policies/TestDominantResourceFairnessPolicy.java @@ -24,7 +24,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -458,33 +457,20 @@ public class TestDominantResourceFairnessPolicy { } Comparator DRFComparator = createComparator(100000, 50000); - // To simulate unallocated resource changes - Thread modThread = modificationThread(schedulableList); - modThread.start(); + /* + * The old sort should fail, but timing it makes testing to flaky. + * TimSort which is used does not handle the concurrent modification of + * objects it is sorting. This is the test that should fail: + * modThread.start(); + * try { + * Collections.sort(schedulableList, DRFComparator); + * } catch (IllegalArgumentException iae) { + * // failed sort + * } + */ - // This should fail: make sure that we do test correctly - // TimSort which is used does not handle the concurrent modification of - // objects it is sorting. - try { - Collections.sort(schedulableList, DRFComparator); - fail("Sorting should have failed and did not"); - } catch (IllegalArgumentException iae) { - assertEquals(iae.getMessage(), "Comparison method violates its general contract!"); - } - try { - modThread.join(); - } catch (InterruptedException ie) { - fail("ModThread join failed: " + ie.getMessage()); - } - - // clean up and try again using TreeSet which should work - schedulableList.clear(); - for (int i=0; i<10000; i++) { - schedulableList.add( - (FakeSchedulable)createSchedulable((i%10)*100, (i%3)*2)); - } TreeSet sortedSchedulable = new TreeSet<>(DRFComparator); - modThread = modificationThread(schedulableList); + Thread modThread = modificationThread(schedulableList); modThread.start(); sortedSchedulable.addAll(schedulableList); try {