HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics. Contributed by Masatake Iwasaki.

This commit is contained in:
Akira Ajisaka 2015-12-18 13:12:33 +09:00
parent 6da9deec20
commit bd5e207432
2 changed files with 9 additions and 4 deletions

View File

@ -1550,6 +1550,9 @@ Release 2.7.3 - UNRELEASED
HADOOP-12602. TestMetricsSystemImpl#testQSize occasionally fails. HADOOP-12602. TestMetricsSystemImpl#testQSize occasionally fails.
(Masatake Iwasaki via aajisaka) (Masatake Iwasaki via aajisaka)
HADOOP-12588. Fix intermittent test failure of TestGangliaMetrics.
(Masatake Iwasaki via aajisaka)
Release 2.7.2 - UNRELEASED Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -29,7 +29,9 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.metrics2.AbstractMetric; import org.apache.hadoop.metrics2.AbstractMetric;
@ -145,7 +147,7 @@ public class TestGangliaMetrics {
private void checkMetrics(List<byte[]> bytearrlist, int expectedCount) { private void checkMetrics(List<byte[]> bytearrlist, int expectedCount) {
boolean[] foundMetrics = new boolean[expectedMetrics.length]; boolean[] foundMetrics = new boolean[expectedMetrics.length];
for (byte[] bytes : bytearrlist) { 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++) { for (int index = 0; index < expectedMetrics.length; index++) {
if (binaryStr.indexOf(expectedMetrics[index]) >= 0) { if (binaryStr.indexOf(expectedMetrics[index]) >= 0) {
foundMetrics[index] = true; foundMetrics[index] = true;
@ -188,13 +190,13 @@ public class TestGangliaMetrics {
* hence all the captured byte arrays were pointing to one instance. * hence all the captured byte arrays were pointing to one instance.
*/ */
private class MockDatagramSocket extends DatagramSocket { private class MockDatagramSocket extends DatagramSocket {
private ArrayList<byte[]> capture; private List<byte[]> capture;
/** /**
* @throws SocketException * @throws SocketException
*/ */
public MockDatagramSocket() throws SocketException { public MockDatagramSocket() throws SocketException {
capture = new ArrayList<byte[]>(); capture = new CopyOnWriteArrayList<byte[]>();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -211,7 +213,7 @@ public class TestGangliaMetrics {
/** /**
* @return the captured byte arrays * @return the captured byte arrays
*/ */
ArrayList<byte[]> getCapturedSend() { List<byte[]> getCapturedSend() {
return capture; return capture;
} }
} }