Skip to content

Commit

Permalink
MAPREDUCE-7459. Fixed TestHistoryViewerPrinter flakiness during strin…
Browse files Browse the repository at this point in the history
…g comparison (#6215). Contributed by Rajiv Ramachandran.

Reviewed-by: Inigo Goiri <[email protected]>
Signed-off-by: Ayush Saxena <[email protected]>
  • Loading branch information
rRajivramachandran authored Nov 4, 2023
1 parent 5b215f2 commit d6bb47e
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hadoop.mapreduce.JobID;
import org.apache.hadoop.mapreduce.JobStatus;
import org.apache.hadoop.mapreduce.TaskType;
import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -35,7 +36,9 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;
import java.util.Locale;

Expand Down Expand Up @@ -160,6 +163,13 @@ public void testHumanPrinter() throws Exception {
LINE_SEPARATOR, outStr);
}

private static void assertEqualLines(String str1, String str2) {
final List<String> linesFromStr1 = Arrays.asList(str1.trim().split("\n"));
final List<String> linesFromStr2 = Arrays.asList(str2.trim().split("\n"));

Assertions.assertThat(linesFromStr1).containsExactlyInAnyOrderElementsOf(linesFromStr2);
}

@Test
public void testHumanPrinterAll() throws Exception {
JobHistoryParser.JobInfo job = createJobInfo();
Expand All @@ -168,7 +178,7 @@ public void testHumanPrinterAll() throws Exception {
TimeZone.getTimeZone("GMT"));
String outStr = run(printer);
if (System.getProperty("java.version").startsWith("1.7")) {
Assert.assertEquals("\n" +
assertEqualLines("\n" +
"Hadoop job: job_1317928501754_0001\n" +
"=====================================\n" +
"User: rkanter\n" +
Expand Down Expand Up @@ -356,7 +366,7 @@ public void testHumanPrinterAll() throws Exception {
"localhost\ttask_1317928501754_0001_m_000002, " +
LINE_SEPARATOR, outStr);
} else {
Assert.assertEquals("\n" +
assertEqualLines("\n" +
"Hadoop job: job_1317928501754_0001\n" +
"=====================================\n" +
"User: rkanter\n" +
Expand Down

0 comments on commit d6bb47e

Please sign in to comment.