Skip to content

Commit e06c291

Browse files
committed
HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics. Contributed by Masatake Iwasaki.
(cherry picked from commit bd5e207)
1 parent 7e5306e commit e06c291

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

hadoop-common-project/hadoop-common/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,9 @@ Release 2.7.3 - UNRELEASED
926926
HADOOP-12602. TestMetricsSystemImpl#testQSize occasionally fails.
927927
(Masatake Iwasaki via aajisaka)
928928

929+
HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics.
930+
(Masatake Iwasaki via aajisaka)
931+
929932
Release 2.7.2 - UNRELEASED
930933

931934
INCOMPATIBLE CHANGES

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import java.util.HashSet;
3030
import java.util.List;
3131
import java.util.Set;
32+
import java.util.concurrent.CopyOnWriteArrayList;
3233

34+
import org.apache.commons.io.Charsets;
3335
import org.apache.commons.logging.Log;
3436
import org.apache.commons.logging.LogFactory;
3537
import org.apache.hadoop.metrics2.AbstractMetric;
@@ -145,7 +147,7 @@ public void testTagsForPrefix() throws Exception {
145147
private void checkMetrics(List<byte[]> bytearrlist, int expectedCount) {
146148
boolean[] foundMetrics = new boolean[expectedMetrics.length];
147149
for (byte[] bytes : bytearrlist) {
148-
String binaryStr = new String(bytes);
150+
String binaryStr = new String(bytes, Charsets.UTF_8);
149151
for (int index = 0; index < expectedMetrics.length; index++) {
150152
if (binaryStr.indexOf(expectedMetrics[index]) >= 0) {
151153
foundMetrics[index] = true;
@@ -188,13 +190,13 @@ private static class TestSource {
188190
* hence all the captured byte arrays were pointing to one instance.
189191
*/
190192
private class MockDatagramSocket extends DatagramSocket {
191-
private ArrayList<byte[]> capture;
193+
private List<byte[]> capture;
192194

193195
/**
194196
* @throws SocketException
195197
*/
196198
public MockDatagramSocket() throws SocketException {
197-
capture = new ArrayList<byte[]>();
199+
capture = new CopyOnWriteArrayList<byte[]>();
198200
}
199201

200202
/* (non-Javadoc)
@@ -211,7 +213,7 @@ public void send(DatagramPacket p) throws IOException {
211213
/**
212214
* @return the captured byte arrays
213215
*/
214-
ArrayList<byte[]> getCapturedSend() {
216+
List<byte[]> getCapturedSend() {
215217
return capture;
216218
}
217219
}

0 commit comments

Comments
 (0)