From bd5e207432c54cc75fd8c040e232241678987e53 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Fri, 18 Dec 2015 13:12:33 +0900 Subject: [PATCH] HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics. Contributed by Masatake Iwasaki. --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../hadoop/metrics2/impl/TestGangliaMetrics.java | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 3c98eadad0..9bd4d6e17a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1550,6 +1550,9 @@ Release 2.7.3 - UNRELEASED HADOOP-12602. TestMetricsSystemImpl#testQSize occasionally fails. (Masatake Iwasaki via aajisaka) + HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics. + (Masatake Iwasaki via aajisaka) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java index e097a0f873..c386e36261 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java @@ -29,7 +29,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.commons.io.Charsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.metrics2.AbstractMetric; @@ -145,7 +147,7 @@ public void testTagsForPrefix() throws Exception { private void checkMetrics(List bytearrlist, int expectedCount) { boolean[] foundMetrics = new boolean[expectedMetrics.length]; for (byte[] bytes : bytearrlist) { - String binaryStr = new String(bytes); + String binaryStr = new String(bytes, Charsets.UTF_8); for (int index = 0; index < expectedMetrics.length; index++) { if (binaryStr.indexOf(expectedMetrics[index]) >= 0) { foundMetrics[index] = true; @@ -188,13 +190,13 @@ private static class TestSource { * hence all the captured byte arrays were pointing to one instance. */ private class MockDatagramSocket extends DatagramSocket { - private ArrayList capture; + private List capture; /** * @throws SocketException */ public MockDatagramSocket() throws SocketException { - capture = new ArrayList(); + capture = new CopyOnWriteArrayList(); } /* (non-Javadoc) @@ -211,7 +213,7 @@ public void send(DatagramPacket p) throws IOException { /** * @return the captured byte arrays */ - ArrayList getCapturedSend() { + List getCapturedSend() { return capture; } }